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
Development

Successfully merging this pull request may close these issues.

7 participants