Skip to content
This repository has been archived by the owner on May 3, 2023. It is now read-only.

Handle google/protobuf/wrappers.proto types on protoc-gen-openapi #1

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

galihputera
Copy link
Collaborator

@galihputera galihputera commented Sep 1, 2022

According to https://developers.google.com/protocol-buffers/docs/proto3#json, Wrapper Types use the same representation in JSON as the wrapped primitive type. On this MR I Modify protoc-gen-openapi code to be able to parse Wrapper Types on schema and parameters.

Also in this MR is changes to map google.protobuf.Timestamp field into string when used as URL query parameters. Previously it will be mapped into two separate fields, for example timestamp_type will mapped into timestampType.seconds and timestampType.nanos
image

Manual Testing

Unit Test

Steps

make all
go test ./...

Result

ok      github.com/google/gnostic       0.702s
?       github.com/google/gnostic/cmd/disco     [no test files]
?       github.com/google/gnostic/cmd/parse-linter-output       [no test files]
ok      github.com/google/gnostic/cmd/petstore-builder  0.468s
ok      github.com/google/gnostic/cmd/protoc-gen-jsonschema     0.745s
?       github.com/google/gnostic/cmd/protoc-gen-jsonschema/generator   [no test files]
ok      github.com/google/gnostic/cmd/protoc-gen-openapi        1.900s
?       github.com/google/gnostic/cmd/protoc-gen-openapi/generator      [no test files]
?       github.com/google/gnostic/cmd/protoc-gen-openapi/generator/wellknown    [no test files]
?       github.com/google/gnostic/cmd/report    [no test files]
?       github.com/google/gnostic/cmd/report-messages   [no test files]
?       github.com/google/gnostic/cmd/vocabulary-operations     [no test files]
ok      github.com/google/gnostic/compiler      0.110s
?       github.com/google/gnostic/conversions   [no test files]
ok      github.com/google/gnostic/discovery     0.375s
ok      github.com/google/gnostic/extensions    0.302s
?       github.com/google/gnostic/extensions/sample/generated/gnostic-x-sampleone       [no test files]
?       github.com/google/gnostic/extensions/sample/generated/gnostic-x-sampleone/proto [no test files]
?       github.com/google/gnostic/extensions/sample/generated/gnostic-x-sampletwo       [no test files]
?       github.com/google/gnostic/extensions/sample/generated/gnostic-x-sampletwo/proto [no test files]
ok      github.com/google/gnostic/generate-gnostic      1.077s
?       github.com/google/gnostic/jsonschema    [no test files]
ok      github.com/google/gnostic/jsonwriter    1.077s
?       github.com/google/gnostic/lib   [no test files]
?       github.com/google/gnostic/linters/go/gnostic-lint-descriptions  [no test files]
?       github.com/google/gnostic/linters/go/gnostic-lint-paths [no test files]
?       github.com/google/gnostic/metrics       [no test files]
?       github.com/google/gnostic/metrics/lint  [no test files]
?       github.com/google/gnostic/metrics/metrics       [no test files]
ok      github.com/google/gnostic/metrics/rules 0.779s
ok      github.com/google/gnostic/metrics/sourceinfo    0.927s
ok      github.com/google/gnostic/metrics/vocabulary    0.773s
ok      github.com/google/gnostic/openapiv2     0.596s
ok      github.com/google/gnostic/openapiv3     0.500s
?       github.com/google/gnostic/openapiv3/schema-generator    [no test files]
ok      github.com/google/gnostic/plugins       0.453s
?       github.com/google/gnostic/plugins/gnostic-analyze       [no test files]
?       github.com/google/gnostic/plugins/gnostic-analyze/statistics    [no test files]
?       github.com/google/gnostic/plugins/gnostic-analyze/summarize     [no test files]
ok      github.com/google/gnostic/plugins/gnostic-complexity    0.214s
?       github.com/google/gnostic/plugins/gnostic-linter        [no test files]
?       github.com/google/gnostic/plugins/gnostic-plugin-request        [no test files]
?       github.com/google/gnostic/plugins/gnostic-process-plugin-response       [no test files]
?       github.com/google/gnostic/plugins/gnostic-summary       [no test files]
ok      github.com/google/gnostic/plugins/gnostic-vocabulary    0.166s
?       github.com/google/gnostic/printer       [no test files]
?       github.com/google/gnostic/surface       [no test files]
?       github.com/google/gnostic/tools/format-schema   [no test files]
?       github.com/google/gnostic/tools/j2y2j   [no test files]

Check generated openapi using Swagger UI

Command

cd cmd/protoc-gen-openapi
protoc -I ../../ -I ../../third_party -I examples examples/tests/protobuftypes/message.proto --openapi_out=naming=proto:.
docker run -p 8080:8080 -e SWAGGER_JSON=/api.yaml -v $(pwd)/openapi.yaml:/api.yaml swaggerapi/swagger-ui

Result on Query String

image

Result on Schema

image

@galihputera galihputera changed the title handle wrappers type on protoc-gen-openapi Handle google/protobuf/wrappers.proto types on protoc-gen-openapi Sep 1, 2022
Copy link

@chaayac chaayac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, you should add the test outputs to the upstream as well.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
7 participants