-
Notifications
You must be signed in to change notification settings - Fork 9
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
intermediate typedef #55
Comments
What is the issue here? |
I want generale a schema for the JSON generated. |
Isn't |
I wanted to generate a JSON schema. But Can be right also only have a new typedef forse the JSON generated |
I don't understand the second part. Isn't |
Imagine this enum
i would like to have this typedef
in this mode i can generate also the schema for example for typescript or jsonschema |
Ah, ok ... I understand now. Well, this could be interesting, in particular because we now allow the type to vary depending on constructor :D |
yes, |
this can be related HaxeFoundation/haxe#4630 |
@francescoagati your linked issue is probably not related. Because tink_json has its own way to serialize haxe enums which is independent of the enum's runtime representation. |
@kevinresol yes i know. now i am working on a library for generate typefed compatible with tink_json for the generation of the enum. when i have finish i will publish this on github |
I have strong belief in TypeScript that it can handle this with something like:
But I don't think it worth the trouble creating Haxe typedefs (or is it even possible to create a useful one?) |
Yeah, in Haxe this will probably be super awkward. What might be interesting is the ability to generate json schema, although that will also hit a wall when it comes to custom parsers/serializers and such. |
for example jhttps://lib.haxe.org/p/json2object/ json2Object has a JsonSchemaWriter for generate a jsonschema but for use it with typescript i need to do two steps for convert the jsonschema in typescript. i would like to use a intermediate typedef because in this mode i can expose this typed in typescript using hxtsdgen |
What's the problem with json-schema-to-typescript? |
yes is only for haven't a two steps passage |
So I just tried JSON Schema and I think it is expressive enough to describe tink_json's output. enum Color {
White;
Hsl(value:{ hue:Float, saturation:Float, lightness:Float });
Hsv(hsv:{ hue:Float, saturation:Float, value:Float });
} Schema: {
"oneOf": [
{ "type": "string", "const": "White" },
{
"type": "object",
"required": ["Hsl"],
"properties": {
"Hsl": {
"type": "object",
"required": ["value"],
"properties": {
"value": {
"type": "object",
"required": ["hue", "lightness", "saturation"],
"properties": {
"hue": {
"type": "number"
},
"lightness": {
"type": "number"
},
"saturation": {
"type": "number"
}
}
}
}
}
}
},
{
"type": "object",
"required": ["Hsv"],
"properties": {
"Hsv": {
"type": "object",
"required": ["hue", "saturation", "value"],
"properties": {
"hue": {
"type": "number"
},
"saturation": {
"type": "number"
},
"value": {
"type": "number"
}
}
}
}
}
]
} Examples: "White"
{"Hsv":{"hue":1,"saturation":2,"value":3}}
{"Hsl":{"value":{"hue":1,"lightness":3,"saturation":2}}} |
Json2Object support json schema |
I made a branch with initial support of json schema: https://github.com/haxetink/tink_json/tree/schema but further work is still needed to support custom rules ( |
hi,
in a case like this can be possible have the typedef intermedie generated for the json definition?
The text was updated successfully, but these errors were encountered: