Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PIE-176 Support more WKTs #6

Merged
merged 12 commits into from
Sep 19, 2024
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/.idea
bin/
47 changes: 22 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
default: build
.PHONY: build install, build_linux samples test

build:
@echo "Generating binary (protoc-gen-jsonschema) ..."
@mkdir -p bin
@go build -o bin/protoc-gen-jsonschema cmd/protoc-gen-jsonschema/main.go
mkdir -p bin
go build -o bin/protoc-gen-jsonschema cmd/protoc-gen-jsonschema/main.go

install:
@GO111MODULE=on go get -u github.com/chrusty/protoc-gen-jsonschema/cmd/protoc-gen-jsonschema && go install github.com/chrusty/protoc-gen-jsonschema/cmd/protoc-gen-jsonschema
GO111MODULE=on go get -u github.com/sixt/protoc-gen-jsonschema/cmd/protoc-gen-jsonschema && go install github.com/sixt/protoc-gen-jsonschema/cmd/protoc-gen-jsonschema

build_linux:
@echo "Generating Linux-amd64 binary (protoc-gen-jsonschema.linux-amd64) ..."
@GOOS=linux GOARCH=amd64 go build -o protoc-gen-jsonschema.linux-amd64
GOOS=linux GOARCH=amd64 go build -o protoc-gen-jsonschema.linux-amd64

PROTO_PATH ?= "internal/converter/testdata/proto"
samples:
@echo "Generating sample JSON-Schemas ..."
@mkdir -p jsonschemas
@PATH=./bin:$$PATH; protoc --jsonschema_out=allow_null_values:jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/ArrayOfMessages.proto 2>/dev/null || echo "No messages found (ArrayOfMessages.proto)"
@PATH=./bin:$$PATH; protoc --jsonschema_out=allow_null_values:jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/ArrayOfObjects.proto 2>/dev/null || echo "No messages found (ArrayOfObjects.proto)"
@PATH=./bin:$$PATH; protoc --jsonschema_out=allow_null_values:jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/ArrayOfPrimitives.proto 2>/dev/null || echo "No messages found (ArrayOfPrimitives.proto)"
@PATH=./bin:$$PATH; protoc --jsonschema_out=disallow_additional_properties:jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/Enumception.proto 2>/dev/null || echo "No messages found (Enumception.proto)"
@PATH=./bin:$$PATH; protoc --jsonschema_out=disallow_additional_properties:jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/ImportedEnum.proto 2>/dev/null || echo "No messages found (ImportedEnum.proto)"
@PATH=./bin:$$PATH; protoc --jsonschema_out=disallow_additional_properties:jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/NestedMessage.proto 2>/dev/null || echo "No messages found (NestedMessage.proto)"
@PATH=./bin:$$PATH; protoc --jsonschema_out=disallow_bigints_as_strings:jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/NestedObject.proto 2>/dev/null || echo "No messages found (NestedObject.proto)"
@PATH=./bin:$$PATH; protoc --jsonschema_out=disallow_bigints_as_strings:jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/PayloadMessage.proto 2>/dev/null || echo "No messages found (PayloadMessage.proto)"
@PATH=./bin:$$PATH; protoc --jsonschema_out=disallow_bigints_as_strings:jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/SeveralEnums.proto 2>/dev/null || echo "No messages found (SeveralEnums.proto)"
@PATH=./bin:$$PATH; protoc --jsonschema_out=disallow_bigints_as_strings:jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/SeveralMessages.proto 2>/dev/null || echo "No messages found (SeveralMessages.proto)"
@PATH=./bin:$$PATH; protoc --jsonschema_out=jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/ArrayOfEnums.proto 2>/dev/null || echo "No messages found (SeveralMessages.proto)"
@PATH=./bin:$$PATH; protoc --jsonschema_out=jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/Maps.proto 2>/dev/null || echo "No messages found (Maps.proto)"
@PATH=./bin:$$PATH; protoc --jsonschema_out=jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/MessageWithComments.proto 2>/dev/null || echo "No messages found (MessageWithComments.proto)"
@PATH=./bin:$$PATH; protoc -I /usr/include --jsonschema_out=jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/WellKnown.proto
samples: build
mkdir -p jsonschemas
PATH=./bin:$$PATH; protoc --jsonschema_out=allow_null_values:jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/ArrayOfMessages.proto
PATH=./bin:$$PATH; protoc --jsonschema_out=allow_null_values:jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/ArrayOfObjects.proto
PATH=./bin:$$PATH; protoc --jsonschema_out=allow_null_values:jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/ArrayOfPrimitives.proto
PATH=./bin:$$PATH; protoc --jsonschema_out=disallow_additional_properties:jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/Enumception.proto
PATH=./bin:$$PATH; protoc --jsonschema_out=disallow_additional_properties:jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/ImportedEnum.proto
PATH=./bin:$$PATH; protoc --jsonschema_out=disallow_additional_properties:jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/NestedMessage.proto
PATH=./bin:$$PATH; protoc --jsonschema_out=disallow_bigints_as_strings:jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/NestedObject.proto
PATH=./bin:$$PATH; protoc --jsonschema_out=disallow_bigints_as_strings:jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/PayloadMessage.proto
PATH=./bin:$$PATH; protoc --jsonschema_out=disallow_bigints_as_strings:jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/SeveralEnums.proto
PATH=./bin:$$PATH; protoc --jsonschema_out=disallow_bigints_as_strings:jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/SeveralMessages.proto
PATH=./bin:$$PATH; protoc --jsonschema_out=jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/ArrayOfEnums.proto
PATH=./bin:$$PATH; protoc --jsonschema_out=jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/Maps.proto
PATH=./bin:$$PATH; protoc --jsonschema_out=jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/MessageWithComments.proto
PATH=./bin:$$PATH; protoc -I /usr/include --jsonschema_out=jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/WellKnown.proto

