Marwes / schemafy

Crate for generating rust types from a json schema
MIT License
242 stars 51 forks source link

Inline enums are not translated #9

Open Marwes opened 6 years ago

Marwes commented 6 years ago

From https://github.com/Marwes/schemafy/blob/master/tests/vega/vega.json

{
    "$ref": "#/definitions/TopLevelExtendedSpec",
    "$schema": "http://json-schema.org/draft-04/schema#",
    "definitions": {
        "BarConfig": {
            "additionalProperties": false,
            "properties": {
                "cursor": {
                    "enum": [
                        "auto",
                        "default",
                        "none"
                    ],
                    "type": "string"
                },
                "type": "object"
            }
        }
    }
}

BarConfig gets assigned the type Option<String> instead of a specific enum type.

waywardmonkeys commented 6 years ago

This is one that I noticed happening a lot as well.

Marwes commented 6 years ago

Inline structs are handled at https://github.com/Marwes/schemafy/blob/7871e2152e0f827ce8c0f6901fb1220eb5b9f35d/src/lib.rs#L351-L360 .

Enums need to do the same thing, generate a new name expand the schema and push it to self.types (which gets emitted later on).