question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] OpenAPI Generator fails to generate array models

See original GitHub issue

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

OpenAPI generator fails to generate array models. It complains with:

[main] INFO  o.o.codegen.DefaultGenerator - Model {} not generated since it's an alias to array (without property) and `generateAliasAsModel` is set to false (default)
openapi-generator version

v4.3.1

And also tried latest master using Docker 07c23f4d1ad184554968b1bbe858b4ad987dd698.

OpenAPI declaration file content or url
openapi: '3.0.3'

info:
  title: Test
  version: 0.1.0

paths: {}

components:
  schemas:
    Test:
      type: array
      items:
        type: object
        properties:
          foo:
            type: string
Generation Details
docker run --rm \                                
  -v ${PWD}:/local openapitools/openapi-generator-cli generate \    
  -i /local/openapi.yaml \ 
  -g go \
  -o /local/out/go
Steps to reproduce
  1. Generate a client for any language using the provided schema. Note that the array model is not generated with the log message from this bug’s description.
Related issues/PRs
Suggest a fix

The following code is erroneous. An array has items not properties (Even required by the OpenAPI spec). You might need to cast Schema to ArraySchema to get access to items or something like that. https://github.com/OpenAPITools/openapi-generator/blob/41851b45e1f1ffa7f0df36270a6b3c0cee6425bb/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java#L485-L488

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:10
  • Comments:19 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
arokantocommented, Mar 8, 2022

Another dirty hack to get the generator to behave, at least on Node, is just to add Array’s built-in length attribute as a property. Like this:

Something:
  type: array
  properties:
    length:
      type: integer
  items:
    $ref: '#/components/schemas/SomethingElse'
3reactions
wing328commented, Oct 25, 2020

Did you try setting the generateAliasAsModel option to true?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java/OpenAPI - Cannot generate Model class for array of ...
Steps to reproduce When I generate the Models, it will generate the models but will not generate the response API from what I...
Read more >
Documentation for the java Generator
Annotate Model and Api using the Swagger Annotations 1.x library. none. apiPackage, package for generated api classes, org.openapitools.client.
Read more >
Free-Form Objects with Array Values | by John Wang | Real APIs
Using OpenAPI Generator. Beyond insufficiently specifying the object values, the OpenAPI Generator Go SDK creator won't generate a schema object ...
Read more >
Open API Server Implementation Using OpenAPI Generator
In the modelPackage, a couple of data model POJOs called Error and Pet are generated, based on the schemas defined in our YAML...
Read more >
Open API/Swagger: on run Code generator get runtime error
:\Users\Filipp.Sokolov\.jdks\adopt-openjdk-1.8.0_232\bin\java.exe -Dfile. · "Thread-1" java.lang.RuntimeException: Could not generate model 'body' · io.swagger.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found