OpenAPITools / OpenAPITools/openapi-generator

[BUG] openapi-yaml template helper incorrectly converts unbounded-type array to arrays of objects.

Open
#7,707 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When the input schema contains an array with no specific type, it gets converted to an array of objects. Which does not have the same meaning at all.

https://swagger.io/docs/specification/data-models/data-types/#array

An array of arbitrary types can be defined as:

openapi-generator version

openapi-generator-cli 5.0.0-SNAPSHOT

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: api
  version: 1.0.1
servers:
  - url: /api/v1
    description: ''
tags:
  - name: General
    description: General commands
  - name: Configuration
    description: Configuration commands
paths:
  /test:
    get:
      summary: Your GET endpoint
      tags: []
      responses:
        '200':
          description: OK
      operationId: getTest
      requestBody:
        content:
          application/json:
            schema:
              $ref: ../core/model/definitions/TestObject.v1.json
components:
  schemas: {}

TestObject.v1.json:

{
  "title": "TestObject",
  "type": "object",
  "properties": {
    "something": {
      "type": "array",
      "items": {}
    }
  }
}
Generation Details

openapitools/openapi-generator-cli generate -i /local/api/api.yaml -t /local/core/swagger/mustache/nodejs-express-server/ -g nodejs-express-server -o /local/server/

Generated schema:

openapi: 3.0.0
info:
  title: api
  version: 1.0.1
servers:
- url: /api/v1
tags:
- description: General commands
  name: General
- description: Configuration commands
  name: Configuration
paths:
  /test:
    get:
      operationId: getTest
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TestObject'
      responses:
        "200":
          description: OK
      summary: Your GET endpoint
      tags: []
      x-eov-operation-handler: controllers/DefaultController
components:
  schemas:
    TestObject:
      example:
        something:
        - '{}'
        - '{}'
      properties:
        something:
          items:
            type: object
          type: array
      title: TestObject
      type: object

Notice this section:

something:
          items:
            type: object
          type: array

It converted my array of generic into an array of object

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

Start with the nodejs-express-server template at /local/core/swagger/mustache/nodejs-express-server/ and reproduce the output using the supplied OpenAPI and TestObject.v1.json files. Compare how the template handles array items defined as an empty schema. Done means an unbounded array remains generic rather than being emitted with items of type object.

Written by the indexing model from the issue text.

Assessment

Tech stack
express, nodejs, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.