OpenAPITools / OpenAPITools/openapi-generator
[BUG] [graphql-nodejs-express-server] generates improper model for arrays
Nobody has claimed this yet.
- 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
- Copy/paste the yaml above into a test.yml
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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