-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement support for discriminated unions (#287)
- Loading branch information
Showing
20 changed files
with
448 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
83 changes: 83 additions & 0 deletions
83
swagger_parser/test/e2e/tests/basic/discriminated_one_of.3.0/discriminated_one_of.3.0.json
This file contains 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,83 @@ | ||
{ | ||
"openapi": "3.1.0", | ||
"info": { | ||
"title": "Family API", | ||
"version": "1.0.0" | ||
}, | ||
"paths": {}, | ||
"components": { | ||
"schemas": { | ||
"Family": { | ||
"type": "object", | ||
"properties": { | ||
"members": { | ||
"type": "array", | ||
"items": { | ||
"oneOf": [ | ||
{ | ||
"$ref": "#/components/schemas/Cat" | ||
}, | ||
{ | ||
"$ref": "#/components/schemas/Dog" | ||
}, | ||
{ | ||
"$ref": "#/components/schemas/Human" | ||
} | ||
], | ||
"discriminator": { | ||
"propertyName": "type", | ||
"mapping": { | ||
"Cat": "#/components/schemas/Cat", | ||
"Dog": "#/components/schemas/Dog", | ||
"Human": "#/components/schemas/Human" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"Cat": { | ||
"type": "object", | ||
"properties": { | ||
"type": { | ||
"type": "string", | ||
"enum": ["Cat"] | ||
}, | ||
"mewCount": { | ||
"type": "integer", | ||
"description": "Number of times the cat meows." | ||
} | ||
}, | ||
"required": ["type", "mewCount"] | ||
}, | ||
"Dog": { | ||
"type": "object", | ||
"properties": { | ||
"type": { | ||
"type": "string", | ||
"enum": ["Dog"] | ||
}, | ||
"barkSound": { | ||
"type": "string", | ||
"description": "The sound of the dog's bark." | ||
} | ||
}, | ||
"required": ["type", "barkSound"] | ||
}, | ||
"Human": { | ||
"type": "object", | ||
"properties": { | ||
"type": { | ||
"type": "string", | ||
"enum": ["Human"] | ||
}, | ||
"job": { | ||
"type": "string", | ||
"description": "The job of the human." | ||
} | ||
}, | ||
"required": ["type", "job"] | ||
} | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
swagger_parser/test/e2e/tests/basic/discriminated_one_of.3.0/expected_files/export.dart
This file contains 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,13 @@ | ||
// coverage:ignore-file | ||
// GENERATED CODE - DO NOT MODIFY BY HAND | ||
// ignore_for_file: type=lint, unused_import | ||
|
||
// Data classes | ||
export 'models/family.dart'; | ||
export 'models/cat.dart'; | ||
export 'models/dog.dart'; | ||
export 'models/human.dart'; | ||
export 'models/family_members_union.dart'; | ||
export 'models/cat_type.dart'; | ||
export 'models/dog_type.dart'; | ||
export 'models/human_type.dart'; |
22 changes: 22 additions & 0 deletions
22
swagger_parser/test/e2e/tests/basic/discriminated_one_of.3.0/expected_files/models/cat.dart
This file contains 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,22 @@ | ||
// coverage:ignore-file | ||
// GENERATED CODE - DO NOT MODIFY BY HAND | ||
// ignore_for_file: type=lint, unused_import | ||
|
||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
|
||
import 'cat_type.dart'; | ||
|
||
part 'cat.freezed.dart'; | ||
part 'cat.g.dart'; | ||
|
||
@Freezed() | ||
class Cat with _$Cat { | ||
const factory Cat({ | ||
required CatType type, | ||
|
||
/// Number of times the cat meows. | ||
required int mewCount, | ||
}) = _Cat; | ||
|
||
factory Cat.fromJson(Map<String, Object?> json) => _$CatFromJson(json); | ||
} |
23 changes: 23 additions & 0 deletions
23
..._parser/test/e2e/tests/basic/discriminated_one_of.3.0/expected_files/models/cat_type.dart
This file contains 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,23 @@ | ||
// coverage:ignore-file | ||
// GENERATED CODE - DO NOT MODIFY BY HAND | ||
// ignore_for_file: type=lint, unused_import | ||
|
||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
|
||
@JsonEnum() | ||
enum CatType { | ||
@JsonValue('Cat') | ||
cat('Cat'), | ||
|
||
/// Default value for all unparsed values, allows backward compatibility when adding new values on the backend. | ||
$unknown(null); | ||
|
||
const CatType(this.json); | ||
|
||
factory CatType.fromJson(String json) => values.firstWhere( | ||
(e) => e.json == json, | ||
orElse: () => $unknown, | ||
); | ||
|
||
final String? json; | ||
} |
22 changes: 22 additions & 0 deletions
22
swagger_parser/test/e2e/tests/basic/discriminated_one_of.3.0/expected_files/models/dog.dart
This file contains 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,22 @@ | ||
// coverage:ignore-file | ||
// GENERATED CODE - DO NOT MODIFY BY HAND | ||
// ignore_for_file: type=lint, unused_import | ||
|
||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
|
||
import 'dog_type.dart'; | ||
|
||
part 'dog.freezed.dart'; | ||
part 'dog.g.dart'; | ||
|
||
@Freezed() | ||
class Dog with _$Dog { | ||
const factory Dog({ | ||
required DogType type, | ||
|
||
/// The sound of the dog's bark. | ||
required String barkSound, | ||
}) = _Dog; | ||
|
||
factory Dog.fromJson(Map<String, Object?> json) => _$DogFromJson(json); | ||
} |
Oops, something went wrong.