-
Notifications
You must be signed in to change notification settings - Fork 324
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
class bar: "ok" | "fail" | "abort" | string; should not only map to a string #164
Comments
Hmm, I think this may be a restriction of the typescript compiler if we use symbols. Can you try https://github.com/vega/ts-json-schema-generator and see whether it does the trick. The other library uses the AST. |
hmm... seems to generate exactly the same: {
"type": "object",
"properties": {
"foo": {
"type": "string",
"enum": [
"abort",
"fail",
"ok"
]
},
"bar": {
"type": "string"
}
},
"required": [
"foo",
"bar"
],
"$schema": "http://json-schema.org/draft-04/schema#"
} |
Okay. I'd say that's not really a bug since string literals are also strings and so Since this is not a bug, I am marking this as an enhancement. |
It will be a great enhancement. In visual studio code, for example, you never see with the auto completion strings "abort", "fail" and "ok" ... you see other unnecessary contextual auto generated strings and you're obviously free to insert also a string. With this enhancement you'll see "abort", "fail" and "ok" and you're also free to insert a common string. I used this schema combination for a very big schema before discover this great tool/library and it's absolutely super! Cheers, |
I just tested https://github.com/vega/ts-json-schema-generator and it produces something different from what you said (and already does what you ask for :-)) > [email protected] run /Users/domoritz/Developer/UW/ts-json-schema-generator
> ts-node ts-json-schema-generator.ts "--path" "test.ts" "--type" "MyObject"
{
"$ref": "#/definitions/MyObject",
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {
"MyObject": {
"additionalProperties": false,
"properties": {
"bar": {
"anyOf": [
{
"enum": [
"ok"
],
"type": "string"
},
{
"enum": [
"fail"
],
"type": "string"
},
{
"enum": [
"abort"
],
"type": "string"
},
{
"type": "string"
}
]
}
},
"required": [
"bar"
],
"type": "object"
}
}
} |
I created an issue for making the schema output a but nicer: vega/ts-json-schema-generator#20. |
I just gave a look at the string-literal-in-line test where I see that the expected result for the bar field is: ... will give a try tomorrow with my real case. Tnx in advance. Giuseppe |
Thanks for trying it. Let me know how it goes. |
ok Dominik, it does the job. I just forked your git. Thank you so much! Giuseppe |
Dominik, quick question: how can I redirect the output to a file? (original --output or -o parameter) G. |
Pipe it with >. You don't need to fork the repo. The library is available on npm. |
ok just like I did (pipe). Thank you so much again. Giuseppe |
Hi to everyone, test "string-literals-inline" field bar:
maps to schema:
but should map to schema:
Cheers,
Giuseppe
The text was updated successfully, but these errors were encountered: