Best way to extend JSON schema parsing #1781
Replies: 1 comment
-
|
Thank you for the detailed proposal and use case explanation. While I understand the value of making I'd like to revisit this after v1 is released and the API has stabilized. At that point, we can consider the best approach without risking breaking changes. Thank you for your contribution and understanding! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have been looking into ways to automatically generate data models for a large and growing collection of schemas that I need to work with. After some experimentation and exploration it appears that the
datamodel-code-generatorappears to be a good project to build what I need off of. However, due to the peculiarities of the schemas I have to work with, the standard JSON schema parser used bydatamodel-code-generator(or any similar project) is not sufficient to capture some of the features I need to extract from my schemas. Thus I believe that I will have to do some extensions to the JSON schema parser that is currently present.For background, the core of my issue is that the schemas in question employ an extension of JSON schema. This extension essentially adds a mechanism,
tag, which is roughly equivalent to$refbut it carries additional information. Namely, our application of JSON schema is validation of YAML data which includes sections which are tagged with YAML tags. Our validation of thetagworks via validating the data using the schema associated with the specific tag including any refinements usingallOfcombiners. However, in addition to the$ref-like behavior, thetaglisted in the schema is also validated against the YAML tag present. While we currently have a system in place to validate data already written to these YAML files, we do not have a good system (its an entirely ad-hoc data model like scheme) to work with building data to write; hence, the desire to generate data models matching the schemas.After doing some prototyping with the current version of
datamodel-code-generatorI have found that I can achieve most of functionality I need. I can do this in two steps:JsonSchemaObject, call itTaggedJsonSchemaObject, to include atagfield and then adding amodel_post_initmethod to that extension which looks up the correct$reffor a giventagand then fills in that information.JsonSchemaParserto then employTaggedJsonSchemaObjectinstead ofJsonSchemaObject.This ends up solving most of the issues I have, but getting the
JsonSchemaParserextension to work properly requires duplicating several methods exactly with the only change being replacingJsonSchemaObjectwithTaggedSchemaObject. These are:parse_combined_schemaparse_raw_obj_parse_fileWhile this approach works, it does not feel like a good approach as it is quite prone to being broken by changes to
JsonSchemaParserin the future. Thus my question(s):datamodel-code-generatorbe interested in an enhancement to make it easier to replace theJsonSchemaObjectinJsonSchemaParser?Edit:
My suggested enhancement is something akin to these changes.
Beta Was this translation helpful? Give feedback.
All reactions