Comments (2)
Hi, thanks for taking the time to report this bug report!
This is indeed a bug. The schema you provided is in fact not a valid JSON Type Definition schema -- the schema at /properties/bar/mapping/foo
is of the empty form, but mapping schemas must be of the properties form -- but jtd-codegen
should be providing a clear error message to this effect, and certainly shouldn't be panicking.
A bit more details on what schemas can appear inside mappings
is covered here: https://jsontypedef.com/docs/jtd-in-5-minutes/
You can only use properties / optionalProperties / additionalProperties in the schemas you put directly in mapping. You canβt use any other kind of schema, otherwise things would become ambiguous.
Admittedly, that language is a bit loose, and I understand how you would think that using no keywords at all would be kosher. The RFC is a bit more explicit: https://tools.ietf.org/html/rfc8927#section-2
; discriminator describes the "discriminator" schema form.
;
; There are additional constraints on this form that cannot be
; expressed in CDDL. Section 2.2.8 describes these additional
; constraints in detail.
discriminator = (
discriminator: tstr,
; Note well: this rule is defined in terms of the "properties"
; CDDL rule, not the "schema" CDDL rule.
mapping: { * tstr => { properties } }
shared,
)
But again: jtd-codegen
should not be leaving you out to dry like this.
In the immediate term, I suspect you'll have success if you alter your schema to be a valid JTD schema. For instance, just adding "properties": {}
to foo
would make your schema valid. This schema seems to work, at least for me:
{
"properties": {
"tag": {
"enum": [
"foo"
]
},
"bar": {
"discriminator": "tag",
"mapping": {
"foo": {
"properties": {}
}
}
}
}
}
In the longer term, the jtd-codegen
bug here is that the tool should validate a schema's correctness before attempting to generate code from it, and produce an error message rather than generate code (and ultimately crash).
from json-typedef-codegen.
Thank you for the prompt reply, and for taking the time to explain!
from json-typedef-codegen.
Related Issues (20)
- Java: Invalid NON_NULL annotation?
- Feature Request/Discussion: Golang string types for discriminator
- Is it possible to use it as a crate from the build.rs?
- codegen for c or c++
- Incorrect singularization of "drives" HOT 1
- Rust: tests broken by shifting dependency versions
- Arm64 support for jtd-codegen
- cant generate types from this jsonld schema HOT 2
- Add nullability annotations in generated Java code HOT 3
- Discriminator variant disapears when type name is overridden
- Go: Use private interfaces instead of generating structs for discriminating types HOT 1
- Python datetime serialisation/deserialisation not working correctly without timezone
- Permit specifying/overriding field names HOT 1
- Go: support for explicit embedded structs
- Remote resource support
- TypeScript: `any` vs `unknown` HOT 1
- How to generate classes part of build.gradle?
- Old url in repo settings
- Name JSON key when erroring
- Certain type names causes errors for Python codegen
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-typedef-codegen.