OpenAPITools / OpenAPITools/openapi-generator

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

Open
#5,684 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug Server: GraphQL
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
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]
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the supplied test.yml and the graphql-nodejs-express-server generation command. Start by inspecting that generator's model templates or entry points to see how array schemas are represented. Done means SomeArray and SomeArrayInput contain the expected [Int] field rather than empty types, with a regression test covering the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
express, javascript, node.js
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.