a-h / generate

Generates Go (golang) Structs from JSON schema.
MIT License
444 stars 137 forks source link

Feature/add defaults values #42

Closed ESegundoRolon closed 6 years ago

ESegundoRolon commented 6 years ago

I add support for default values as the schema specifications declares: http://json-schema.org/draft-07/json-schema-validation.html#rfc.section.10.2 The client of this library needs to check if multiple default values are provided. Also needs to check if the type of default value is correct

Example:

In the following JSON schema...

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "foo",
    "properties": {
        "foo": {
                "type": "string",
                "default":"foo"
        }
    }
}

... the default value will be parsed and available into the property Default

The following JSON schema:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "foo",
    "properties": {
        "foo": {
                "type": "int",
                "default":"foo"
        }
    }
}

...should be validated by the library client