You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When Spring MVC header-based API versioning has a default version and an
operation documents version-specific header values with @Schema(allowableValues = ...), requesting /v3/api-docs returns HTTP 500.
SpringDoc attempts to append the configured MVC default version to the schema
enum created from the annotation. That enum is immutable, so Schema.addEnumItemObject throws UnsupportedOperationException.
Runtime request routing works correctly. The failure occurs while generating
the OpenAPI description.
HTTP 500
java.lang.UnsupportedOperationException
at io.swagger.v3.oas.models.media.Schema.addEnumItemObject(...)
at org.springdoc.core.service.AbstractRequestService.getHeaders(...)
The relevant merge in AbstractRequestService.getHeaders() reads the default
from versionDefaultMap and calls:
when the annotation-derived enum does not contain the configured default.
Removing spring.mvc.apiversion.default allows /v3/api-docs to be generated.
Adding the default version to the v3 annotation's allowable values also avoids
this call, but produces incorrect documentation because the v3 operation is not
available under version 2.0.0.
Expected behavior
/v3/api-docs should return a valid OpenAPI document rather than HTTP 500.
The operation-specific supported versions should remain accurate. For the
example above, the header schema should continue to allow only 3.0.0:
SpringDoc should avoid adding a global default to an operation whose mapping
does not support that version. If an enum needs to be augmented in other cases,
the annotation-derived values must first be copied into a mutable collection.
The same addEnumItemObject(defaultValue) merge is still present by source
inspection in tags v3.1.0, v3.1.1, and the main branch as of
2026-09-11. Those versions were inspected but not executed with this
reproducer.
The current workaround is to leave spring.mvc.apiversion.default unset and
implement the fallback in a custom API version resolver. This preserves
runtime defaulting without exposing the default to SpringDoc's merge path.
No existing issue matching Schema.addEnumItemObject with this API-version
configuration was found before preparing this report.
Describe the bug
When Spring MVC header-based API versioning has a default version and an
operation documents version-specific header values with
@Schema(allowableValues = ...), requesting/v3/api-docsreturns HTTP 500.SpringDoc attempts to append the configured MVC default version to the schema
enum created from the annotation. That enum is immutable, so
Schema.addEnumItemObjectthrowsUnsupportedOperationException.Runtime request routing works correctly. The failure occurs while generating
the OpenAPI description.
To Reproduce
4.1.17.0.9springdoc-openapi-starter-webmvc-ui:3.0.32.2.47(transitive)25Configure Spring MVC API versioning:
Create an annotation for an operation that is available only in version
3.0.0:Use it on a versioned controller method:
Request:
Actual result:
The relevant merge in
AbstractRequestService.getHeaders()reads the defaultfrom
versionDefaultMapand calls:when the annotation-derived enum does not contain the configured default.
Removing
spring.mvc.apiversion.defaultallows/v3/api-docsto be generated.Adding the default version to the v3 annotation's allowable values also avoids
this call, but produces incorrect documentation because the v3 operation is not
available under version
2.0.0.Expected behavior
/v3/api-docsshould return a valid OpenAPI document rather than HTTP 500.The operation-specific supported versions should remain accurate. For the
example above, the header schema should continue to allow only
3.0.0:{ "name": "x-api-version", "in": "header", "schema": { "type": "string", "enum": ["3.0.0"] } }SpringDoc should avoid adding a global default to an operation whose mapping
does not support that version. If an enum needs to be augmented in other cases,
the annotation-derived values must first be copied into a mutable collection.
Screenshots
Not applicable.
Additional context
Spring Framework 7 - API versioning support #2975
ApiVersionConfigurerdefaults:Api Versioning. Use the default version from ApiVersionConfigurer #3159
addEnumItemObject(defaultValue)merge is still present by sourceinspection in tags
v3.1.0,v3.1.1, and themainbranch as of2026-09-11. Those versions were inspected but not executed with this
reproducer.
spring.mvc.apiversion.defaultunset andimplement the fallback in a custom API version resolver. This preserves
runtime defaulting without exposing the default to SpringDoc's merge path.
Schema.addEnumItemObjectwith this API-versionconfiguration was found before preparing this report.