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

Resolving Schema for system enums fails if enumsAsRef is enabled #4362

Closed
mdjimy opened this issue Feb 17, 2023 · 0 comments · Fixed by #4364
Closed

Resolving Schema for system enums fails if enumsAsRef is enabled #4362

mdjimy opened this issue Feb 17, 2023 · 0 comments · Fixed by #4364

Comments

@mdjimy
Copy link

mdjimy commented Feb 17, 2023

If ModelResolver.enumsAsRef is set to true and model contains property with java.time.DayOfWeek enum, then generation of OpenAPI specification for such a model will result in the following exception:

java.lang.NullPointerException: null
	at java.base/java.util.Objects.requireNonNull(Objects.java:208)
	at java.base/java.util.TreeMap.put(TreeMap.java:809)
	at java.base/java.util.TreeMap.put(TreeMap.java:534)
	at io.swagger.v3.core.converter.ModelConverterContextImpl.defineModel(ModelConverterContextImpl.java:60)
	at io.swagger.v3.core.jackson.ModelResolver.resolve(ModelResolver.java:350)
	at org.springdoc.core.converters.AdditionalModelsConverter.resolve(AdditionalModelsConverter.java:155)
	at org.springdoc.core.converters.FileSupportConverter.resolve(FileSupportConverter.java:69)
	at org.springdoc.core.converters.ResponseSupportConverter.resolve(ResponseSupportConverter.java:79)
	at ...

I believe the problem is that ModelResolver.resolve( ) checks if type is not system type (using ReflectionUtils.isSystemType(type)) and if so, default value of property schema name is not inferred from its type name.

Proposed solution is to skip system type check for enum types.

Here you can find gist with minimal code example to reproduce the problem:
https://gist.github.com/mdjimy/2a08b1f9f0eb26485f2794c50df7dd35

Tested with io.swagger.core.v3:swagger-core-jakarta:2.2.8

@mdjimy mdjimy changed the title Schema generation for system enums fails if enumsAsRef is enabled Resolving Schema for system enums fails if enumsAsRef is enabled Feb 17, 2023
mdjimy pushed a commit to mdjimy/swagger-core that referenced this issue Feb 17, 2023
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

Successfully merging a pull request may close this issue.

1 participant