[BUG] OpenAPI Generator fails to generate array models
See original GitHub issueBug 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
- 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:
- Created 3 years ago
- Reactions:10
- Comments:19 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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:Did you try setting the
generateAliasAsModel
option totrue
?