Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Renaming options to field_options (#84)
Browse files Browse the repository at this point in the history
* Renaming options to field_options (so we can fit in things like MessageOptions and FileOptions in future)

* Updated expected schema

Co-authored-by: Chrusty <>
  • Loading branch information
chrusty authored Sep 23, 2021
1 parent cf9fe3e commit 82b76ee
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 15 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ samples:
@PATH=./bin:$$PATH; protoc --jsonschema_out=jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/Proto2NestedMessage.proto || echo "No messages found (Proto2NestedMessage.proto)"
@PATH=./bin:$$PATH; protoc --jsonschema_out=jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/GoogleValue.proto || echo "No messages found (GoogleValue.proto)"
@PATH=./bin:$$PATH; protoc --jsonschema_out=jsonschemas -I. --proto_path=${PROTO_PATH} ${PROTO_PATH}/HiddenFields.proto || echo "No messages found (HiddenFields.proto)"
@PATH=./bin:$$PATH; protoc --jsonschema_out=jsonschemas -I. --proto_path=${PROTO_PATH} ${PROTO_PATH}/Proto3Required.proto || echo "No messages found (Proto3Required.proto)"
@PATH=./bin:$$PATH; protoc --jsonschema_out=enforce_oneof:jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/OneOf.proto || echo "No messages found (OneOf.proto)"
@PATH=./bin:$$PATH; protoc --jsonschema_out=all_fields_required:jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/Proto2NestedObject.proto || echo "No messages found (Proto2NestedObject.proto)"
@PATH=./bin:$$PATH; protoc -I /usr/include --jsonschema_out=jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/WellKnown.proto || echo "No messages found (WellKnown.proto)"
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ package samples;
import "options.proto";
message HiddenFields {
string visible1 = 1 [(protoc.gen.jsonschema.options).ignore = false];
string visible1 = 1 [(protoc.gen.jsonschema.field_options).ignore = false];
string visible2 = 2;
string hidden1 = 3 [(protoc.gen.jsonschema.options).ignore = true];
string hidden2 = 4 [deprecated = true, (protoc.gen.jsonschema.options).ignore = true];
string hidden1 = 3 [(protoc.gen.jsonschema.field_options).ignore = true];
string hidden2 = 4 [deprecated = true, (protoc.gen.jsonschema.field_options).ignore = true];
}
```

Expand All @@ -148,8 +148,8 @@ package samples;
import "options.proto";
message Proto3Required {
string query = 1 [(protoc.gen.jsonschema.options).required = true];
int32 page_number = 2 [deprecated = true, (protoc.gen.jsonschema.options).required = true];
string query = 1 [(protoc.gen.jsonschema.field_options).required = true];
int32 page_number = 2 [deprecated = true, (protoc.gen.jsonschema.field_options).required = true];
int32 result_per_page = 3;
}
```
Expand Down
2 changes: 1 addition & 1 deletion internal/converter/testdata/field_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ const FieldOptions = `{
},
"additionalProperties": true,
"type": "object",
"description": "Custom FieldOptions for protoc-gen-jsonschema:"
"description": "Custom FieldOptions:"
}`
6 changes: 3 additions & 3 deletions internal/converter/testdata/proto/HiddenFields.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package samples;
import "options.proto";

message HiddenFields {
string visible1 = 1 [(protoc.gen.jsonschema.options).ignore = false];
string visible1 = 1 [(protoc.gen.jsonschema.field_options).ignore = false];
string visible2 = 2;
string hidden1 = 3 [(protoc.gen.jsonschema.options).ignore = true];
string hidden2 = 4 [deprecated = true, (protoc.gen.jsonschema.options).ignore = true];
string hidden1 = 3 [(protoc.gen.jsonschema.field_options).ignore = true];
string hidden2 = 4 [deprecated = true, (protoc.gen.jsonschema.field_options).ignore = true];
}
4 changes: 2 additions & 2 deletions internal/converter/testdata/proto/Proto3Required.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package samples;
import "options.proto";

message Proto3Required {
string query = 1 [(protoc.gen.jsonschema.options).required = true];
int32 page_number = 2 [deprecated = true, (protoc.gen.jsonschema.options).required = true];
string query = 1 [(protoc.gen.jsonschema.field_options).required = true];
int32 page_number = 2 [deprecated = true, (protoc.gen.jsonschema.field_options).required = true];
int32 result_per_page = 3;
}
20 changes: 20 additions & 0 deletions jsonschemas/Proto3Required.jsonschema
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"required": [
"query",
"page_number"
],
"properties": {
"query": {
"type": "string"
},
"page_number": {
"type": "integer"
},
"result_per_page": {
"type": "integer"
}
},
"additionalProperties": true,
"type": "object"
}
11 changes: 7 additions & 4 deletions options.proto
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
// Custom options for protoc-gen-jsonschema
// Allocated range is 1125-1129
// See https://github.com/protocolbuffers/protobuf/blob/master/docs/options.md

syntax = "proto3";
package protoc.gen.jsonschema;
import "google/protobuf/descriptor.proto";
option go_package = "./protos";

// Custom FieldOptions for protoc-gen-jsonschema:

// Custom FieldOptions:
message FieldOptions {

// Fields tagged with this will be omitted from generated schemas:
Expand All @@ -14,8 +19,6 @@ message FieldOptions {
}


// Custom FieldOptions using our legitimate registered number:
// https://github.com/protocolbuffers/protobuf/blob/master/docs/options.md
extend google.protobuf.FieldOptions {
FieldOptions options = 1125;
FieldOptions field_options = 1125;
}

0 comments on commit 82b76ee

Please sign in to comment.