Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #108
Closed
Open
Issue created May 19, 2018 by Administrator@rootContributor

[java] no inner enums generated on arrays of enums

Created by: jmini

Description

When an model is an array of enums, the type is not the correct one.

openapi-generator version

3.0.0-SNAPSHOT

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: OpenAPI test
  description: Example spec
  version: 1.0.0
servers:
  - url: 'http://api.company.xyz/call'
paths:
  /some/ping:
    get:
      operationId: op1
      responses:
        '200':
          description: Ok
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ArrayOfEnum'
components:
  schemas:
    ArrayOfEnum:
      type: array
      items:
        type: string
        enum:
          - val1
          - val2
          - val3
          - val4
Command line used for generation

java client generator, without any particular option

JavaClientCodegen config = new org.openapitools.codegen.languages.JavaClientCodegen();
config.setArtifactId(artifactId);
config.setJava8Mode(true);

Path outputDirPath = Paths.get(outputDir);

config.setHideGenerationTimestamp(true);
config.setOutputDir(outputDir);

final OpenAPIParser openApiParser = new OpenAPIParser();
final ParseOptions options = new ParseOptions();
final OpenAPI openAPI = openApiParser.readLocation(inputSpec, null, options).getOpenAPI();

final ClientOptInput opts = new ClientOptInput();
opts.setConfig(config);
opts.setOpenAPI(openAPI);
opts.setOpts(new ClientOpts());
new DefaultGenerator().opts(opts).generate();
Suggest a fix/enhancement

Model class is:

public class ArrayOfEnum extends ArrayList<String> {
//...
}

Should be a ArrayList of the enum type (maybe an inner enum) instead of String

Work around:

Use an indirection over $ref:

openapi: 3.0.1
info:
  title: OpenAPI test
  description: Example spec
  version: 1.0.0
servers:
  - url: 'http://api.company.xyz/call'
paths:
  /some/ping:
    get:
      operationId: op1
      responses:
        '200':
          description: Ok
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ArrayOfEnum'
components:
  schemas:
    ArrayOfEnum:
      type: array
      items:
        $ref: '#/components/schemas/SomeEnum'
    SomeEnum:
      type: string
      enum:
        - val1
        - val2
        - val3
        - val4
Assignee
Assign to
Time tracking