Skip to content

Fix OpenAPI property-level [JsonConverter] on [AsParameters] enum ignored with request body - #69241

Open
fahmymohammed wants to merge 1 commit into
dotnet:mainfrom
fahmymohammed:fix/openapi-asparameters-property-jsonconverter-69156
Open

Fix OpenAPI property-level [JsonConverter] on [AsParameters] enum ignored with request body#69241
fahmymohammed wants to merge 1 commit into
dotnet:mainfrom
fahmymohammed:fix/openapi-asparameters-property-jsonconverter-69156

Conversation

@fahmymohammed

Copy link
Copy Markdown

Summary

Fixes #69156

  • When an [AsParameters] DTO has an enum property with a property-level [JsonConverter(typeof(JsonStringEnumConverter))], the generated schema emits { "type": "integer" } instead of string enum values — but only when the endpoint also has a request body parameter.
  • Root cause: CreateSchema(Type) generates schemas for bare types without property-level converter context. When the response type doesn't reference the enum, it is first registered as an integer component during parameter processing — before the property-level converter is seen.
  • Fix: detect property-level JsonStringEnumConverter attributes in ApplyParameterInfo and inject string enum values before the schema is componentized.

Test plan

  • Added GetOpenApiParameters_HandlesPropertyLevelJsonStringEnumConverterWithRequestBody — the exact bug scenario (enum + body param)
  • Added GetOpenApiParameters_HandlesPropertyLevelJsonStringEnumConverterWithoutRequestBody — confirms the already-working path stays correct
  • All 1035 existing OpenApi tests pass (0 failures, 5 pre-existing skips)
  • All 19 enum-related tests pass

@github-actions github-actions Bot added the area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc label Sep 11, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Sep 11, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @fahmymohammed. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@fahmymohammed

Copy link
Copy Markdown
Author

@dotnet-policy-service agree

@fahmymohammed
fahmymohammed force-pushed the fix/openapi-asparameters-property-jsonconverter-69156 branch from e42fe3f to d9242dd Compare September 11, 2026 20:03
…ored with request body

Fixes dotnet#69156

When an [AsParameters] DTO had an enum property annotated with a property-level
[JsonConverter(typeof(JsonStringEnumConverter))], the generated schema emitted
"type": "integer" with no enum values whenever the endpoint also had a request
body parameter.

Enum parameters are generated from the bare type, which carries no property-level
converter context, so the enum was registered as an integer component during
parameter processing before the converter was ever seen.

Detect property-level string enum converters in ApplyParameterInfo and drop the
integer type keyword so the existing non-body enum handling supplies the string
member names. Covers the non-generic, generic and derived JsonStringEnumConverter
forms across query, header, route and form binding sources, and leaves converters
that do not serialize enums as strings untouched.
@fahmymohammed
fahmymohammed force-pushed the fix/openapi-asparameters-property-jsonconverter-69156 branch from d9242dd to 9532b1b Compare September 11, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAPI property-level [JsonConverter] on [AsParameters] enum ignored when the operation has a request body

1 participant