google / gnostic

A compiler for APIs described by the OpenAPI Specification with plugins for code generation and other API support tasks.
Apache License 2.0
2.08k stars 247 forks source link

protoc-gen-openapi: remove duplicate body params #444

Open jagobagascon opened 3 months ago

jagobagascon commented 3 months ago

When a request has both path parameters and body = "", the path parameters were being repeated in the body. But according to the docs: the special name `` is used to define that every field not bound by the path template should be mapped to the request body.

This commit does exactly that, when the body is * and there are some path parameters, then the a new message schema is created that does not include the path parameters. The name of the schema is the same as the message name, with the _Body suffix.

fixes #323


The only code that I modified was the cmd/protoc-gen-openapi/generator/generator.go file. The rest of the changes were autogenerated by the tests (setting the GENERATE_FIXTURES = true) or by running make all test.

jagobagascon commented 3 months ago

It looks like yesterday's protoc-gen-go release (v1.34.2) generates code that is not compatible with the used Go 1.12 version. I changed the COMPILE-PROTOS.sh script to remove the @latest tag and use a fixed version.