chrusty / protoc-gen-jsonschema

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

Handling default in proto2 #184

Open alexloginov opened 7 months ago

alexloginov commented 7 months ago

Hi!

Is there a way to include to Json Schema default values of the fields? Proto2 supports defaults.

Example:

message MyMsg {
    optional string a = 1 ;
    optional string b = 2 [default = "NOT_SPECIFIED"];
}

I would expect to see something like:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "$ref": "#/definitions/Lifecycle",
    "definitions": {
        "MyMsg": {
            "properties": {
                "a": {
                    "type": "string"
                },
                "minor": {
                    "b": "string",
                    "default": "NOT_SPECIFIED"
                }
            },
            "additionalProperties": true,
            "type": "object",
            "title": "MyMsg"
        }
    }
}