Skip to content

fix(plugin): handle IsIn enum inference when type falls back to Object#3876

Merged
kamilmysliwiec merged 1 commit into
nestjs:masterfrom
y-hsgw:fix/plugin-string-literal-union-type
Apr 27, 2026
Merged

fix(plugin): handle IsIn enum inference when type falls back to Object#3876
kamilmysliwiec merged 1 commit into
nestjs:masterfrom
y-hsgw:fix/plugin-string-literal-union-type

Conversation

@y-hsgw

@y-hsgw y-hsgw commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

classValidatorShim can emit enum metadata from @IsIn(...), but when the plugin falls back to type: () => Object for a literal-union property, 11.4.1 keeps type: object in the generated schema. That produces an invalid schema for downstream tools.

Issue Number: N/A

What is the new behavior?

When schema metadata has enum and the inferred type is the plugin fallback Object, SchemaObjectFactory now infers the scalar schema type from the enum values instead of keeping object.

Example output:

{
  "type": "string",
  "enum": ["a", 1]
}

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

  • Added regression coverage in test/services/schema-object-factory.spec.ts for type: () => Object + enum metadata.
  • Added plugin coverage in test/plugin/model-class-visitor.spec.ts for @IsIn(['a', 1]) on a literal-union property.

@y-hsgw y-hsgw marked this pull request as draft April 24, 2026 13:28
@y-hsgw y-hsgw changed the title fix(plugin): resolve string literal union type as String instead of Object fix(plugin): handle IsIn enum inference when type falls back to Object Apr 24, 2026
@y-hsgw y-hsgw force-pushed the fix/plugin-string-literal-union-type branch from 7d9755d to 9a3745b Compare April 24, 2026 13:57
@y-hsgw y-hsgw marked this pull request as ready for review April 24, 2026 13:58
@kamilmysliwiec kamilmysliwiec merged commit a51cf09 into nestjs:master Apr 27, 2026
1 check passed
@y-hsgw y-hsgw deleted the fix/plugin-string-literal-union-type branch April 28, 2026 01:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants