Skip to content

fix: respect constAsEnum in all const-emitting code paths(#588) - #637

Open
won-N-only wants to merge 1 commit into
YousefED:masterfrom
won-N-only:fix/const-as-enum-all-paths
Open

won-N-only wants to merge 1 commit into
YousefED:masterfrom
won-N-only:fix/const-as-enum-all-paths

Conversation

@won-N-only

Copy link
Copy Markdown

Fixes #588

Problem

constAsEnum is only respected in one of the three places that emit a single fixed value:

location path respects
typescript-json-schema.ts:776 literal type yes
typescript-json-schema.ts:973 enum member type no
typescript-json-schema.ts:1035 union collapsing to one value no

So const still leaks out with the flag on, and the document is not valid OpenAPI 3.0:

interface MyObject {
    reference: true;   // { "enum": [true] }  ok
    member: Enum.X;    // { "const": 0 }      expected { "enum": [0] }
}

What changed

The const-vs-enum decision moves into one setSingleValue helper used by all three sites, so they cannot drift apart again. It returns the definition, which keeps the union site's original ternary.

Two test cases added — an enum member type, and the reproduction from #588. Both fail on branch master.

Impact

None when constAsEnum is off, which is the default. The existing enums-value-in-interface test covers the same enum member shape with the flag off, still expects const, and passes unchanged.


  • Make your pull request atomic, fixing one issue at a time unless there are many relevant issues that cannot be decoupled.
  • Provide a test case & update the documentation in the Readme.md
    Readme.md is unchanged: --constAsEnum is already documented there and this makes the implementation match it.

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.

constAsEnum not aways working in combination with strictNullChecks

1 participant