Skip to content

Commit 2f0d5bd

Browse files
committed
#21582 [BUG][dart-dio] Bug generating inline enums with common names
1 parent f632ab7 commit 2f0d5bd

3 files changed

Lines changed: 66 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
generatorName: dart-dio
2+
outputDir: samples/openapi3/client/bug-samples/issue_21582
3+
inputSpec: modules/openapi-generator/src/test/resources/bugs/issues_21582.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/dart/libraries/dio
5+
additionalProperties:
6+
hideGenerationTimestamp: "true"
7+
enumUnknownDefaultCase: "true"
8+
dateLibrary: "core"

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractDartCodegen.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,12 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert
577577
// inner items e.g. enums in collections, only works for one level
578578
// but same is the case for DefaultCodegen
579579
property.setDatatypeWithEnum(property.datatypeWithEnum.replace(property.items.datatypeWithEnum, enumName));
580+
// Because properties are cached in org.openapitools.codegen.DefaultCodegen.fromProperty(java.lang.String, io.swagger.v3.oas.models.media.Schema, boolean, boolean)
581+
// then the same object could be for multiple properties where the name of the inline enum is the same
582+
// in 2 different classes and the following renaming will impact properties in other classes we
583+
// therefore clone them before editing
584+
property.items = property.items.clone();
585+
property.mostInnerItems = property.items;
580586
property.items.setDatatypeWithEnum(enumName);
581587
property.items.setEnumName(enumName);
582588
} else {
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
openapi: "3.0.3"
2+
info:
3+
version: 1.0.0
4+
title: test
5+
paths:
6+
/test:
7+
get:
8+
summary: test
9+
operationId: test
10+
responses:
11+
'200':
12+
description: OK
13+
content:
14+
application/json:
15+
schema:
16+
$ref: '#/components/schemas/ObjectThree'
17+
components:
18+
schemas:
19+
ObjectOne:
20+
type: object
21+
properties:
22+
attribute:
23+
description: 'Object one attribute enum'
24+
type: 'array'
25+
uniqueItems: true
26+
items:
27+
type: 'string'
28+
enum: [
29+
'valueone',
30+
'vauetwo'
31+
]
32+
ObjectTwo:
33+
type: object
34+
properties:
35+
attribute:
36+
description: 'Object two attribute enum'
37+
type: 'array'
38+
uniqueItems: true
39+
items:
40+
type: 'string'
41+
enum: [
42+
'valueone',
43+
'vauetwo'
44+
]
45+
ObjectThree:
46+
type: object
47+
properties:
48+
objectone:
49+
$ref: '#/components/schemas/ObjectOne'
50+
objecttwo:
51+
$ref: '#/components/schemas/ObjectTwo'
52+

0 commit comments

Comments
 (0)