Skip to content

Commit

Permalink
Add lost import for inner enums (#1731)
Browse files Browse the repository at this point in the history
  • Loading branch information
altro3 authored Sep 4, 2024
1 parent 0eecbf5 commit cf0d6a2
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.apache.commons.lang3.builder.HashCodeBuilder;
import java.util.Objects;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
{{#useOptional}}
import java.util.Optional;
{{/useOptional}}
Expand Down Expand Up @@ -69,7 +70,6 @@ import io.swagger.v3.oas.annotations.media.Schema;
{{#models}}
{{#model}}
{{#isEnum}}
import java.util.function.Function;

{{>common/model/enum}}
{{/isEnum}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,4 +613,14 @@ void testImplicitHeadersRegex() {
"@Header(name = \"Content-Type\", defaultValue = \"application/json\") @Nullable String contentType"
);
}

@Test
void testInnerEnum() {

var codegen = new JavaMicronautClientCodegen();
String outputPath = generateFiles(codegen, "src/test/resources/3_0/inner-enum.yml", CodegenConstants.MODELS);
String path = outputPath + "src/main/java/org/openapitools/";

assertFileContains(path + "model/CustomerCreateDTO.java", "import java.util.function.Function;");
}
}
124 changes: 124 additions & 0 deletions openapi-generator/src/test/resources/3_0/inner-enum.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
openapi: "3.0.0"
info:
version: 1.0.0
title: Compute API
description: API for the Compute Service
servers:
- url: localhost:8000/api
description: The api server

paths:
/sendEnum:
get:
operationId: sendEnum
tags: [ parameters ]
parameters:
- name: name
in: query
required: true
schema:
$ref: "#/components/schemas/StringEnum"
- name: intEnum
in: query
required: true
schema:
$ref: "#/components/schemas/IntEnum"
- name: longEnum
in: query
required: true
schema:
$ref: "#/components/schemas/LongEnum"
- name: boolEnum
in: query
required: true
schema:
$ref: "#/components/schemas/BooleanEnum"
- name: decimalEnum
in: query
required: true
schema:
$ref: "#/components/schemas/DecimalEnum"
responses:
200:
description: Success
components:
schemas:
CustomerCreateDTO:
type: object
required:
- profile
- nip
allOf:
- $ref: '#/components/schemas/CustomerUpdateDTO'
- type: object
properties:
profile:
type: string
enum:
- individual
- corporate
nip:
type: string
maxLength: 128
minLength: 8
CustomerUpdateDTO:
type: object
required:
- street
- buildingNumber
- postalCode
- city
- email
- parking
- licensePlate
properties:
firstName:
type: string
maxLength: 128
lastName:
type: string
maxLength: 128
companyName:
type: string
maxLength: 256
street:
type: string
maxLength: 512
buildingNumber:
type: string
maxLength: 64
apartmentNumber:
type: string
maxLength: 32
postalCode:
type: string
maxLength: 16
city:
type: string
maxLength: 256
email:
type: string
maxLength: 256
format: email
licensePlate:
type: string
maxLength: 64
notes:
type: string
maxLength: 512
StringEnum:
type: string
enum: ['starting', 'running', 'stopped', 'deleted']
IntEnum:
type: integer
enum: [1, 2, 3, 4, 5]
LongEnum:
type: integer
format: int64
enum: [1, 2, 3, 4, 5]
BooleanEnum:
type: boolean
enum: ['true', 'false']
DecimalEnum:
type: number
enum: [1.23, 2.45, 34.10]

0 comments on commit cf0d6a2

Please sign in to comment.