Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] no inner enums generated on arrays of enums #108

Open
jmini opened this issue May 19, 2018 · 3 comments
Open

[java] no inner enums generated on arrays of enums #108

jmini opened this issue May 19, 2018 · 3 comments

Comments

@jmini
Copy link
Member

jmini commented May 19, 2018

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
@jmini
Copy link
Member Author

jmini commented May 19, 2018

This is also wrong with jax-rs

@andymoody
Copy link

Also an issue for kotlin-spring. The standard kotlin generator is even worse, resulting in &lt and &gt symbols instead of < and >

@jmini
Copy link
Member Author

jmini commented Jun 26, 2019

resulting in &lt and &gt symbols instead of < and >

@andymoody : there is easy to fix in the templates:
instead of using {{type}} you need to use {{{type}}} or the other way around (one notation is creating &lt and &gt the other one is creating the < and > brackets).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants