Skip to content
Open
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 @@ -719,6 +719,19 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required) {
property.isModel = true;
});

} else if (property.isEnum) {
// Multi-element anyOf/oneOf where the default codegen guessed at an
// inline enum (e.g. anyOf of [$ref enum, inline literal enum]). The
// dart generator can't produce a single enum class that covers all
// branches, and the inline-enum template is suppressed for composed
// schemas, so we'd emit references to an enum class that is never
// declared anywhere in lib/model/. Collapse the property to its
// underlying primitive type instead.
property.isEnum = false;
property.datatypeWithEnum = property.dataType;
property.enumName = null;
property.allowableValues = null;
property._enum = null;
}
}
return property;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/// Returns a new [{{{classname}}}] instance.
{{{classname}}}({
{{{classname}}}({{#hasVars}}{
{{#vars}}
{{!
A field is required in Dart when it is
required && !defaultValue in OAS
}}
{{^required}}{{#vendorExtensions.x-is-optional}}this.{{{name}}}{{#defaultValue}} = const Optional.present({{#isEnum}}{{^isContainer}}const {{{enumName}}}._({{/isContainer}}{{/isEnum}}{{{.}}}{{#isEnum}}{{^isContainer}}){{/isContainer}}{{/isEnum}}){{/defaultValue}}{{^defaultValue}} = const Optional.absent(){{/defaultValue}},{{/vendorExtensions.x-is-optional}}{{/required}}{{^required}}{{^vendorExtensions.x-is-optional}}this.{{{name}}}{{#defaultValue}} = {{#isEnum}}{{^isContainer}}const {{{enumName}}}._({{/isContainer}}{{/isEnum}}{{{.}}}{{#isEnum}}{{^isContainer}}){{/isContainer}}{{/isEnum}}{{/defaultValue}},{{/vendorExtensions.x-is-optional}}{{/required}}{{#required}}{{^defaultValue}}required {{/defaultValue}}{{/required}}{{#required}}this.{{{name}}}{{#defaultValue}} = {{#isEnum}}{{^isContainer}}const {{{enumName}}}._({{/isContainer}}{{/isEnum}}{{{.}}}{{#isEnum}}{{^isContainer}}){{/isContainer}}{{/isEnum}}{{/defaultValue}},{{/required}}
{{/vars}}
});
}{{/hasVars}});
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ class {{{classname}}} {

{{/vars}}
@override
bool operator ==(Object other) => identical(this, other) || other is {{{classname}}} &&
bool operator ==(Object other) => identical(this, other) || other is {{{classname}}}{{#hasVars}} &&
{{#vars}}
{{#isMap}}_deepEquality.equals(other.{{{name}}}, {{{name}}}){{/isMap}}{{^isMap}}{{#isArray}}_deepEquality.equals(other.{{{name}}}, {{{name}}}){{/isArray}}{{^isArray}}other.{{{name}}} == {{{name}}}{{/isArray}}{{/isMap}}{{^-last}} &&{{/-last}}{{#-last}};{{/-last}}
{{/vars}}
{{/vars}}{{/hasVars}}{{^hasVars}};{{/hasVars}}

@override
int get hashCode =>
// ignore: unnecessary_parenthesis
{{#vars}}
({{#isNullable}}{{{name}}} == null ? 0 : {{/isNullable}}{{^isNullable}}{{^required}}{{^defaultValue}}{{{name}}} == null ? 0 : {{/defaultValue}}{{/required}}{{/isNullable}}{{{name}}}{{#isNullable}}!{{/isNullable}}{{^isNullable}}{{^required}}{{^defaultValue}}!{{/defaultValue}}{{/required}}{{/isNullable}}.hashCode){{^-last}} +{{/-last}}{{#-last}};{{/-last}}
{{/vars}}
{{/vars}}{{^hasVars}} 0;{{/hasVars}}

@override
String toString() => '{{{classname}}}[{{#vars}}{{{name}}}=${{{name}}}{{^-last}}, {{/-last}}{{/vars}}]';
Expand Down Expand Up @@ -228,7 +228,7 @@ class {{{classname}}} {
{{{name}}}: {{items.complexType}}.mapFromJson(json[r'{{{baseName}}}']),
{{/items.complexType}}
{{^items.complexType}}
{{{name}}}: mapCastOfType<String, dynamic>(json, r'{{{baseName}}}'){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}} ?? {{{.}}}{{/defaultValue}}{{/required}},
{{{name}}}: (json[r'{{{baseName}}}'] as Map?)?.map((k, v) => MapEntry(k as String, (v as Map).cast<String, {{items.items.dataType}}>())){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}} ?? {{{.}}}{{/defaultValue}}{{/required}},
{{/items.complexType}}
{{/items.isMap}}
{{^items.isMap}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2141,3 +2141,54 @@ components:
$ref: '#/components/schemas/ObjectWithInlineEnum'
object_two:
$ref: '#/components/schemas/ObjectWithDuplicateInlineEnum'
PetReactionStatus:
type: string
title: PetReactionStatus
enum:
- liked
- disliked
- barked
PetReactionResponse:
type: object
description: |
Reproduces a bug where anyOf between a named-enum $ref and an inline
literal-enum produced a property typed as an undeclared enum class.
Generator must either inline a proper enum or fall back to String.
properties:
petId:
type: integer
format: int64
status:
anyOf:
- $ref: '#/components/schemas/PetReactionStatus'
- type: string
enum:
- pending-verification
PetEmptyMetadata:
description: |
Reproduces a bug where a schema that resolves to a class with zero
properties (e.g. an empty oneOf wrapper) emitted invalid Dart syntax
in `==`, `hashCode`, and the named-args constructor.
oneOf:
- type: string
- type: integer
PetReactionsResponse:
type: object
description: |
Reproduces a bug where nested `Map<String, Map<String, T>>` properties
were decoded with a single-level `mapCastOfType<String, dynamic>` cast
that can't be assigned to the declared field type.
properties:
myReacts:
type: object
additionalProperties:
type: object
additionalProperties:
type: boolean
reactionCounts:
type: object
additionalProperties:
type: object
additionalProperties:
type: integer
format: int32
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ doc/OuterObjectWithEnumProperty.md
doc/ParentWithNullable.md
doc/Pet.md
doc/PetApi.md
doc/PetEmptyMetadata.md
doc/PetReactionResponse.md
doc/PetReactionStatus.md
doc/PetReactionsResponse.md
doc/ReadOnlyFirst.md
doc/SingleRefType.md
doc/SpecialModelName.md
Expand Down Expand Up @@ -129,6 +133,10 @@ lib/src/model/outer_enum_integer_default_value.dart
lib/src/model/outer_object_with_enum_property.dart
lib/src/model/parent_with_nullable.dart
lib/src/model/pet.dart
lib/src/model/pet_empty_metadata.dart
lib/src/model/pet_reaction_response.dart
lib/src/model/pet_reaction_status.dart
lib/src/model/pet_reactions_response.dart
lib/src/model/read_only_first.dart
lib/src/model/single_ref_type.dart
lib/src/model/special_model_name.dart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ Class | Method | HTTP request | Description
- [OuterObjectWithEnumProperty](doc/OuterObjectWithEnumProperty.md)
- [ParentWithNullable](doc/ParentWithNullable.md)
- [Pet](doc/Pet.md)
- [PetEmptyMetadata](doc/PetEmptyMetadata.md)
- [PetReactionResponse](doc/PetReactionResponse.md)
- [PetReactionStatus](doc/PetReactionStatus.md)
- [PetReactionsResponse](doc/PetReactionsResponse.md)
- [ReadOnlyFirst](doc/ReadOnlyFirst.md)
- [SingleRefType](doc/SingleRefType.md)
- [SpecialModelName](doc/SpecialModelName.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# openapi.model.PetEmptyMetadata

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

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------

[[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,16 @@
# openapi.model.PetReactionResponse

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

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**petId** | **int** | | [optional]
**status** | **String** | | [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,14 @@
# openapi.model.PetReactionStatus

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

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------

[[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,16 @@
# openapi.model.PetReactionsResponse

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

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**myReacts** | [**Map&lt;String, Map&lt;String, bool&gt;&gt;**](Map.md) | | [optional]
**reactionCounts** | [**Map&lt;String, Map&lt;String, int&gt;&gt;**](Map.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
Expand Up @@ -66,6 +66,10 @@ export 'package:openapi/src/model/outer_enum_integer_default_value.dart';
export 'package:openapi/src/model/outer_object_with_enum_property.dart';
export 'package:openapi/src/model/parent_with_nullable.dart';
export 'package:openapi/src/model/pet.dart';
export 'package:openapi/src/model/pet_empty_metadata.dart';
export 'package:openapi/src/model/pet_reaction_response.dart';
export 'package:openapi/src/model/pet_reaction_status.dart';
export 'package:openapi/src/model/pet_reactions_response.dart';
export 'package:openapi/src/model/read_only_first.dart';
export 'package:openapi/src/model/single_ref_type.dart';
export 'package:openapi/src/model/special_model_name.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ import 'package:openapi/src/model/outer_composite.dart';
import 'package:openapi/src/model/outer_object_with_enum_property.dart';
import 'package:openapi/src/model/parent_with_nullable.dart';
import 'package:openapi/src/model/pet.dart';
import 'package:openapi/src/model/pet_empty_metadata.dart';
import 'package:openapi/src/model/pet_reaction_response.dart';
import 'package:openapi/src/model/pet_reactions_response.dart';
import 'package:openapi/src/model/read_only_first.dart';
import 'package:openapi/src/model/special_model_name.dart';
import 'package:openapi/src/model/tag.dart';
Expand Down Expand Up @@ -169,6 +172,15 @@ final _regMap = RegExp(r'^Map<String,(.*)>$');
return ParentWithNullable.fromJson(value as Map<String, dynamic>) as ReturnType;
case 'Pet':
return Pet.fromJson(value as Map<String, dynamic>) as ReturnType;
case 'PetEmptyMetadata':
return PetEmptyMetadata.fromJson(value as Map<String, dynamic>) as ReturnType;
case 'PetReactionResponse':
return PetReactionResponse.fromJson(value as Map<String, dynamic>) as ReturnType;
case 'PetReactionStatus':


case 'PetReactionsResponse':
return PetReactionsResponse.fromJson(value as Map<String, dynamic>) as ReturnType;
case 'ReadOnlyFirst':
return ReadOnlyFirst.fromJson(value as Map<String, dynamic>) as ReturnType;
case 'SingleRefType':
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// 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 'pet_empty_metadata.g.dart';


@CopyWith()
@JsonSerializable(
checked: true,
createToJson: true,
disallowUnrecognizedKeys: false,
explicitToJson: true,
)
class PetEmptyMetadata {
/// Returns a new [PetEmptyMetadata] instance.
PetEmptyMetadata({
});



@override
bool operator ==(Object other) => identical(this, other) || other is PetEmptyMetadata &&

@override
int get hashCode =>

factory PetEmptyMetadata.fromJson(Map<String, dynamic> json) => _$PetEmptyMetadataFromJson(json);

Map<String, dynamic> toJson() => _$PetEmptyMetadataToJson(this);

@override
String toString() {
return toJson().toString();
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//
// 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 'pet_reaction_response.g.dart';


@CopyWith()
@JsonSerializable(
checked: true,
createToJson: true,
disallowUnrecognizedKeys: false,
explicitToJson: true,
)
class PetReactionResponse {
/// Returns a new [PetReactionResponse] instance.
PetReactionResponse({

this.petId,

this.status,
});

@JsonKey(

name: r'petId',
required: false,
includeIfNull: false,
)


final int? petId;



@JsonKey(

name: r'status',
required: false,
includeIfNull: false,
)


final String? status;





@override
bool operator ==(Object other) => identical(this, other) || other is PetReactionResponse &&
other.petId == petId &&
other.status == status;

@override
int get hashCode =>
petId.hashCode +
status.hashCode;

factory PetReactionResponse.fromJson(Map<String, dynamic> json) => _$PetReactionResponseFromJson(json);

Map<String, dynamic> toJson() => _$PetReactionResponseToJson(this);

@override
String toString() {
return toJson().toString();
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//

// ignore_for_file: unused_element
import 'package:json_annotation/json_annotation.dart';


enum PetReactionStatus {
@JsonValue(r'liked')
liked(r'liked'),
@JsonValue(r'disliked')
disliked(r'disliked'),
@JsonValue(r'barked')
barked(r'barked'),
@JsonValue(r'unknown_default_open_api')
unknownDefaultOpenApi(r'unknown_default_open_api');

const PetReactionStatus(this.value);

final String value;

@override
String toString() => value;
}
Loading
Loading