Skip to content

Commit

Permalink
feat: Add mandatory_nullable and int64 as string option
Browse files Browse the repository at this point in the history
  • Loading branch information
uanid committed Sep 18, 2023
1 parent 010de0c commit c096734
Show file tree
Hide file tree
Showing 26 changed files with 713 additions and 507 deletions.
2 changes: 1 addition & 1 deletion examples/dump_example_request.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ cd $(dirname $0)

protoc \
--debug_out="." \
-I ../proto \
-I ../ \
-I ./ \
./example.proto
14 changes: 8 additions & 6 deletions examples/example.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import "google/protobuf/any.proto";
import "google/protobuf/duration.proto";

option (pubg.jsonschema.file) = {
entrypoint_message: "ArrayOfEnums";
entrypoint_message: "Values";
};

message Values {
// This is a comment
FirstForm first = 1 [(pubg.jsonschema.field) = {title: "A lorem ipsum", nullable: true}];
FirstForm second = 2;
optional FirstForm first = 1 [(pubg.jsonschema.field) = {title: "A lorem ipsum", nullable: true}];
optional FirstForm second = 2;
oneof oneof {
string a = 3;
string b = 4;
Expand Down Expand Up @@ -55,7 +55,9 @@ message SecondMessage {
}

enum MyEnum {
FOO = 0;
BAR = 1;
BAZ = 2;
option allow_alias = true;
ME_FOO = 0;
ME_BAR = 1;
ME_AAA = 1;
ME_BAZ = 2;
}
239 changes: 205 additions & 34 deletions examples/example.schema.json
Original file line number Diff line number Diff line change
@@ -1,55 +1,226 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$ref": "#/definitions/.schema.ArrayOfEnums",
"$ref": "#/definitions/.schema.Values",
"definitions": {
".schema.ArrayOfEnums": {
".schema.MyEnum": {
"type": "string",
"enum": [
"ME_FOO",
"ME_BAR",
"ME_AAA",
"ME_BAZ"
]
},
".schema.Values": {
"allOf": [
{
"oneOf": [
{
"required": [
"a"
]
},
{
"required": [
"b"
]
},
{
"not": {
"anyOf": [
{
"required": [
"a"
]
},
{
"required": [
"b"
]
}
]
}
}
]
},
{
"oneOf": [
{
"required": [
"first"
]
},
{
"not": {
"anyOf": [
{
"required": [
"first"
]
}
]
}
}
]
},
{
"oneOf": [
{
"required": [
"second"
]
},
{
"not": {
"anyOf": [
{
"required": [
"second"
]
}
]
}
}
]
}
],
"properties": {
"first": {
"oneOf": [
{
"type": "null"
},
{
"$ref": "#/definitions/.schema.Values.first"
}
]
},
"second": {
"oneOf": [
{
"type": "null"
},
{
"$ref": "#/definitions/.schema.Values.second"
}
]
},
"a": {
"oneOf": [
{
"type": "null"
},
{
"$ref": "#/definitions/.schema.Values.a"
}
]
},
"b": {
"oneOf": [
{
"type": "null"
},
{
"$ref": "#/definitions/.schema.Values.b"
}
]
}
},
"type": "object"
},
".schema.Values.first": {
"$ref": "#/definitions/.schema.FirstForm",
"title": "A lorem ipsum",
"description": "This is a comment"
},
".schema.Values.second": {
"$ref": "#/definitions/.schema.FirstForm"
},
".schema.Values.a": {
"type": "string"
},
".schema.Values.b": {
"type": "string"
},
".schema.FirstForm": {
"properties": {
"description": {
"$ref": "#/definitions/.schema.ArrayOfEnums.description"
"name": {
"$ref": "#/definitions/.schema.FirstForm.name"
},
"second_message": {
"$ref": "#/definitions/.schema.FirstForm.second_message"
},
"my_enum": {
"$ref": "#/definitions/.schema.FirstForm.my_enum"
},
"stuff": {
"$ref": "#/definitions/.schema.ArrayOfEnums.stuff"
"mymap": {
"$ref": "#/definitions/.schema.FirstForm.mymap"
},
"any": {
"$ref": "#/definitions/.schema.ArrayOfEnums.any"
"v1": {
"$ref": "#/definitions/.schema.FirstForm.v1"
},
"duration": {
"$ref": "#/definitions/.schema.ArrayOfEnums.duration"
"v2": {
"$ref": "#/definitions/.schema.FirstForm.v2"
},
"v3": {
"$ref": "#/definitions/.schema.FirstForm.v3"
}
},
"type": "object",
"required": [
"description",
"stuff",
"any",
"duration"
],
"title": "ArrayOfEnums"
},
".schema.ArrayOfEnums.InlineEnum": {
"type": "string",
"enum": [
"FOO",
"BAR",
"FIZZ",
"BUZZ"
"name",
"second_message",
"my_enum",
"mymap",
"v1",
"v2",
"v3"
]
},
".schema.ArrayOfEnums.description": {
".schema.FirstForm.name": {
"type": "string"
},
".schema.ArrayOfEnums.stuff": {
"additionalItems": {
"$ref": "#/definitions/.schema.ArrayOfEnums.InlineEnum"
},
"type": "array"
".schema.FirstForm.second_message": {
"$ref": "#/definitions/.schema.SecondMessage"
},
".schema.ArrayOfEnums.any": {
".schema.FirstForm.my_enum": {
"$ref": "#/definitions/.schema.MyEnum"
},
".schema.FirstForm.mymap": {
"additionalProperties": {
"type": "string"
},
"type": "object"
},
".schema.ArrayOfEnums.duration": {
"type": "string",
"format": "duration"
".schema.FirstForm.v1": {
"type": "string"
},
".schema.FirstForm.v2": {
"type": "integer"
},
".schema.FirstForm.v3": {
"type": "number"
},
".schema.SecondMessage": {
"properties": {
"a": {
"$ref": "#/definitions/.schema.SecondMessage.a"
},
"b": {
"$ref": "#/definitions/.schema.SecondMessage.b"
}
},
"type": "object",
"required": [
"a",
"b"
]
},
".schema.SecondMessage.a": {
"type": "string"
},
".schema.SecondMessage.b": {
"type": "string"
}
},
"type": "object"
Expand Down
2 changes: 1 addition & 1 deletion examples/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protoc \
--jsonschema_out=./ \
--jsonschema_opt=draft=Draft07 \
-I ./ \
-I ../proto \
-I ../ \
./example.proto

rm protoc-gen-jsonschema
2 changes: 1 addition & 1 deletion proto/generate.sh → generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -eux
cd $(dirname $0)

protoc \
--go_out=../pkg/proto \
--go_out=./pkg/proto \
--go_opt=paths=source_relative \
-I ./ \
./*.proto
Expand Down
Loading

0 comments on commit c096734

Please sign in to comment.