Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE on Json sub type with no name defined #2862

Closed
lwielek opened this issue Jun 29, 2018 · 5 comments
Closed

NPE on Json sub type with no name defined #2862

lwielek opened this issue Jun 29, 2018 · 5 comments

Comments

@lwielek
Copy link

lwielek commented Jun 29, 2018

During OpenAPI object creation, the jackson model resolver fails with NPE (swagger-core 2.0.2):

at io.swagger.v3.core.jackson.ModelResolver.resolveSubtypes(ModelResolver.java:1087)
at io.swagger.v3.core.jackson.ModelResolver.resolve(ModelResolver.java:642)

Fails on JsonSubType wit null/empty name, example:

@com.fasterxml.jackson.annotation.JsonTypeInfo(use = com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME, include = com.fasterxml.jackson.annotation.JsonTypeInfo.As.WRAPPER_OBJECT)
@com.fasterxml.jackson.annotation.JsonSubTypes({
        @com.fasterxml.jackson.annotation.JsonSubTypes.Type(value = ExampleSubType.class)})
public interface Example {
//...
}
public enum ExampleSubType implements Example {
//...
@frantuma
Copy link
Member

Seems not to be reproducible, can you share the full failing resource/model class and the caller code, and possibly the full stack trace?

@lwielek
Copy link
Author

lwielek commented Jul 18, 2018

@frantuma
source attached

issue.2862.zip

full stack trace:

Exception in thread "main" java.lang.NullPointerException
	at io.swagger.v3.core.jackson.ModelResolver.resolveSubtypes(ModelResolver.java:1106)
	at io.swagger.v3.core.jackson.ModelResolver.resolve(ModelResolver.java:679)
	at io.swagger.v3.core.converter.ModelConverterContextImpl.resolve(ModelConverterContextImpl.java:90)
	at io.swagger.v3.core.converter.ModelConverters.resolveAsResolvedSchema(ModelConverters.java:112)
	at io.swagger.v3.jaxrs2.Reader.parseMethod(Reader.java:949)
	at io.swagger.v3.jaxrs2.Reader.parseMethod(Reader.java:754)
	at io.swagger.v3.jaxrs2.Reader.read(Reader.java:422)
	at io.swagger.v3.jaxrs2.Reader.read(Reader.java:169)
	at io.swagger.v3.jaxrs2.Reader.read(Reader.java:196)
	at io.swagger.v3.oas.integration.GenericOpenApiContext.read(GenericOpenApiContext.java:353)
	at example.main.Main.main(Main.java:23)

frantuma added a commit that referenced this issue Jul 18, 2018
frantuma added a commit that referenced this issue Jul 18, 2018
@frantuma
Copy link
Member

Thanks, issue was indeed with enums in combination with subtypes compound models; not really sure what the example models represent, however #2878 fixes the NPE for such scenario; the outcome for the given example would be:

Example:
  type: object
ExampleSubType:
  type: string
  allOf:
  - $ref: '#/components/schemas/Example'
  enum:
  - VALUE1
  - VALUE2

closing ticket, please reopen if you're still experiencing issues

@lwielek
Copy link
Author

lwielek commented Jul 18, 2018

@frantuma thanks! looking forward for a release containing this fix

@lwielek
Copy link
Author

lwielek commented Jul 19, 2018

@frantuma
There's another issue, I spotted here.
The JsonTypeInfo.As.WRAPPER_OBJECT is not handled correctly in the OpenAPI model.
With the wrapper object annotation, the enum is serialized as an object, not as a simple string.
Example:

{"ExampleSubType":"VALUE1"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants