chrusty / protoc-gen-jsonschema

Protobuf to JSON-Schema compiler
Apache License 2.0
496 stars 101 forks source link

Question: Is there a way to have root message being not reference #140

Closed metsawyr closed 1 year ago

metsawyr commented 1 year ago

Is there a way to generate json schema in a way, so the root object is placed in root level instead of being referenced from definitions? Meaning not in $ref, but containing all the properties at the root level.

chrusty commented 1 year ago

Hi @metsawyr, thanks for your interest.

No - currently there is no option to generate JSON schemas in this way. The libraries I'm using here default to this behaviour of "re-usable" schemas and references, I guess because it makes efficient code when you reuse them. Previous versions DID have the behaviour you're after, but that opened up a range of other problems and the current behaviour is preferable.

Having said that, the "root" objects you're referring to will still function perfectly well as JSON schemas, and validate correctly. They may appear slightly more complex than necessary, but other than that are functionally the same.

Is there any specific reason you'd rather they rendered differently?

metsawyr commented 1 year ago

Yep, the reason is that the integration platform we generate these json schema for, can't import files without root declaration for some reason. Just was wondering if I am able to do this with just he library, or I have to build a script to fix that.

Thank you