Skip to content

#21582 [BUG][dart-dio] Bug generating inline enums with common names #21591

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

Merged
merged 8 commits into from
Aug 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,12 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert
// inner items e.g. enums in collections, only works for one level
// but same is the case for DefaultCodegen
property.setDatatypeWithEnum(property.datatypeWithEnum.replace(property.items.datatypeWithEnum, enumName));
// Because properties are cached in org.openapitools.codegen.DefaultCodegen.fromProperty(java.lang.String, io.swagger.v3.oas.models.media.Schema, boolean, boolean)
// then the same object could be for multiple properties where the name of the inline enum is the same
// in 2 different classes and the following renaming will impact properties in other classes we
// therefore clone them before editing
property.items = property.items.clone();
property.mostInnerItems = property.items;
property.items.setDatatypeWithEnum(enumName);
property.items.setEnumName(enumName);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,19 @@ paths:
responses:
200:
description: The instance started successfully
/fake/duplicate-inline-enums:
get:
tags:
- fake
summary: test objects with duplicate inline enums see issue# 21582
operationId: fake-duplicate-inline-enum
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/ObjectThatReferencesObjectsWithDuplicateInlineEnums'
servers:
- url: 'http://{server}.swagger.io:{port}/v2'
description: petstore server
Expand Down Expand Up @@ -2081,3 +2094,36 @@ components:
$ref: '#/components/schemas/TestEnum'
default: ""
title: TestItem
ObjectWithInlineEnum:
type: object
properties:
attribute:
description: 'Object one attribute enum'
type: 'array'
uniqueItems: true
items:
type: 'string'
enum: [
'value_one',
'value_two'
]
ObjectWithDuplicateInlineEnum:
type: object
properties:
attribute:
description: 'Object two attribute enum'
type: 'array'
uniqueItems: true
items:
type: 'string'
enum: [
'value_one',
'value_two'
]
ObjectThatReferencesObjectsWithDuplicateInlineEnums:
type: object
properties:
object_one:
$ref: '#/components/schemas/ObjectWithInlineEnum'
object_two:
$ref: '#/components/schemas/ObjectWithDuplicateInlineEnum'
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ doc/ModelReturn.md
doc/Name.md
doc/NullableClass.md
doc/NumberOnly.md
doc/ObjectThatReferencesObjectsWithDuplicateInlineEnums.md
doc/ObjectWithDeprecatedFields.md
doc/ObjectWithDuplicateInlineEnum.md
doc/ObjectWithInlineEnum.md
doc/Order.md
doc/OuterComposite.md
doc/OuterEnum.md
Expand Down Expand Up @@ -110,7 +113,10 @@ lib/src/model/model_return.dart
lib/src/model/name.dart
lib/src/model/nullable_class.dart
lib/src/model/number_only.dart
lib/src/model/object_that_references_objects_with_duplicate_inline_enums.dart
lib/src/model/object_with_deprecated_fields.dart
lib/src/model/object_with_duplicate_inline_enum.dart
lib/src/model/object_with_inline_enum.dart
lib/src/model/order.dart
lib/src/model/outer_composite.dart
lib/src/model/outer_enum.dart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Class | Method | HTTP request | Description
[*AnotherFakeApi*](doc/AnotherFakeApi.md) | [**call123testSpecialTags**](doc/AnotherFakeApi.md#call123testspecialtags) | **PATCH** /another-fake/dummy | To test special tags
[*DefaultApi*](doc/DefaultApi.md) | [**fooGet**](doc/DefaultApi.md#fooget) | **GET** /foo |
[*FakeApi*](doc/FakeApi.md) | [**fakeBigDecimalMap**](doc/FakeApi.md#fakebigdecimalmap) | **GET** /fake/BigDecimalMap |
[*FakeApi*](doc/FakeApi.md) | [**fakeDuplicateInlineEnum**](doc/FakeApi.md#fakeduplicateinlineenum) | **GET** /fake/duplicate-inline-enums | test objects with duplicate inline enums see issue# 21582
[*FakeApi*](doc/FakeApi.md) | [**fakeHealthGet**](doc/FakeApi.md#fakehealthget) | **GET** /fake/health | Health check endpoint
[*FakeApi*](doc/FakeApi.md) | [**fakeHttpSignatureTest**](doc/FakeApi.md#fakehttpsignaturetest) | **GET** /fake/http-signature-test | test http signature authentication
[*FakeApi*](doc/FakeApi.md) | [**fakeOuterBooleanSerialize**](doc/FakeApi.md#fakeouterbooleanserialize) | **POST** /fake/outer/boolean |
Expand Down Expand Up @@ -150,7 +151,10 @@ Class | Method | HTTP request | Description
- [Name](doc/Name.md)
- [NullableClass](doc/NullableClass.md)
- [NumberOnly](doc/NumberOnly.md)
- [ObjectThatReferencesObjectsWithDuplicateInlineEnums](doc/ObjectThatReferencesObjectsWithDuplicateInlineEnums.md)
- [ObjectWithDeprecatedFields](doc/ObjectWithDeprecatedFields.md)
- [ObjectWithDuplicateInlineEnum](doc/ObjectWithDuplicateInlineEnum.md)
- [ObjectWithInlineEnum](doc/ObjectWithInlineEnum.md)
- [Order](doc/Order.md)
- [OuterComposite](doc/OuterComposite.md)
- [OuterEnum](doc/OuterEnum.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*
Method | HTTP request | Description
------------- | ------------- | -------------
[**fakeBigDecimalMap**](FakeApi.md#fakebigdecimalmap) | **GET** /fake/BigDecimalMap |
[**fakeDuplicateInlineEnum**](FakeApi.md#fakeduplicateinlineenum) | **GET** /fake/duplicate-inline-enums | test objects with duplicate inline enums see issue# 21582
[**fakeHealthGet**](FakeApi.md#fakehealthget) | **GET** /fake/health | Health check endpoint
[**fakeHttpSignatureTest**](FakeApi.md#fakehttpsignaturetest) | **GET** /fake/http-signature-test | test http signature authentication
[**fakeOuterBooleanSerialize**](FakeApi.md#fakeouterbooleanserialize) | **POST** /fake/outer/boolean |
Expand Down Expand Up @@ -72,6 +73,43 @@ No authorization required

[[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)

# **fakeDuplicateInlineEnum**
> ObjectThatReferencesObjectsWithDuplicateInlineEnums fakeDuplicateInlineEnum()

test objects with duplicate inline enums see issue# 21582

### Example
```dart
import 'package:openapi/api.dart';

final api = Openapi().getFakeApi();

try {
final response = api.fakeDuplicateInlineEnum();
print(response);
} catch on DioException (e) {
print('Exception when calling FakeApi->fakeDuplicateInlineEnum: $e\n');
}
```

### Parameters
This endpoint does not need any parameter.

### Return type

[**ObjectThatReferencesObjectsWithDuplicateInlineEnums**](ObjectThatReferencesObjectsWithDuplicateInlineEnums.md)

### Authorization

No authorization required

### HTTP request headers

- **Content-Type**: Not defined
- **Accept**: application/json

[[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)

# **fakeHealthGet**
> HealthCheckResult fakeHealthGet()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# openapi.model.ObjectThatReferencesObjectsWithDuplicateInlineEnums

## Load the model package
```dart
import 'package:openapi/api.dart';
```

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**objectOne** | [**ObjectWithInlineEnum**](ObjectWithInlineEnum.md) | | [optional]
**objectTwo** | [**ObjectWithDuplicateInlineEnum**](ObjectWithDuplicateInlineEnum.md) | | [optional]

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


Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# openapi.model.ObjectWithDuplicateInlineEnum

## Load the model package
```dart
import 'package:openapi/api.dart';
```

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**attribute** | **Set<String>** | Object two attribute enum | [optional]

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


Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# openapi.model.ObjectWithInlineEnum

## Load the model package
```dart
import 'package:openapi/api.dart';
```

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**attribute** | **Set<String>** | Object one attribute enum | [optional]

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


Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ export 'package:openapi/src/model/model_return.dart';
export 'package:openapi/src/model/name.dart';
export 'package:openapi/src/model/nullable_class.dart';
export 'package:openapi/src/model/number_only.dart';
export 'package:openapi/src/model/object_that_references_objects_with_duplicate_inline_enums.dart';
export 'package:openapi/src/model/object_with_deprecated_fields.dart';
export 'package:openapi/src/model/object_with_duplicate_inline_enum.dart';
export 'package:openapi/src/model/object_with_inline_enum.dart';
export 'package:openapi/src/model/order.dart';
export 'package:openapi/src/model/outer_composite.dart';
export 'package:openapi/src/model/outer_enum.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:openapi/src/model/file_schema_test_class.dart';
import 'package:openapi/src/model/health_check_result.dart';
import 'package:openapi/src/model/model_client.dart';
import 'package:openapi/src/model/model_enum_class.dart';
import 'package:openapi/src/model/object_that_references_objects_with_duplicate_inline_enums.dart';
import 'package:openapi/src/model/outer_composite.dart';
import 'package:openapi/src/model/outer_object_with_enum_property.dart';
import 'package:openapi/src/model/pet.dart';
Expand Down Expand Up @@ -97,6 +98,76 @@ _responseData = rawData == null ? null : deserialize<FakeBigDecimalMap200Respons
);
}

/// test objects with duplicate inline enums see issue# 21582
///
///
/// Parameters:
/// * [cancelToken] - A [CancelToken] that can be used to cancel the operation
/// * [headers] - Can be used to add additional headers to the request
/// * [extras] - Can be used to add flags to the request
/// * [validateStatus] - A [ValidateStatus] callback that can be used to determine request success based on the HTTP status of the response
/// * [onSendProgress] - A [ProgressCallback] that can be used to get the send progress
/// * [onReceiveProgress] - A [ProgressCallback] that can be used to get the receive progress
///
/// Returns a [Future] containing a [Response] with a [ObjectThatReferencesObjectsWithDuplicateInlineEnums] as data
/// Throws [DioException] if API call or serialization fails
Future<Response<ObjectThatReferencesObjectsWithDuplicateInlineEnums>> fakeDuplicateInlineEnum({
CancelToken? cancelToken,
Map<String, dynamic>? headers,
Map<String, dynamic>? extra,
ValidateStatus? validateStatus,
ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress,
}) async {
final _path = r'/fake/duplicate-inline-enums';
final _options = Options(
method: r'GET',
headers: <String, dynamic>{
...?headers,
},
extra: <String, dynamic>{
'secure': <Map<String, String>>[],
...?extra,
},
validateStatus: validateStatus,
);

final _response = await _dio.request<Object>(
_path,
options: _options,
cancelToken: cancelToken,
onSendProgress: onSendProgress,
onReceiveProgress: onReceiveProgress,
);

ObjectThatReferencesObjectsWithDuplicateInlineEnums? _responseData;

try {
final rawData = _response.data;
_responseData = rawData == null ? null : deserialize<ObjectThatReferencesObjectsWithDuplicateInlineEnums, ObjectThatReferencesObjectsWithDuplicateInlineEnums>(rawData, 'ObjectThatReferencesObjectsWithDuplicateInlineEnums', growable: true);

} catch (error, stackTrace) {
throw DioException(
requestOptions: _response.requestOptions,
response: _response,
type: DioExceptionType.unknown,
error: error,
stackTrace: stackTrace,
);
}

return Response<ObjectThatReferencesObjectsWithDuplicateInlineEnums>(
data: _responseData,
headers: _response.headers,
isRedirect: _response.isRedirect,
requestOptions: _response.requestOptions,
redirects: _response.redirects,
statusCode: _response.statusCode,
statusMessage: _response.statusMessage,
extra: _response.extra,
);
}

/// Health check endpoint
///
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ import 'package:openapi/src/model/model_return.dart';
import 'package:openapi/src/model/name.dart';
import 'package:openapi/src/model/nullable_class.dart';
import 'package:openapi/src/model/number_only.dart';
import 'package:openapi/src/model/object_that_references_objects_with_duplicate_inline_enums.dart';
import 'package:openapi/src/model/object_with_deprecated_fields.dart';
import 'package:openapi/src/model/object_with_duplicate_inline_enum.dart';
import 'package:openapi/src/model/object_with_inline_enum.dart';
import 'package:openapi/src/model/order.dart';
import 'package:openapi/src/model/outer_composite.dart';
import 'package:openapi/src/model/outer_object_with_enum_property.dart';
Expand Down Expand Up @@ -131,8 +134,14 @@ final _regMap = RegExp(r'^Map<String,(.*)>$');
return NullableClass.fromJson(value as Map<String, dynamic>) as ReturnType;
case 'NumberOnly':
return NumberOnly.fromJson(value as Map<String, dynamic>) as ReturnType;
case 'ObjectThatReferencesObjectsWithDuplicateInlineEnums':
return ObjectThatReferencesObjectsWithDuplicateInlineEnums.fromJson(value as Map<String, dynamic>) as ReturnType;
case 'ObjectWithDeprecatedFields':
return ObjectWithDeprecatedFields.fromJson(value as Map<String, dynamic>) as ReturnType;
case 'ObjectWithDuplicateInlineEnum':
return ObjectWithDuplicateInlineEnum.fromJson(value as Map<String, dynamic>) as ReturnType;
case 'ObjectWithInlineEnum':
return ObjectWithInlineEnum.fromJson(value as Map<String, dynamic>) as ReturnType;
case 'Order':
return Order.fromJson(value as Map<String, dynamic>) as ReturnType;
case 'OuterComposite':
Expand Down
Loading
Loading