Skip to content

Commit 9cb04c1

Browse files
authored
#21582 [BUG][dart-dio] Bug generating inline enums with common names (#21591)
* #21582 [BUG][dart-dio] Bug generating inline enums with common names * #21582 [BUG][dart-dio] Bug generating inline enums with common names added petstore test * #21582 [BUG][dart-dio] Bug generating inline enums with common names added generated samples to commit. * #21582 [BUG][dart-dio] Bug generating inline enums with common names removed bug test files that were duplicates * #21582 [BUG][dart-dio] Bug generating inline enums with common names. Added generated files that were missed. * #21582 [BUG][dart-dio] Bug generating inline enums with common names. Added generated files that were missed. * #21582 [BUG][dart-dio] Bug generating inline enums with common names. Added generated files that where updated as a result of changes in master.
1 parent aacbdf8 commit 9cb04c1

File tree

47 files changed

+1868
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1868
-0
lines changed

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
@@ -576,6 +576,12 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert
576576
// inner items e.g. enums in collections, only works for one level
577577
// but same is the case for DefaultCodegen
578578
property.setDatatypeWithEnum(property.datatypeWithEnum.replace(property.items.datatypeWithEnum, enumName));
579+
// Because properties are cached in org.openapitools.codegen.DefaultCodegen.fromProperty(java.lang.String, io.swagger.v3.oas.models.media.Schema, boolean, boolean)
580+
// then the same object could be for multiple properties where the name of the inline enum is the same
581+
// in 2 different classes and the following renaming will impact properties in other classes we
582+
// therefore clone them before editing
583+
property.items = property.items.clone();
584+
property.mostInnerItems = property.items;
579585
property.items.setDatatypeWithEnum(enumName);
580586
property.items.setEnumName(enumName);
581587
} else {

modules/openapi-generator/src/test/resources/3_0/dart/petstore-with-fake-endpoints-models-for-testing.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,19 @@ paths:
13031303
responses:
13041304
200:
13051305
description: The instance started successfully
1306+
/fake/duplicate-inline-enums:
1307+
get:
1308+
tags:
1309+
- fake
1310+
summary: test objects with duplicate inline enums see issue# 21582
1311+
operationId: fake-duplicate-inline-enum
1312+
responses:
1313+
'200':
1314+
description: OK
1315+
content:
1316+
application/json:
1317+
schema:
1318+
$ref: '#/components/schemas/ObjectThatReferencesObjectsWithDuplicateInlineEnums'
13061319
servers:
13071320
- url: 'http://{server}.swagger.io:{port}/v2'
13081321
description: petstore server
@@ -2081,3 +2094,36 @@ components:
20812094
$ref: '#/components/schemas/TestEnum'
20822095
default: ""
20832096
title: TestItem
2097+
ObjectWithInlineEnum:
2098+
type: object
2099+
properties:
2100+
attribute:
2101+
description: 'Object one attribute enum'
2102+
type: 'array'
2103+
uniqueItems: true
2104+
items:
2105+
type: 'string'
2106+
enum: [
2107+
'value_one',
2108+
'value_two'
2109+
]
2110+
ObjectWithDuplicateInlineEnum:
2111+
type: object
2112+
properties:
2113+
attribute:
2114+
description: 'Object two attribute enum'
2115+
type: 'array'
2116+
uniqueItems: true
2117+
items:
2118+
type: 'string'
2119+
enum: [
2120+
'value_one',
2121+
'value_two'
2122+
]
2123+
ObjectThatReferencesObjectsWithDuplicateInlineEnums:
2124+
type: object
2125+
properties:
2126+
object_one:
2127+
$ref: '#/components/schemas/ObjectWithInlineEnum'
2128+
object_two:
2129+
$ref: '#/components/schemas/ObjectWithDuplicateInlineEnum'

samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/.openapi-generator/FILES

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ doc/ModelReturn.md
4040
doc/Name.md
4141
doc/NullableClass.md
4242
doc/NumberOnly.md
43+
doc/ObjectThatReferencesObjectsWithDuplicateInlineEnums.md
4344
doc/ObjectWithDeprecatedFields.md
45+
doc/ObjectWithDuplicateInlineEnum.md
46+
doc/ObjectWithInlineEnum.md
4447
doc/Order.md
4548
doc/OuterComposite.md
4649
doc/OuterEnum.md
@@ -110,7 +113,10 @@ lib/src/model/model_return.dart
110113
lib/src/model/name.dart
111114
lib/src/model/nullable_class.dart
112115
lib/src/model/number_only.dart
116+
lib/src/model/object_that_references_objects_with_duplicate_inline_enums.dart
113117
lib/src/model/object_with_deprecated_fields.dart
118+
lib/src/model/object_with_duplicate_inline_enum.dart
119+
lib/src/model/object_with_inline_enum.dart
114120
lib/src/model/order.dart
115121
lib/src/model/outer_composite.dart
116122
lib/src/model/outer_enum.dart

samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Class | Method | HTTP request | Description
6969
[*AnotherFakeApi*](doc/AnotherFakeApi.md) | [**call123testSpecialTags**](doc/AnotherFakeApi.md#call123testspecialtags) | **PATCH** /another-fake/dummy | To test special tags
7070
[*DefaultApi*](doc/DefaultApi.md) | [**fooGet**](doc/DefaultApi.md#fooget) | **GET** /foo |
7171
[*FakeApi*](doc/FakeApi.md) | [**fakeBigDecimalMap**](doc/FakeApi.md#fakebigdecimalmap) | **GET** /fake/BigDecimalMap |
72+
[*FakeApi*](doc/FakeApi.md) | [**fakeDuplicateInlineEnum**](doc/FakeApi.md#fakeduplicateinlineenum) | **GET** /fake/duplicate-inline-enums | test objects with duplicate inline enums see issue# 21582
7273
[*FakeApi*](doc/FakeApi.md) | [**fakeHealthGet**](doc/FakeApi.md#fakehealthget) | **GET** /fake/health | Health check endpoint
7374
[*FakeApi*](doc/FakeApi.md) | [**fakeHttpSignatureTest**](doc/FakeApi.md#fakehttpsignaturetest) | **GET** /fake/http-signature-test | test http signature authentication
7475
[*FakeApi*](doc/FakeApi.md) | [**fakeOuterBooleanSerialize**](doc/FakeApi.md#fakeouterbooleanserialize) | **POST** /fake/outer/boolean |
@@ -150,7 +151,10 @@ Class | Method | HTTP request | Description
150151
- [Name](doc/Name.md)
151152
- [NullableClass](doc/NullableClass.md)
152153
- [NumberOnly](doc/NumberOnly.md)
154+
- [ObjectThatReferencesObjectsWithDuplicateInlineEnums](doc/ObjectThatReferencesObjectsWithDuplicateInlineEnums.md)
153155
- [ObjectWithDeprecatedFields](doc/ObjectWithDeprecatedFields.md)
156+
- [ObjectWithDuplicateInlineEnum](doc/ObjectWithDuplicateInlineEnum.md)
157+
- [ObjectWithInlineEnum](doc/ObjectWithInlineEnum.md)
154158
- [Order](doc/Order.md)
155159
- [OuterComposite](doc/OuterComposite.md)
156160
- [OuterEnum](doc/OuterEnum.md)

samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/doc/FakeApi.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*
1010
Method | HTTP request | Description
1111
------------- | ------------- | -------------
1212
[**fakeBigDecimalMap**](FakeApi.md#fakebigdecimalmap) | **GET** /fake/BigDecimalMap |
13+
[**fakeDuplicateInlineEnum**](FakeApi.md#fakeduplicateinlineenum) | **GET** /fake/duplicate-inline-enums | test objects with duplicate inline enums see issue# 21582
1314
[**fakeHealthGet**](FakeApi.md#fakehealthget) | **GET** /fake/health | Health check endpoint
1415
[**fakeHttpSignatureTest**](FakeApi.md#fakehttpsignaturetest) | **GET** /fake/http-signature-test | test http signature authentication
1516
[**fakeOuterBooleanSerialize**](FakeApi.md#fakeouterbooleanserialize) | **POST** /fake/outer/boolean |
@@ -72,6 +73,43 @@ No authorization required
7273

7374
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
7475

76+
# **fakeDuplicateInlineEnum**
77+
> ObjectThatReferencesObjectsWithDuplicateInlineEnums fakeDuplicateInlineEnum()
78+
79+
test objects with duplicate inline enums see issue# 21582
80+
81+
### Example
82+
```dart
83+
import 'package:openapi/api.dart';
84+
85+
final api = Openapi().getFakeApi();
86+
87+
try {
88+
final response = api.fakeDuplicateInlineEnum();
89+
print(response);
90+
} catch on DioException (e) {
91+
print('Exception when calling FakeApi->fakeDuplicateInlineEnum: $e\n');
92+
}
93+
```
94+
95+
### Parameters
96+
This endpoint does not need any parameter.
97+
98+
### Return type
99+
100+
[**ObjectThatReferencesObjectsWithDuplicateInlineEnums**](ObjectThatReferencesObjectsWithDuplicateInlineEnums.md)
101+
102+
### Authorization
103+
104+
No authorization required
105+
106+
### HTTP request headers
107+
108+
- **Content-Type**: Not defined
109+
- **Accept**: application/json
110+
111+
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
112+
75113
# **fakeHealthGet**
76114
> HealthCheckResult fakeHealthGet()
77115
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# openapi.model.ObjectThatReferencesObjectsWithDuplicateInlineEnums
2+
3+
## Load the model package
4+
```dart
5+
import 'package:openapi/api.dart';
6+
```
7+
8+
## Properties
9+
Name | Type | Description | Notes
10+
------------ | ------------- | ------------- | -------------
11+
**objectOne** | [**ObjectWithInlineEnum**](ObjectWithInlineEnum.md) | | [optional]
12+
**objectTwo** | [**ObjectWithDuplicateInlineEnum**](ObjectWithDuplicateInlineEnum.md) | | [optional]
13+
14+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
15+
16+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# openapi.model.ObjectWithDuplicateInlineEnum
2+
3+
## Load the model package
4+
```dart
5+
import 'package:openapi/api.dart';
6+
```
7+
8+
## Properties
9+
Name | Type | Description | Notes
10+
------------ | ------------- | ------------- | -------------
11+
**attribute** | **Set<String>** | Object two attribute enum | [optional]
12+
13+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
14+
15+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# openapi.model.ObjectWithInlineEnum
2+
3+
## Load the model package
4+
```dart
5+
import 'package:openapi/api.dart';
6+
```
7+
8+
## Properties
9+
Name | Type | Description | Notes
10+
------------ | ------------- | ------------- | -------------
11+
**attribute** | **Set<String>** | Object one attribute enum | [optional]
12+
13+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
14+
15+

samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/openapi.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ export 'package:openapi/src/model/model_return.dart';
5151
export 'package:openapi/src/model/name.dart';
5252
export 'package:openapi/src/model/nullable_class.dart';
5353
export 'package:openapi/src/model/number_only.dart';
54+
export 'package:openapi/src/model/object_that_references_objects_with_duplicate_inline_enums.dart';
5455
export 'package:openapi/src/model/object_with_deprecated_fields.dart';
56+
export 'package:openapi/src/model/object_with_duplicate_inline_enum.dart';
57+
export 'package:openapi/src/model/object_with_inline_enum.dart';
5558
export 'package:openapi/src/model/order.dart';
5659
export 'package:openapi/src/model/outer_composite.dart';
5760
export 'package:openapi/src/model/outer_enum.dart';

samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/api/fake_api.dart

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import 'package:openapi/src/model/file_schema_test_class.dart';
1515
import 'package:openapi/src/model/health_check_result.dart';
1616
import 'package:openapi/src/model/model_client.dart';
1717
import 'package:openapi/src/model/model_enum_class.dart';
18+
import 'package:openapi/src/model/object_that_references_objects_with_duplicate_inline_enums.dart';
1819
import 'package:openapi/src/model/outer_composite.dart';
1920
import 'package:openapi/src/model/outer_object_with_enum_property.dart';
2021
import 'package:openapi/src/model/pet.dart';
@@ -97,6 +98,76 @@ _responseData = rawData == null ? null : deserialize<FakeBigDecimalMap200Respons
9798
);
9899
}
99100

101+
/// test objects with duplicate inline enums see issue# 21582
102+
///
103+
///
104+
/// Parameters:
105+
/// * [cancelToken] - A [CancelToken] that can be used to cancel the operation
106+
/// * [headers] - Can be used to add additional headers to the request
107+
/// * [extras] - Can be used to add flags to the request
108+
/// * [validateStatus] - A [ValidateStatus] callback that can be used to determine request success based on the HTTP status of the response
109+
/// * [onSendProgress] - A [ProgressCallback] that can be used to get the send progress
110+
/// * [onReceiveProgress] - A [ProgressCallback] that can be used to get the receive progress
111+
///
112+
/// Returns a [Future] containing a [Response] with a [ObjectThatReferencesObjectsWithDuplicateInlineEnums] as data
113+
/// Throws [DioException] if API call or serialization fails
114+
Future<Response<ObjectThatReferencesObjectsWithDuplicateInlineEnums>> fakeDuplicateInlineEnum({
115+
CancelToken? cancelToken,
116+
Map<String, dynamic>? headers,
117+
Map<String, dynamic>? extra,
118+
ValidateStatus? validateStatus,
119+
ProgressCallback? onSendProgress,
120+
ProgressCallback? onReceiveProgress,
121+
}) async {
122+
final _path = r'/fake/duplicate-inline-enums';
123+
final _options = Options(
124+
method: r'GET',
125+
headers: <String, dynamic>{
126+
...?headers,
127+
},
128+
extra: <String, dynamic>{
129+
'secure': <Map<String, String>>[],
130+
...?extra,
131+
},
132+
validateStatus: validateStatus,
133+
);
134+
135+
final _response = await _dio.request<Object>(
136+
_path,
137+
options: _options,
138+
cancelToken: cancelToken,
139+
onSendProgress: onSendProgress,
140+
onReceiveProgress: onReceiveProgress,
141+
);
142+
143+
ObjectThatReferencesObjectsWithDuplicateInlineEnums? _responseData;
144+
145+
try {
146+
final rawData = _response.data;
147+
_responseData = rawData == null ? null : deserialize<ObjectThatReferencesObjectsWithDuplicateInlineEnums, ObjectThatReferencesObjectsWithDuplicateInlineEnums>(rawData, 'ObjectThatReferencesObjectsWithDuplicateInlineEnums', growable: true);
148+
149+
} catch (error, stackTrace) {
150+
throw DioException(
151+
requestOptions: _response.requestOptions,
152+
response: _response,
153+
type: DioExceptionType.unknown,
154+
error: error,
155+
stackTrace: stackTrace,
156+
);
157+
}
158+
159+
return Response<ObjectThatReferencesObjectsWithDuplicateInlineEnums>(
160+
data: _responseData,
161+
headers: _response.headers,
162+
isRedirect: _response.isRedirect,
163+
requestOptions: _response.requestOptions,
164+
redirects: _response.redirects,
165+
statusCode: _response.statusCode,
166+
statusMessage: _response.statusMessage,
167+
extra: _response.extra,
168+
);
169+
}
170+
100171
/// Health check endpoint
101172
///
102173
///

0 commit comments

Comments
 (0)