Skip to content

Specify "type" for enums in OpenAPI#66418

Open
Youssef1313 wants to merge 2 commits intomainfrom
dev/ygerges/openapi-type-enum
Open

Specify "type" for enums in OpenAPI#66418
Youssef1313 wants to merge 2 commits intomainfrom
dev/ygerges/openapi-type-enum

Conversation

@Youssef1313
Copy link
Copy Markdown
Member

Specify "type" for enums in OpenAPI

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Description

When encountering an enum in schema, we set the type to "string" instead of leaving it as null.

Fixes #61303

Copilot AI review requested due to automatic review settings April 22, 2026 14:39
@Youssef1313 Youssef1313 requested a review from a team as a code owner April 22, 2026 14:39
@github-actions github-actions Bot added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Apr 22, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates OpenAPI schema generation so enums serialized as strings (e.g., via JsonStringEnumConverter) get an explicit "type": "string" instead of leaving type unset, aligning generated specs with expected OpenAPI schema shape.

Changes:

  • Set type: "string" on enum schemas when an enum array is present but type is missing.
  • Update the parameter schema test to assert JsonSchemaType.String for enum parameters using string enum conversion.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs Adds enum-specific schema fix-up during STJ schema export transform.
src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Services/OpenApiSchemaService/OpenApiSchemaService.ParameterSchemas.cs Updates enum-with-converter test assertion to expect type to be string.

Comment thread src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Microsoft.AspNetCore.OpenApi: Enum type is missing when using JsonStringEnumConverter

2 participants