Fixes #3263 - strip null-key entries from component schema properties…#3267
Open
Shaveenblu wants to merge 1 commit intospringdoc:mainfrom
Open
Fixes #3263 - strip null-key entries from component schema properties…#3267Shaveenblu wants to merge 1 commit intospringdoc:mainfrom
Shaveenblu wants to merge 1 commit intospringdoc:mainfrom
Conversation
…roperties before serialization When swagger-core resolves a @JsonUnwrapped bean property (e.g. Spring HATEOAS EntityModel<T>), it uses JSON-based cloning internally. Schema.getName() is @JsonIgnore, so the name is lost during cloning. These null-named schemas are then inserted as null keys into the properties map, causing Jackson to throw JsonMappingException: Null key for a Map not allowed in JSON when serializing the OpenAPI document. Add SpringDocUtils.removeNullKeySchemas(OpenAPI) which recursively removes any null-key entry from every component schema properties map, and call it in AbstractOpenApiResource.getOpenApi() after schema resolution and before the user-facing customizers run. Five unit tests added in SpringDocUtilsTest covering top-level null keys, nested null keys, null OpenAPI, null components, and schemas with no properties.
b706edf to
289d9d1
Compare
Contributor
|
Hi, have we investigated the cause for this issue? My understanding from the github-issue is that it is entirely new with 3.0.3, and thus that it is a regression stemming from somewhere. If that is the case, I would find it suitable to first look for the cause of the regression, since it could affect many other things, before we introduce a "cleaner" that simply attempts to cover the issue up with additional post-processing. It might for example be tied to this new way of conducting a copy. But it is of course easiest to test verify if we use Springdoc 3.0.2 and then bump only swagger-core (to tell if the change merely comes from the bump of swagger-core or if the issue resides in springdoc itself). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When swagger-core resolves a @JsonUnwrapped bean property (e.g. Spring HATEOAS EntityModel), it uses JSON-based cloning internally. Schema.getName() is @JsonIgnore, so the name is lost during cloning. These null-named schemas are then inserted as null keys into the properties map, causing Jackson to throw JsonMappingException: Null key for a Map not allowed in JSON when serializing the OpenAPI document.
Add SpringDocUtils.removeNullKeySchemas(OpenAPI) which recursively removes any null-key entry from every component schema properties map, and call it in AbstractOpenApiResource.getOpenApi() after schema resolution and before the user-facing customizers run.
Five unit tests added in SpringDocUtilsTest covering top-level null keys, nested null keys, null OpenAPI, null components, and schemas with no properties.