OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.8k stars 6.58k forks source link

[BUG] [graphql-nodejs-express-server] generates improper model for arrays #5684

Open rdecarreau opened 4 years ago

rdecarreau commented 4 years ago

Bug Report Checklist

Description

My spec has an array in it, when I run the generator, the model for the array is an empty type.

openapi-generator version

CLI version 4.2.3

OpenAPI declaration file content or url
openapi: '3.0.0'
info:
  title: My API
  description: This is a test
  version: 0.1.1

paths:
  /someArray:
    get:
      summary: Returns an array
      responses:
        200:
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SomeArray'
components:
  schema:
    SomeArray:
      type: array
      items:
          type: integer
Command line used for generation

java -jar codegen-cli.jar generate -i test.yml -g graphql-nodejs-express-server -o /out/graphql-nodejs-express-server --generate-alias-as-model

Steps to reproduce
  1. Copy/paste the yaml above into a test.yml
  2. Call the command above via command line
Related issues/PRs

NA

Suggest a fix

This is a tough one. OpenAPI doesn't provide a name element for array types, but GraphQL requires that each property be named (sensibly). Maybe the generator can use the type name? Actual

type SomeArray {
}

input SomeArrayInput {
}

Expected

type SomeArray {
  someArray: [Int]
}

input SomeArrayInput {
    someArray: [Int]
}
auto-labeler[bot] commented 4 years ago

👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

ReginaldoSantos commented 3 years ago

I'm facing a very similar problem. Check "results" property below:

OpenAPI snippet:

   PageElements:
      type: object
      properties:
        page:
          type: 'integer'
          format: 'int32'
          example: 5
        size:
          type: 'integer'
          format: 'int32'
          example: 20
        totalPages:
          type: 'integer'
          format: 'int32'
          example: 10
        totalElements:
          type: 'integer'
          format: 'int64'
          example: 189
        results:
          type: 'array'
          items:
            $ref: '#/components/schemas/Element'

Actual

type PageElements {
  results: Element
  page: Int!
  size: Int!
  totalPages: Int!
  totalElements: Int!
}

Expected

type PageElements {
  results: [Element]
  page: Int!
  size: Int!
  totalPages: Int!
  totalElements: Int!
}
wing328 commented 3 years ago

May I know if you've time to contribute a fix? I can show you some good starting point.