Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

constant number is converted to a generic number type #1912

Closed
Wassap124 opened this issue Apr 11, 2024 · 4 comments
Closed

constant number is converted to a generic number type #1912

Wassap124 opened this issue Apr 11, 2024 · 4 comments

Comments

@Wassap124
Copy link

Wassap124 commented Apr 11, 2024

Trying to upgrade to the new 1.5.1 2.0.1 version.

I have a type definition with a constant number:

type Configuration = { version?: number }; // along with other stuff
type ConfigurationV1 = Configuration & { version: 1 };
type ConfigurationV2 = Configuration & { version: 2 };

the generated schemas in 1.5.0 USED TO include the hard-coded value for the specific versions, like so:

"version": {
   "const": 2,
   "type": "number"
}

but now it's generated without the const part
im using
pnpm@7.33.4
node@20.12.1

@domoritz
Copy link
Member

I just tried it with the latest version and get this

yarn --silent run run --path 'test.ts' --type '*'
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "Configuration": {
      "additionalProperties": false,
      "properties": {
        "version": {
          "type": "number"
        }
      },
      "type": "object"
    },
    "ConfigurationV1": {
      "additionalProperties": false,
      "properties": {
        "version": {
          "const": 1,
          "type": "number"
        }
      },
      "required": [
        "version"
      ],
      "type": "object"
    },
    "ConfigurationV2": {
      "additionalProperties": false,
      "properties": {
        "version": {
          "const": 2,
          "type": "number"
        }
      },
      "required": [
        "version"
      ],
      "type": "object"
    }
  }
}

I think this is fixed.

@Wassap124
Copy link
Author

by latest you mean 2.0.1, right?

@Wassap124
Copy link
Author

Wassap124 commented Apr 15, 2024

just tried in 2.0.1, it persists for me

@domoritz

@domoritz
Copy link
Member

Try the next branch and show me an example.

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

No branches or pull requests

2 participants