GenSON icon indicating copy to clipboard operation
GenSON copied to clipboard

Enhancement: definitions support

Open DylanYoung opened this issue 6 years ago • 3 comments

I'd like to see support for definitions and a parameter to control when they're used. Most simple would be to a threshold for how many "objects of the same structure" to see before converting them to a single definition and references.

This is something I'd be interested in encoding if you're amenable :)

DylanYoung avatar Feb 12 '20 19:02 DylanYoung

I'm not entirely sure what you're asking for here. Could you elaborate or give some example of how you would want the API to behave?

wolverdude avatar Apr 11 '20 19:04 wolverdude

Basically the idea is that if the same "subschema" is encountered more than X times, it would be encoded in the resulting schema as a definition and referenced where it appears (using $defs and $ref), rather than being duplicated across the schema. Probably needs a bit more thought though as to how it behaves... Maybe it just depends on $defs being defined in the seed schema, then any place that matches a definition uses a $ref instead of inlining it?

DylanYoung avatar May 29 '22 00:05 DylanYoung

Ah, I see. Support for $def/$ref could be useful, especially when recursive structure is involved.

I wouldn’t want to dynamically infer that though. There’s too many edge-cases. I would do it with seed schemes where you can create a stub $def and place a $ref where you expect it to show up in the structure. GenSON would then automatically fill out the $def. This change probably wouldn’t be that hard to do, honestly. The biggest challenge would be keeping the definitions in-scope for each node.

Would that work for your use-case?

On Sat, May 28, 2022 at 5:10 PM DylanYoung @.***> wrote:

Basically the idea is that if the same "subschema" is encountered more than X times, it would be encoded in the resulting schema as a definition and referenced where it appears (using $defs https://json-schema.org/understanding-json-schema/structuring.html#defs and $ref, rather than being duplicated across the schema. Probably needs a bit more thought though as to how it behaves... Maybe it just depends on $defs being defined in the seed schema, then any place that matches a definition uses a $ref instead of inlining it?

— Reply to this email directly, view it on GitHub https://github.com/wolverdude/GenSON/issues/45#issuecomment-1140347147, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABAUATRVIMC3JTIY5KX544DVMKYYLANCNFSM4KUBMD5A . You are receiving this because you commented.Message ID: @.***>

wolverdude avatar Oct 11 '22 08:10 wolverdude