Skip to content

Commit

Permalink
SchemaConverter fails on null #10425
Browse files Browse the repository at this point in the history
(cherry picked from commit f51a63f)
  • Loading branch information
vbradnitski authored and rymsha committed Jan 15, 2025
1 parent 1510dd3 commit 9b66715
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

import com.enonic.xp.lib.schema.mapper.SchemaConverter;
import com.enonic.xp.resource.DynamicContentSchemaType;
import com.enonic.xp.resource.DynamicSchemaResult;
import com.enonic.xp.resource.DynamicSchemaService;
import com.enonic.xp.resource.GetDynamicContentSchemaParams;
import com.enonic.xp.schema.BaseSchema;
import com.enonic.xp.schema.BaseSchemaName;
import com.enonic.xp.schema.content.ContentTypeName;
import com.enonic.xp.schema.mixin.MixinName;
Expand Down Expand Up @@ -55,7 +57,8 @@ public Object execute()
final GetDynamicContentSchemaParams params =
GetDynamicContentSchemaParams.create().name( schemaName ).type( dynamicContentSchemaType ).build();

return SchemaConverter.convert( dynamicSchemaServiceSupplier.get().getContentSchema( params ) );
final DynamicSchemaResult<BaseSchema<?>> contentSchema = dynamicSchemaServiceSupplier.get().getContentSchema( params );
return contentSchema != null ? SchemaConverter.convert( contentSchema ) : null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,11 @@ public void testInvalidSchemaType()
runFunction( "/test/GetDynamicContentSchemaHandlerTest.js", "getInvalidContentSchemaType" );
}

@Test
public void testNull()
{
when( dynamicSchemaService.getContentSchema( isA( GetDynamicContentSchemaParams.class ) ) ).thenReturn( null );
runFunction( "/test/GetDynamicContentSchemaHandlerTest.js", "getNullSchema" );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ var assert = require('/lib/xp/testing');

exports.getInvalidContentSchemaType = function () {
assert.assertThrows(() => schemaLib.getSchema({
key: 'myapp:mydata',
name: 'myapp:mydata',
type: 'INVALID_TYPE'
}));
};

exports.getNullSchema = function () {
assert.assertNull(schemaLib.getSchema({
name: 'myapp:non-existing-schema',
type: 'MIXIN'
}));
};


0 comments on commit 9b66715

Please sign in to comment.