-
Notifications
You must be signed in to change notification settings - Fork 406
Convert json schema draft 06 const values to typescript const values #264
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
Conversation
Awesome! Open source at it's finest 👍. I like the simplicity of the solution. The simple example now works: export interface Foo {
bar: true;
} However, it seems that falsy values don't work yet 😈. {
"title": "Foo",
"required": ["bar", "baz", "qux", "quux"],
"type": "object",
"additionalProperties": false,
"properties": {
"bar": {
"const": false
},
"baz": {
"const": ""
},
"qux": {
"const": 0
},
"quux": {
"const": null
}
}
}
This results in: export interface Foo {
bar: {
[k: string]: any;
};
baz: {
[k: string]: any;
};
qux: {
[k: string]: any;
};
quux: {
[k: string]: any;
};
} |
The falsy value thingy should be fixed in djbeaumont#1 🤟 |
ahh great catch, thank you! |
Support falsy values in `const` declarations
@bcherny what do you think of this? I suppose it would have to be a new major version as it will be a big change to the outputted types. |
@bcherny I don't want to be rude, but could you please take a look? I would like to actually use it at our company. Thanks! |
@nicojs Unfortunately bcherny maintains this package pretty unfrequently, I guess he'll accept this PR, but it could take a while. |
@nicojs FWIW I'm using this workaround in my codebase:
It works because the constant property I want to set happens to be the same as the filename of the schema that I'm parsing. Clearly not a general solution. |
@djbeaumont According to JSON Schema const is only a shorthand for enum with single element, so if you can modify original JSON Schema file, simply replace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there @djbeaumont! Thanks for the contribution, and sorry about the delay in reviewing it.
Since const
is just sugar for a single-member enum
, could we try to implement this as normalizer step instead that de-sugars const
to enum
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requesting changes per my comment above^
@djbeaumont I can't wait for this to make it in. Thank you so much for pursuing this! Do you expect to follow up soon with corrections so this can be merged in? |
What's the status on this? I found myself wanting to use |
Hi there? Any updates upcomming here? |
#290 is another shot at this, using the normalizer approach. |
Resolves #263
I'm a little unclear on the structure of the project so any feedback on the PR is gratefully received. This is a little exploratory and I have no idea if this can be said to implement the feature from json schema draft 06, but I think it covers enough for my needs.