Skip to content

fix: infer omitted enum schema types - #191

Merged
nikcio merged 1 commit into
Nikcio-labs:mainfrom
geirsagberg-udir:geir/infer-enum-type
Sep 6, 2026
Merged

fix: infer omitted enum schema types#191
nikcio merged 1 commit into
Nikcio-labs:mainfrom
geirsagberg-udir:geir/infer-enum-type

Conversation

@geirsagberg-udir

Copy link
Copy Markdown
Contributor

Summary

  • infer string when every non-null enum value is a string
  • infer integer when every non-null enum value is an integral value supported by the generated C# enum
  • leave mixed, fractional, empty, and otherwise ambiguous enums untyped
  • preserve explicit OpenAPI type as authoritative

Why

ASP.NET Core with JsonStringEnumConverter can emit component schemas with string enum values but no type (dotnet/aspnetcore#61303). These currently fall through to an empty record. OpenAPI Generator 7.25.0 and NSwag 14.7.1 both infer a string enum for the same schema.

A schema containing only enum is valid, but enum values can technically mix JSON types. Inference is therefore limited to homogeneous values that map cleanly to the generator’s supported C# enum representations.

Verification

  • focused tests cover typeless string and integer enums plus mixed and fractional ambiguity
  • dotnet build --no-restore --configuration Release
  • dotnet test --no-build --configuration Release --verbosity normal (278 passed, 1 intentionally skipped)

@nikcio
nikcio enabled auto-merge (squash) September 6, 2026 10:12
@nikcio
nikcio merged commit e356447 into Nikcio-labs:main Sep 6, 2026
2 checks passed
@nikcio

nikcio commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

@geirsagberg-udir Thanks for this fix

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