nytimes / openapi2proto

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

Generating Empty Request + Response #109

Closed mjallday closed 5 years ago

mjallday commented 5 years ago
openapi: '3.0.0'
info:
  title: Example API

paths:
  /records:
    post:
      operationId: createRecords
      tags:
        - records
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: array
                  items:
                    $ref: '#/components/schemas/RecordCreateRequest'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/Record'

components:

  schemas:
    Record:
      type: "object"
      properties:
        id:
          type: "string"
          example: RCvafeqcnYSvHLxtqAhur7MX

    RecordCreateRequest:
      type: "object"
      properties:
        value:
          type: "string"
          example: fooo

Gives me

syntax = "proto3";

package exampleapi;

import "google/protobuf/empty.proto";

service ExampleAPIService {
    rpc CreateRecords(google.protobuf.Empty) returns (google.protobuf.Empty) {}
}

Any idea why it's generating the input and return types as google.protobuf.Empty?

jprobinson commented 5 years ago

Sorry, this tool is only set up for the Open API v2 specification. The differences in schemas means this tool is unable to read the requestBody field.

I could've sworn we had something in the README calling this out, but I guess I need to make an issue. 😓

mjallday commented 5 years ago

Thanks for the info JP. I was crawling the issues and thought I saw someone using v3.