-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
[dart] Fix compile error in inline enum properties with "default" vaues(#22120) #22165
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
Open
chizhanov
wants to merge
1
commit into
OpenAPITools:master
Choose a base branch
from
chizhanov:fix-22120
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+765
−303
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...store_client_lib_fake-json_serializable/doc/ObjectWithInlineEnumDefaultValue.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# openapi.model.ObjectWithInlineEnumDefaultValue | ||
|
||
## Load the model package | ||
```dart | ||
import 'package:openapi/api.dart'; | ||
``` | ||
|
||
## Properties | ||
Name | Type | Description | Notes | ||
------------ | ------------- | ------------- | ------------- | ||
**attribute** | **String** | Object one attribute enum with default value | [optional] [default to 'value_one'] | ||
|
||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...lient_lib_fake-json_serializable/lib/src/model/object_with_inline_enum_default_value.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// | ||
// AUTO-GENERATED FILE, DO NOT MODIFY! | ||
// | ||
|
||
// ignore_for_file: unused_element | ||
import 'package:copy_with_extension/copy_with_extension.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'object_with_inline_enum_default_value.g.dart'; | ||
|
||
|
||
@CopyWith() | ||
@JsonSerializable( | ||
checked: true, | ||
createToJson: true, | ||
disallowUnrecognizedKeys: false, | ||
explicitToJson: true, | ||
) | ||
class ObjectWithInlineEnumDefaultValue { | ||
/// Returns a new [ObjectWithInlineEnumDefaultValue] instance. | ||
ObjectWithInlineEnumDefaultValue({ | ||
|
||
this.attribute = const ObjectWithInlineEnumDefaultValueAttributeEnum._('value_one'), | ||
}); | ||
|
||
/// Object one attribute enum with default value | ||
@JsonKey( | ||
defaultValue: 'value_one', | ||
name: r'attribute', | ||
required: false, | ||
includeIfNull: false, | ||
unknownEnumValue: ObjectWithInlineEnumDefaultValueAttributeEnum.unknownDefaultOpenApi, | ||
) | ||
|
||
|
||
final ObjectWithInlineEnumDefaultValueAttributeEnum? attribute; | ||
|
||
|
||
|
||
|
||
|
||
@override | ||
bool operator ==(Object other) => identical(this, other) || other is ObjectWithInlineEnumDefaultValue && | ||
other.attribute == attribute; | ||
|
||
@override | ||
int get hashCode => | ||
attribute.hashCode; | ||
|
||
factory ObjectWithInlineEnumDefaultValue.fromJson(Map<String, dynamic> json) => _$ObjectWithInlineEnumDefaultValueFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$ObjectWithInlineEnumDefaultValueToJson(this); | ||
|
||
@override | ||
String toString() { | ||
return toJson().toString(); | ||
} | ||
|
||
} | ||
|
||
/// Object one attribute enum with default value | ||
enum ObjectWithInlineEnumDefaultValueAttributeEnum { | ||
/// Object one attribute enum with default value | ||
@JsonValue(r'value_one') | ||
valueOne(r'value_one'), | ||
/// Object one attribute enum with default value | ||
@JsonValue(r'value_two') | ||
valueTwo(r'value_two'), | ||
/// Object one attribute enum with default value | ||
@JsonValue(r'unknown_default_open_api') | ||
unknownDefaultOpenApi(r'unknown_default_open_api'); | ||
|
||
const ObjectWithInlineEnumDefaultValueAttributeEnum(this.value); | ||
|
||
final String value; | ||
|
||
@override | ||
String toString() => value; | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...store/dart-dio/petstore_client_lib_fake-json_serializable/test/object_with_enum_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'package:test/test.dart'; | ||
import 'package:openapi/openapi.dart'; | ||
|
||
// tests for ObjectWithEnum | ||
void main() { | ||
final ObjectWithEnum? instance = /* ObjectWithEnum(...) */ null; | ||
// TODO add properties to the entity | ||
|
||
group(ObjectWithEnum, () { | ||
// TestEnum attribute (default value: TestEnum.empty) | ||
test('to test the property `attribute`', () async { | ||
// TODO | ||
}); | ||
|
||
}); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we keep the same test schemas and add new one covered by this PR instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous test schemas were actually incorrect — they were missing an
allOf
, which caused inconsistent behavior.I fixed that and renamed the test and parameters to make them consistent with the other tests in the project.
Additionally, I added a new test that covers a separate case where the enum is defined inline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not keep the same
?
why do you need to change the enum values to something else?
wouldn't "1", "2" still work with the fix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These enum values are not similar to the values of other enums in other test cases.
This change only affects consistency.
Leaving these changes unchanged will not change anything.
Its will work.
I can return these values back if it is important.