Skip to content

Fixes #3263 - strip null-key entries from component schema properties…#3267

Open
Shaveenblu wants to merge 1 commit intospringdoc:mainfrom
Shaveenblu:fix/null-key-schema-properties-3263
Open

Fixes #3263 - strip null-key entries from component schema properties…#3267
Shaveenblu wants to merge 1 commit intospringdoc:mainfrom
Shaveenblu:fix/null-key-schema-properties-3263

Conversation

@Shaveenblu
Copy link
Copy Markdown

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.

…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.
@Shaveenblu Shaveenblu force-pushed the fix/null-key-schema-properties-3263 branch from b706edf to 289d9d1 Compare April 14, 2026 11:32
@Mattias-Sehlstedt
Copy link
Copy Markdown
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).

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 this pull request may close these issues.

2 participants