test:
@go test ./... -cover
go test ./... -cover
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This will hopefully be useful for people who define their data using ProtoBuf, b

Installation
------------
`GO111MODULE=on go get -u github.com/chrusty/protoc-gen-jsonschema/cmd/protoc-gen-jsonschema && go install github.com/chrusty/protoc-gen-jsonschema/cmd/protoc-gen-jsonschema`
`GO111MODULE=on go get -u github.com/sixt/protoc-gen-jsonschema/cmd/protoc-gen-jsonschema && go install github.com/sixt/protoc-gen-jsonschema/cmd/protoc-gen-jsonschema`

Links
-----
Expand Down
3 changes: 2 additions & 1 deletion internal/converter/sourcecodeinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
)

// Protobuf tag values for relevant message fields. Full list here:
// https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/descriptor.proto
//
// https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/descriptor.proto
const (
tag_FileDescriptor_messageType int32 = 4
tag_FileDescriptor_enumType int32 = 5
Expand Down
21 changes: 20 additions & 1 deletion internal/converter/testdata/proto/WellKnown.proto
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
syntax = "proto3";
package samples;

import "google/protobuf/duration.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/struct.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/wrappers.proto";

message WellKnown {
google.protobuf.StringValue string_value = 1;
map<int32, google.protobuf.Int32Value> map_of_integers = 2;
map<int32, int32> map_of_scalar_integers = 3;
repeated google.protobuf.Int32Value list_of_integers = 4;
}

google.protobuf.BoolValue bool_value = 5;
google.protobuf.BytesValue bytes_value = 6;
google.protobuf.DoubleValue double_value = 7;
google.protobuf.Duration duration = 8;
google.protobuf.Empty empty = 9;
google.protobuf.FloatValue float_value = 10;
google.protobuf.Int32Value int32_value = 11;
google.protobuf.Int64Value int64_value = 12;
google.protobuf.ListValue list_value = 13;
google.protobuf.NullValue null_value = 14;
google.protobuf.Struct struct = 15;
google.protobuf.Timestamp timestamp = 16;
google.protobuf.UInt32Value uint32_value = 17;
google.protobuf.UInt64Value uint64_value = 18;
}
137 changes: 137 additions & 0 deletions internal/converter/testdata/wellknown.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,143 @@ const WellKnown = `{
]
},
"type": "array"
},
"bool_value": {
"oneOf": [
{
"type": "null"
},
{
"type": "boolean"
}
]
},
"bytes_value": {
"oneOf": [
{
"type": "null"
},
{
"type": "string"
}
]
},
"double_value": {
"oneOf": [
{
"type": "null"
},
{
"type": "number"
}
]
},
"duration": {
"oneOf": [
{
"type": "null"
},
{
"pattern": "^[0-9]+(\\.[0-9]{0,9})?s$",
"type": "string",
"format": "regex"
}
]
},
"empty": {
"oneOf": [
{
"type": "null"
},
{
"additionalProperties": false,
"type": "object"
}
]
},
"float_value": {
"oneOf": [
{
"type": "null"
},
{
"type": "number"
}
]
},
"int32_value": {
"oneOf": [
{
"type": "null"
},
{
"type": "integer"
}
]
},
"int64_value": {
"oneOf": [
{
"type": "null"
},
{
"type": "string"
}
]
},
"list_value": {
"oneOf": [
{
"type": "null"
},
{
"type": "array"
}
]
},
"null_value": {
"type": "null"
},
"struct": {
"oneOf": [
{
"type": "null"
},
{
"type": "object"
}
]
},
"timestamp": {
"oneOf": [
{
"type": "null"
},
{
"type": "string",
"format": "date-time"
}
]
},
"uint32_value": {
"oneOf": [
{
"type": "null"
},
{
"type": "integer"
}
]
},
"uint64_value": {
"oneOf": [
{
"type": "null"
},
{
"type": "string"
}
]
}
},
"additionalProperties": true,
Expand Down
Loading