[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