Skip to content
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 @@ -125,20 +125,13 @@ protected ImmutableMap.Builder<String, Mustache.Lambda> addMustacheLambdas() {

@Override
public String toDefaultValue(Schema schema) {
if (ModelUtils.isMapSchema(schema)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to remove these 4 lines from DartClient too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, in the dart generator you need the collection default values. But in dart-dio there are none, we use a builder pattern there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The models are mutable and you said you would expect to have an empty collection that you can just add to after instantiating the object. This is what the collection default values are used for.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what the collection default values are used for.

Yes, when I worked on that I kept it for backwards compatibility, I would do it differently now: keep compatibility with most popular generators where default value is null, unless field is required or defined as non-null. At some point we'll have to break it, but not rush.

return "const {}";
} else if (ModelUtils.isArraySchema(schema)) {
return "const []";
}

if (schema.getDefault() != null) {
if (ModelUtils.isStringSchema(schema)) {
return "'" + schema.getDefault().toString().replaceAll("'", "\\'") + "'";
}
return schema.getDefault().toString();
} else {
return "null";
}
return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ abstract class {{classname}} implements Built<{{classname}}, {{classname}}Builde
// Boilerplate code needed to wire-up generated code
{{classname}}._();

static void _initializeBuilder({{{classname}}}Builder b) => b{{#vars}}{{#defaultValue}}
..{{{name}}} = {{#isEnum}}{{^isContainer}}const {{{classname}}}{{{enumName}}}._({{/isContainer}}{{/isEnum}}{{{defaultValue}}}{{#isEnum}}{{^isContainer}}){{/isContainer}}{{/isEnum}}{{/defaultValue}}{{/vars}};

factory {{classname}}([updates({{classname}}Builder b)]) = _${{classname}};
static Serializer<{{classname}}> get serializer => _${{#lambda.camelcase}}{{{classname}}}{{/lambda.camelcase}}Serializer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:{{pubName}}/api.dart';
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
{{#vars}}**{{name}}** | {{#isPrimitiveType}}**{{{dataType}}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{{dataType}}}**]({{complexType}}.md){{/isPrimitiveType}} | {{{description}}} | {{^required}}[optional] {{/required}}{{#readOnly}}[readonly] {{/readOnly}}{{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}}
{{#vars}}**{{name}}** | {{#isPrimitiveType}}**{{{dataType}}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{{dataType}}}**]({{complexType}}.md){{/isPrimitiveType}} | {{{description}}} | {{^required}}[optional] {{/required}}{{#readOnly}}[readonly] {{/readOnly}}{{#defaultValue}}[default to {{{defaultValue}}}]{{/defaultValue}}
{{/vars}}

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void simpleModelTest() {
Assert.assertEquals(property1.baseName, "id");
Assert.assertEquals(property1.dataType, "int");
Assert.assertEquals(property1.name, "id");
Assert.assertEquals(property1.defaultValue, "null");
Assert.assertNull(property1.defaultValue);
Assert.assertEquals(property1.baseType, "int");
Assert.assertTrue(property1.required);
Assert.assertTrue(property1.isPrimitiveType);
Expand All @@ -79,7 +79,7 @@ public void simpleModelTest() {
Assert.assertEquals(property2.baseName, "name");
Assert.assertEquals(property2.dataType, "String");
Assert.assertEquals(property2.name, "name");
Assert.assertEquals(property2.defaultValue, "null");
Assert.assertNull(property2.defaultValue);
Assert.assertEquals(property2.baseType, "String");
Assert.assertTrue(property2.required);
Assert.assertTrue(property2.isPrimitiveType);
Expand All @@ -90,7 +90,7 @@ public void simpleModelTest() {
Assert.assertEquals(property3.complexType, "DateTime");
Assert.assertEquals(property3.dataType, "DateTime");
Assert.assertEquals(property3.name, "createdAt");
Assert.assertEquals(property3.defaultValue, "null");
Assert.assertNull(property3.defaultValue);
Assert.assertEquals(property3.baseType, "DateTime");
Assert.assertFalse(property3.required);
Assert.assertFalse(property3.isContainer);
Expand Down Expand Up @@ -128,7 +128,7 @@ public void simpleModelWithTimeMachineTest() {
Assert.assertEquals(property1.baseName, "id");
Assert.assertEquals(property1.dataType, "int");
Assert.assertEquals(property1.name, "id");
Assert.assertEquals(property1.defaultValue, "null");
Assert.assertNull(property1.defaultValue);
Assert.assertEquals(property1.baseType, "int");
Assert.assertTrue(property1.required);
Assert.assertTrue(property1.isPrimitiveType);
Expand All @@ -138,7 +138,7 @@ public void simpleModelWithTimeMachineTest() {
Assert.assertEquals(property2.baseName, "name");
Assert.assertEquals(property2.dataType, "String");
Assert.assertEquals(property2.name, "name");
Assert.assertEquals(property2.defaultValue, "null");
Assert.assertNull(property2.defaultValue);
Assert.assertEquals(property2.baseType, "String");
Assert.assertTrue(property2.required);
Assert.assertTrue(property2.isPrimitiveType);
Expand All @@ -149,7 +149,7 @@ public void simpleModelWithTimeMachineTest() {
Assert.assertEquals(property3.complexType, "OffsetDateTime");
Assert.assertEquals(property3.dataType, "OffsetDateTime");
Assert.assertEquals(property3.name, "createdAt");
Assert.assertEquals(property3.defaultValue, "null");
Assert.assertNull(property3.defaultValue);
Assert.assertEquals(property3.baseType, "OffsetDateTime");
Assert.assertFalse(property3.required);
Assert.assertFalse(property3.isContainer);
Expand All @@ -159,7 +159,7 @@ public void simpleModelWithTimeMachineTest() {
Assert.assertEquals(property4.complexType, "OffsetDate");
Assert.assertEquals(property4.dataType, "OffsetDate");
Assert.assertEquals(property4.name, "birthDate");
Assert.assertEquals(property4.defaultValue, "null");
Assert.assertNull(property4.defaultValue);
Assert.assertEquals(property4.baseType, "OffsetDate");
Assert.assertFalse(property4.required);
Assert.assertFalse(property4.isContainer);
Expand Down Expand Up @@ -187,7 +187,7 @@ public void listPropertyTest() {
Assert.assertEquals(property1.baseName, "id");
Assert.assertEquals(property1.dataType, "int");
Assert.assertEquals(property1.name, "id");
Assert.assertEquals(property1.defaultValue, "null");
Assert.assertNull(property1.defaultValue);
Assert.assertEquals(property1.baseType, "int");
Assert.assertTrue(property1.required);
Assert.assertTrue(property1.isPrimitiveType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import 'package:openapi/api.dart';
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**code** | **int** | | [optional] [default to null]
**type** | **String** | | [optional] [default to null]
**message** | **String** | | [optional] [default to null]
**code** | **int** | | [optional]
**type** | **String** | | [optional]
**message** | **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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import 'package:openapi/api.dart';
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**id** | **int** | | [optional] [default to null]
**name** | **String** | | [optional] [default to null]
**id** | **int** | | [optional]
**name** | **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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import 'package:openapi/api.dart';
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**id** | **int** | | [optional] [default to null]
**petId** | **int** | | [optional] [default to null]
**quantity** | **int** | | [optional] [default to null]
**shipDate** | [**DateTime**](DateTime.md) | | [optional] [default to null]
**status** | **String** | Order Status | [optional] [default to null]
**id** | **int** | | [optional]
**petId** | **int** | | [optional]
**quantity** | **int** | | [optional]
**shipDate** | [**DateTime**](DateTime.md) | | [optional]
**status** | **String** | Order Status | [optional]
**complete** | **bool** | | [optional] [default to false]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
Expand Down
12 changes: 6 additions & 6 deletions samples/client/petstore/dart-dio/petstore_client_lib/doc/Pet.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import 'package:openapi/api.dart';
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**id** | **int** | | [optional] [default to null]
**category** | [**Category**](Category.md) | | [optional] [default to null]
**name** | **String** | | [default to null]
**photoUrls** | **BuiltList<String>** | | [default to const []]
**tags** | [**BuiltList<Tag>**](Tag.md) | | [optional] [default to const []]
**status** | **String** | pet status in the store | [optional] [default to null]
**id** | **int** | | [optional]
**category** | [**Category**](Category.md) | | [optional]
**name** | **String** | |
**photoUrls** | **BuiltList<String>** | |
**tags** | [**BuiltList<Tag>**](Tag.md) | | [optional]
**status** | **String** | pet status in the store | [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)

Expand Down
22 changes: 11 additions & 11 deletions samples/client/petstore/dart-dio/petstore_client_lib/doc/PetApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ try {

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**petId** | **int**| Pet id to delete | [default to null]
**apiKey** | **String**| | [optional] [default to null]
**petId** | **int**| Pet id to delete |
**apiKey** | **String**| | [optional]

### Return type

Expand Down Expand Up @@ -133,7 +133,7 @@ try {

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**status** | [**BuiltList<String>**](String.md)| Status values that need to be considered for filter | [default to const []]
**status** | [**BuiltList<String>**](String.md)| Status values that need to be considered for filter |

### Return type

Expand Down Expand Up @@ -178,7 +178,7 @@ try {

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**tags** | [**BuiltList<String>**](String.md)| Tags to filter by | [default to const []]
**tags** | [**BuiltList<String>**](String.md)| Tags to filter by |

### Return type

Expand Down Expand Up @@ -225,7 +225,7 @@ try {

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**petId** | **int**| ID of pet to return | [default to null]
**petId** | **int**| ID of pet to return |

### Return type

Expand Down Expand Up @@ -311,9 +311,9 @@ try {

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**petId** | **int**| ID of pet that needs to be updated | [default to null]
**name** | **String**| Updated name of the pet | [optional] [default to null]
**status** | **String**| Updated status of the pet | [optional] [default to null]
**petId** | **int**| ID of pet that needs to be updated |
**name** | **String**| Updated name of the pet | [optional]
**status** | **String**| Updated status of the pet | [optional]

### Return type

Expand Down Expand Up @@ -358,9 +358,9 @@ try {

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**petId** | **int**| ID of pet to update | [default to null]
**additionalMetadata** | **String**| Additional data to pass to server | [optional] [default to null]
**file** | **Uint8List**| file to upload | [optional] [default to null]
**petId** | **int**| ID of pet to update |
**additionalMetadata** | **String**| Additional data to pass to server | [optional]
**file** | **Uint8List**| file to upload | [optional]

### Return type

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ try {

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**orderId** | **String**| ID of the order that needs to be deleted | [default to null]
**orderId** | **String**| ID of the order that needs to be deleted |

### Return type

Expand Down Expand Up @@ -126,7 +126,7 @@ try {

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**orderId** | **int**| ID of pet that needs to be fetched | [default to null]
**orderId** | **int**| ID of pet that needs to be fetched |

### Return type

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import 'package:openapi/api.dart';
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**id** | **int** | | [optional] [default to null]
**name** | **String** | | [optional] [default to null]
**id** | **int** | | [optional]
**name** | **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)

Expand Down
16 changes: 8 additions & 8 deletions samples/client/petstore/dart-dio/petstore_client_lib/doc/User.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import 'package:openapi/api.dart';
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**id** | **int** | | [optional] [default to null]
**username** | **String** | | [optional] [default to null]
**firstName** | **String** | | [optional] [default to null]
**lastName** | **String** | | [optional] [default to null]
**email** | **String** | | [optional] [default to null]
**password** | **String** | | [optional] [default to null]
**phone** | **String** | | [optional] [default to null]
**userStatus** | **int** | User Status | [optional] [default to null]
**id** | **int** | | [optional]
**username** | **String** | | [optional]
**firstName** | **String** | | [optional]
**lastName** | **String** | | [optional]
**email** | **String** | | [optional]
**password** | **String** | | [optional]
**phone** | **String** | | [optional]
**userStatus** | **int** | User Status | [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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ try {

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**username** | **String**| The name that needs to be deleted | [default to null]
**username** | **String**| The name that needs to be deleted |

### Return type

Expand Down Expand Up @@ -207,7 +207,7 @@ try {

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**username** | **String**| The name that needs to be fetched. Use user1 for testing. | [default to null]
**username** | **String**| The name that needs to be fetched. Use user1 for testing. |

### Return type

Expand Down Expand Up @@ -249,8 +249,8 @@ try {

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**username** | **String**| The user name for login | [default to null]
**password** | **String**| The password for login in clear text | [default to null]
**username** | **String**| The user name for login |
**password** | **String**| The password for login in clear text |

### Return type

Expand Down Expand Up @@ -329,7 +329,7 @@ try {

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**username** | **String**| name that need to be deleted | [default to null]
**username** | **String**| name that need to be deleted |
**body** | [**User**](User.md)| Updated user object |

### Return type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ abstract class ApiResponse implements Built<ApiResponse, ApiResponseBuilder> {
// Boilerplate code needed to wire-up generated code
ApiResponse._();

static void _initializeBuilder(ApiResponseBuilder b) => b;

factory ApiResponse([updates(ApiResponseBuilder b)]) = _$ApiResponse;
static Serializer<ApiResponse> get serializer => _$apiResponseSerializer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ abstract class Category implements Built<Category, CategoryBuilder> {
// Boilerplate code needed to wire-up generated code
Category._();

static void _initializeBuilder(CategoryBuilder b) => b;

factory Category([updates(CategoryBuilder b)]) = _$Category;
static Serializer<Category> get serializer => _$categorySerializer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ abstract class Order implements Built<Order, OrderBuilder> {
// Boilerplate code needed to wire-up generated code
Order._();

static void _initializeBuilder(OrderBuilder b) => b
..complete = false;

factory Order([updates(OrderBuilder b)]) = _$Order;
static Serializer<Order> get serializer => _$orderSerializer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ abstract class Pet implements Built<Pet, PetBuilder> {
// Boilerplate code needed to wire-up generated code
Pet._();

static void _initializeBuilder(PetBuilder b) => b;

factory Pet([updates(PetBuilder b)]) = _$Pet;
static Serializer<Pet> get serializer => _$petSerializer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ abstract class Tag implements Built<Tag, TagBuilder> {
// Boilerplate code needed to wire-up generated code
Tag._();

static void _initializeBuilder(TagBuilder b) => b;

factory Tag([updates(TagBuilder b)]) = _$Tag;
static Serializer<Tag> get serializer => _$tagSerializer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ abstract class User implements Built<User, UserBuilder> {
// Boilerplate code needed to wire-up generated code
User._();

static void _initializeBuilder(UserBuilder b) => b;

factory User([updates(UserBuilder b)]) = _$User;
static Serializer<User> get serializer => _$userSerializer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import 'package:openapi/api.dart';
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**code** | **int** | | [optional] [default to null]
**type** | **String** | | [optional] [default to null]
**message** | **String** | | [optional] [default to null]
**code** | **int** | | [optional]
**type** | **String** | | [optional]
**message** | **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)

Expand Down
Loading