-
Notifications
You must be signed in to change notification settings - Fork 198
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
Support patternProperties #1859
Comments
I tried to read the code to contribute fix but didn't understand where to start. |
Honestly, this was my question - how to use |
Thanks for the report. Can you provide a minimal reproducible example that demonstrates the issue? |
#!/bin/bash
# Create input file
echo 'export type A = `wifi${number}`;' > test_str.ts
# Expected output
cat <<EOF > expected_str.json
{
"\$ref": "#/definitions/A",
"\$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"A": {
"type": "string",
"pattern": "^wifi[0-9]+$"
}
}
}
EOF
# Actual output
# Generate schema using ts-json-schema-generator
npx ts-json-schema-generator --path test_str.ts --out actual_str.json
# Compare actual and expected output
diff -u1 --color expected_str.json actual_str.json
Output: bash mre.sh --- expected_str.json 2024-05-28 09:46:21.504403302 +0300
+++ actual_str.json 2024-05-28 09:46:22.776424172 +0300
@@ -5,6 +5,5 @@
"A": {
- "type": "string",
- "pattern": "^wifi[0-9]+$"
+ "type": "string"
}
}
-}
+} |
My current solution is to use annotations, which works in some (not all) cases, but seems a redundant. |
@ELigoP Can you show a small example, pls? |
@se-panfilov I don't see how the problem could be reduced further. In case it's the way it's formatted: The input: export type A = `wifi${string}`; The output: {
"$ref": "#/definitions/A",
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"A": {
"type": "string"
}
}
} The expected output, something like: {
"$ref": "#/definitions/A",
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"A": {
"type": "string",
"pattern": "^wifi.*$"
}
}
} Alternatively, use comments to preserve the typescript def. |
I changed the issue to be a feature request then. The request is to generate a pattern for template strings. Note that |
Yeahhhh but by that logic you could simplify this project a lot by returning Are there other cases where the type conversion is lossy? It'd be nice if there was an option to fail the conversion in these cases, or to include a comment with the typescript type that couldn't be losslessly converted. |
Yes, that would be valid but a lot less useful. I'm just saying it to justify making this an enhancement rather than a bug. I'm still completely in favor of fixing this issue! I'm sure there are other cases where json schema is not as expressive as typescript. |
Typescript-restricted key (fail)
Annotated string (pass)
Annotated key (kinda pass)
Real life object (fail)
The text was updated successfully, but these errors were encountered: