nytimes / openapi2proto

A tool for generating Protobuf v3 schemas and gRPC service definitions from OpenAPI specifications
Apache License 2.0
961 stars 98 forks source link

Issue processing additional properties #113

Closed rbg closed 5 years ago

rbg commented 5 years ago

Using a simple example it looks like there is bug in processing additional parameters as Maps.

the error returned is:

error: failed to transpile: failed to compile OpenAPI spec to Protocol buffers: failed to compile paths: failed to compile path /test: got non-message type (*protobuf.Map) in response for GetTest
rbg commented 5 years ago

The swagger example used was:

swagger: "2.0"
info:
  title: "API"
  version: "1.0.0"
  contact:
    name: Contact Name
    email: contact@example.com
    url: https://example.com/
tags:
  - name: Metadata
    description: Metadata related requests

paths: 
  /test:
    get:
      summary: Simple test for o2p
      produces:
        - application/json
      responses:
        '200':
          description: Test info 
          schema:
              $ref: "#/definitions/Infohash"
definitions:
  Infohash:
    type: object
    additionalProperties:
      type: string
rbg commented 5 years ago

while the prev swagger does generate the expected go code (i'm using go-swagger) openapi2proto errors out as described: However if i use the following both go-swagger and openapi2proto produce the expected output:

swagger: "2.0"
info:
  title: "API"
  version: "1.0.0"
  contact:
    name: Contact Name
    email: contact@example.com
    url: https://example.com/
tags:
  - name: Metadata
    description: Metadata related requests

paths: 
  /test:
    get:
      summary: Simple test for o2p
      produces:
        - application/json
      responses:
        '200':
          description: Test info 
          schema:
            $ref: "#/definitions/Infohash"

definitions:
  Infohash:
    type: object
    properties:
      info:
        type: object
        additionalProperties:
          type: string