Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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,9 @@ 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}}}'] == null
? {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}
: (json[r'{{{baseName}}}'] as Map).map((k, v) => MapEntry(k as String, (v as Map).cast<String, {{items.items.dataType}}>())){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}},
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Outdated
{{/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 @@ -45,15 +45,17 @@ class ApiResponse {
@override
bool operator ==(Object other) => identical(this, other) || other is ApiResponse &&
other.code == code &&
other.type == type &&
other.message == message;
other.type == type &&
other.message == message;


@override
int get hashCode =>
// ignore: unnecessary_parenthesis
(code == null ? 0 : code!.hashCode) +
(type == null ? 0 : type!.hashCode) +
(message == null ? 0 : message!.hashCode);
(type == null ? 0 : type!.hashCode) +
(message == null ? 0 : message!.hashCode);


@override
String toString() => 'ApiResponse[code=$code, type=$type, message=$message]';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ class Category {
@override
bool operator ==(Object other) => identical(this, other) || other is Category &&
other.id == id &&
other.name == name;
other.name == name;


@override
int get hashCode =>
// ignore: unnecessary_parenthesis
(id == null ? 0 : id!.hashCode) +
(name == null ? 0 : name!.hashCode);
(name == null ? 0 : name!.hashCode);


@override
String toString() => 'Category[id=$id, name=$name]';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,23 @@ class Order {
@override
bool operator ==(Object other) => identical(this, other) || other is Order &&
other.id == id &&
other.petId == petId &&
other.quantity == quantity &&
other.shipDate == shipDate &&
other.status == status &&
other.complete == complete;
other.petId == petId &&
other.quantity == quantity &&
other.shipDate == shipDate &&
other.status == status &&
other.complete == complete;


@override
int get hashCode =>
// ignore: unnecessary_parenthesis
(id == null ? 0 : id!.hashCode) +
(petId == null ? 0 : petId!.hashCode) +
(quantity == null ? 0 : quantity!.hashCode) +
(shipDate == null ? 0 : shipDate!.hashCode) +
(status == null ? 0 : status!.hashCode) +
(complete.hashCode);
(petId == null ? 0 : petId!.hashCode) +
(quantity == null ? 0 : quantity!.hashCode) +
(shipDate == null ? 0 : shipDate!.hashCode) +
(status == null ? 0 : status!.hashCode) +
(complete.hashCode);


@override
String toString() => 'Order[id=$id, petId=$petId, quantity=$quantity, shipDate=$shipDate, status=$status, complete=$complete]';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,23 @@ class Pet {
@override
bool operator ==(Object other) => identical(this, other) || other is Pet &&
other.id == id &&
other.category == category &&
other.name == name &&
_deepEquality.equals(other.photoUrls, photoUrls) &&
_deepEquality.equals(other.tags, tags) &&
other.status == status;
other.category == category &&
other.name == name &&
_deepEquality.equals(other.photoUrls, photoUrls) &&
_deepEquality.equals(other.tags, tags) &&
other.status == status;


@override
int get hashCode =>
// ignore: unnecessary_parenthesis
(id == null ? 0 : id!.hashCode) +
(category == null ? 0 : category!.hashCode) +
(name.hashCode) +
(photoUrls.hashCode) +
(tags.hashCode) +
(status == null ? 0 : status!.hashCode);
(category == null ? 0 : category!.hashCode) +
(name.hashCode) +
(photoUrls.hashCode) +
(tags.hashCode) +
(status == null ? 0 : status!.hashCode);


@override
String toString() => 'Pet[id=$id, category=$category, name=$name, photoUrls=$photoUrls, tags=$tags, status=$status]';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ class Tag {
@override
bool operator ==(Object other) => identical(this, other) || other is Tag &&
other.id == id &&
other.name == name;
other.name == name;


@override
int get hashCode =>
// ignore: unnecessary_parenthesis
(id == null ? 0 : id!.hashCode) +
(name == null ? 0 : name!.hashCode);
(name == null ? 0 : name!.hashCode);


@override
String toString() => 'Tag[id=$id, name=$name]';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,27 @@ class User {
@override
bool operator ==(Object other) => identical(this, other) || other is User &&
other.id == id &&
other.username == username &&
other.firstName == firstName &&
other.lastName == lastName &&
other.email == email &&
other.password == password &&
other.phone == phone &&
other.userStatus == userStatus;
other.username == username &&
other.firstName == firstName &&
other.lastName == lastName &&
other.email == email &&
other.password == password &&
other.phone == phone &&
other.userStatus == userStatus;


@override
int get hashCode =>
// ignore: unnecessary_parenthesis
(id == null ? 0 : id!.hashCode) +
(username == null ? 0 : username!.hashCode) +
(firstName == null ? 0 : firstName!.hashCode) +
(lastName == null ? 0 : lastName!.hashCode) +
(email == null ? 0 : email!.hashCode) +
(password == null ? 0 : password!.hashCode) +
(phone == null ? 0 : phone!.hashCode) +
(userStatus == null ? 0 : userStatus!.hashCode);
(username == null ? 0 : username!.hashCode) +
(firstName == null ? 0 : firstName!.hashCode) +
(lastName == null ? 0 : lastName!.hashCode) +
(email == null ? 0 : email!.hashCode) +
(password == null ? 0 : password!.hashCode) +
(phone == null ? 0 : phone!.hashCode) +
(userStatus == null ? 0 : userStatus!.hashCode);


@override
String toString() => 'User[id=$id, username=$username, firstName=$firstName, lastName=$lastName, email=$email, password=$password, phone=$phone, userStatus=$userStatus]';
Expand Down
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 @@ -131,6 +135,10 @@ lib/model/outer_enum_integer_default_value.dart
lib/model/outer_object_with_enum_property.dart
lib/model/parent_with_nullable.dart
lib/model/pet.dart
lib/model/pet_empty_metadata.dart
lib/model/pet_reaction_response.dart
lib/model/pet_reaction_status.dart
lib/model/pet_reactions_response.dart
lib/model/read_only_first.dart
lib/model/single_ref_type.dart
lib/model/special_model_name.dart
Expand All @@ -139,3 +147,7 @@ lib/model/test_enum.dart
lib/model/test_inline_freeform_additional_properties_request.dart
lib/model/user.dart
pubspec.yaml
test/pet_empty_metadata_test.dart
test/pet_reaction_response_test.dart
test/pet_reaction_status_test.dart
test/pet_reactions_response_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,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<String, Map<String, bool>>**](Map.md) | | [optional] [default to const {}]
**reactionCounts** | [**Map<String, Map<String, int>>**](Map.md) | | [optional] [default to const {}]

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


Loading
Loading