gnostic icon indicating copy to clipboard operation
gnostic copied to clipboard

Is there a way to set up openapi examples from protobuf?

Open daiki-sone opened this issue 3 years ago • 3 comments

I am using gnostic to output openapiv3 yaml files from protobuf. Furthermore, I am setting up a Mock server from openapiv3 using Prism, but I want to use the response from the examples specified. Is there a way to set up examples in protobuf and output them to openapiv3 in a format that can be used with prism's mock?

I want to output openapi yaml like this from protobuf.

responses:
  '200':
    description: OK
    content:
      application/json:
        schema:
          '$ref': '#/components/schemas/Pet'
        examples:
          cat:
            summary: An example of a cat
            value:
              id: 2
              name: Fluffy
          dog:
            summary: An example of a dog
            value:
              id: 1
              name: Spot

daiki-sone avatar Aug 12 '22 05:08 daiki-sone

@daiki-sone have you tried using the options? You can see an example here: https://github.com/google/gnostic/blob/main/cmd/protoc-gen-openapi/examples/tests/openapiv3annotations/message.proto#L63

The MediaType message has an examples property so I think you can set it that way https://github.com/google/gnostic/blob/main/openapiv3/OpenAPIv3.proto#L252

jeffsawatzky avatar Apr 07 '23 01:04 jeffsawatzky

Have you solved it? I have the same need

plum330 avatar Nov 15 '23 02:11 plum330

@daiki-sone have you tried using the options? You can see an example here: https://github.com/google/gnostic/blob/main/cmd/protoc-gen-openapi/examples/tests/openapiv3annotations/message.proto#L63

The MediaType message has an examples property so I think you can set it that way https://github.com/google/gnostic/blob/main/openapiv3/OpenAPIv3.proto#L252

#417 I want to set example for the field to display by mock, but above advice can not work

plum330 avatar Nov 26 '23 13:11 plum330