mbknor / mbknor-jackson-jsonSchema

Generate JSON Schema with Polymorphism using Jackson annotations
MIT License
235 stars 79 forks source link

Support for generating a file per class #163

Open chrisguiney opened 2 years ago

chrisguiney commented 2 years ago

It'd be great if I'd be able to generate a file per class without duplicating class definitions --

that is, instead of referencing any classes used for properties in the definitions clause, instead allow referencing them by filename.

For example, see this schema:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "additionalProperties": false,
    "properties": {
        "ReferenceToLocalSchema": {
            "$ref": "#/definitions/LocalType"
        },
        "ReferenceToExternalSchema": {
            "$ref": "Bar.json"
        }
    },
    "definitions": {
        "LocalType": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "no-write": {
                    "type": "boolean",
                    "default": false
                }
            }
        }
    }
}

where Bar.json would be another schema in the same directory.

I'm not incredibly familiar with scala, but I'm happy to give it a shot, if you're open to supporting the feature.

Alternatively, allowing multiple classes to be generated in the same schema without doing something like creating a root class.

My basic use case is that I've got a collection of classes that I'm generating schemas for, and some of them are included in others. This is really frustrating when trying to use a code generator, which will generate the same class multiple times.

Any input/advice welcomed.