Skip to content
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

[Python] remove default value from being fallback to example #2213

Merged
merged 2 commits into from
Feb 22, 2019
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 @@ -614,14 +614,6 @@ public String toDefaultValue(Schema p) {
else
return "True";
}
// include fallback to example, default defined as server only
// example is not defined as server only
if (p.getExample() != null) {
if (Boolean.valueOf(p.getExample().toString()) == false)
return "False";
else
return "True";
}
} else if (ModelUtils.isDateSchema(p)) {
// TODO
} else if (ModelUtils.isDateTimeSchema(p)) {
Expand All @@ -630,48 +622,24 @@ public String toDefaultValue(Schema p) {
if (p.getDefault() != null) {
return p.getDefault().toString();
}
// default numbers are not yet returned by v2 spec openAPI results
// https://github.com/swagger-api/swagger-parser/issues/971
// include fallback to example, default defined as server only
// example is not defined as server only
if (p.getExample() != null) {
return p.getExample().toString();
}
} else if (ModelUtils.isIntegerSchema(p)) {
if (p.getDefault() != null) {
return p.getDefault().toString();
}
// default integers are not yet returned by v2 spec openAPI results
// https://github.com/swagger-api/swagger-parser/issues/971
// include fallback to example, default defined as server only
// example is not defined as server only
if (p.getExample() != null) {
return p.getExample().toString();
}
} else if (ModelUtils.isStringSchema(p)) {
if (p.getDefault() != null) {
if (Pattern.compile("\r\n|\r|\n").matcher((String) p.getDefault()).find())
return "'''" + p.getDefault() + "'''";
else
return "'" + p.getDefault() + "'";
}
// include fallback to example, default defined as server only
// example is not defined as server only
if (p.getExample() != null) {
if (Pattern.compile("\r\n|\r|\n").matcher((String) p.getExample()).find())
return "'''" + p.getExample() + "'''";
else
return "'" + p.getExample() + "'";
}
} else if (ModelUtils.isArraySchema(p)) {
if (p.getDefault() != null) {
return p.getDefault().toString();
}
// include fallback to example, default defined as server only
// example is not defined as server only
if (p.getExample() != null) {
return p.getExample().toString();
}
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,7 @@ definitions:
uuid:
type: string
format: uuid
example: 72f98069-206d-4f12-9f12-3d1e525a8e84
password:
type: string
format: password
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,7 @@ components:
uuid:
type: string
format: uuid
example: 72f98069-206d-4f12-9f12-3d1e525a8e84
password:
type: string
format: password
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/go/go-petstore/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,7 @@ components:
format: date-time
type: string
uuid:
example: 72f98069-206d-4f12-9f12-3d1e525a8e84
format: uuid
type: string
password:
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/haskell-http-client/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,7 @@ components:
format: date-time
type: string
uuid:
example: 72f98069-206d-4f12-9f12-3d1e525a8e84
format: uuid
type: string
password:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public FormatTest uuid(UUID uuid) {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public FormatTest uuid(UUID uuid) {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public FormatTest uuid(UUID uuid) {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public FormatTest uuid(UUID uuid) {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public FormatTest uuid(UUID uuid) {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public FormatTest uuid(UUID uuid) {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public FormatTest uuid(UUID uuid) {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public FormatTest uuid(UUID uuid) {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public FormatTest uuid(UUID uuid) {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public FormatTest uuid(UUID uuid) {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public FormatTest uuid(UUID uuid) {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public FormatTest uuid(UUID uuid) {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public FormatTest uuid(UUID uuid) {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public FormatTest uuid(UUID uuid) {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public FormatTest uuid(UUID uuid) {
* @return uuid
**/
@Valid
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public FormatTest uuid(UUID uuid) {
* @return uuid
**/
@Valid
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public FormatTest uuid(UUID uuid) {
* @return uuid
**/
@Valid
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public FormatTest uuid(UUID uuid) {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public FormatTest uuid(UUID uuid) {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public FormatTest uuid(UUID uuid) {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public FormatTest uuid(UUID uuid) {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public FormatTest uuid(UUID uuid) {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/python/docs/Pet.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**id** | **int** | | [optional]
**category** | [**Category**](Category.md) | | [optional]
**name** | **str** | | [default to 'doggie']
**name** | **str** | |
**photo_urls** | **list[str]** | |
**tags** | [**list[Tag]**](Tag.md) | | [optional]
**status** | **str** | pet status in the store | [optional]
Expand Down
8 changes: 4 additions & 4 deletions samples/client/petstore/python/docs/TypeHolderExample.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**string_item** | **str** | | [default to 'what']
**string_item** | **str** | |
**number_item** | **float** | | [default to 1.234]
**integer_item** | **int** | | [default to -2]
**bool_item** | **bool** | | [default to True]
**array_item** | **list[int]** | | [default to [0, 1, 2, 3]]
**integer_item** | **int** | |
**bool_item** | **bool** | |
**array_item** | **list[int]** | |

[[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
30 changes: 15 additions & 15 deletions samples/client/petstore/python/docs/XmlItem.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,33 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**attribute_string** | **str** | | [optional] [default to 'string']
**attribute_string** | **str** | | [optional]
**attribute_number** | **float** | | [optional] [default to 1.234]
**attribute_integer** | **int** | | [optional] [default to -2]
**attribute_boolean** | **bool** | | [optional] [default to True]
**attribute_integer** | **int** | | [optional]
**attribute_boolean** | **bool** | | [optional]
**wrapped_array** | **list[int]** | | [optional]
**name_string** | **str** | | [optional] [default to 'string']
**name_string** | **str** | | [optional]
**name_number** | **float** | | [optional] [default to 1.234]
**name_integer** | **int** | | [optional] [default to -2]
**name_boolean** | **bool** | | [optional] [default to True]
**name_integer** | **int** | | [optional]
**name_boolean** | **bool** | | [optional]
**name_array** | **list[int]** | | [optional]
**name_wrapped_array** | **list[int]** | | [optional]
**prefix_string** | **str** | | [optional] [default to 'string']
**prefix_string** | **str** | | [optional]
**prefix_number** | **float** | | [optional] [default to 1.234]
**prefix_integer** | **int** | | [optional] [default to -2]
**prefix_boolean** | **bool** | | [optional] [default to True]
**prefix_integer** | **int** | | [optional]
**prefix_boolean** | **bool** | | [optional]
**prefix_array** | **list[int]** | | [optional]
**prefix_wrapped_array** | **list[int]** | | [optional]
**namespace_string** | **str** | | [optional] [default to 'string']
**namespace_string** | **str** | | [optional]
**namespace_number** | **float** | | [optional] [default to 1.234]
**namespace_integer** | **int** | | [optional] [default to -2]
**namespace_boolean** | **bool** | | [optional] [default to True]
**namespace_integer** | **int** | | [optional]
**namespace_boolean** | **bool** | | [optional]
**namespace_array** | **list[int]** | | [optional]
**namespace_wrapped_array** | **list[int]** | | [optional]
**prefix_ns_string** | **str** | | [optional] [default to 'string']
**prefix_ns_string** | **str** | | [optional]
**prefix_ns_number** | **float** | | [optional] [default to 1.234]
**prefix_ns_integer** | **int** | | [optional] [default to -2]
**prefix_ns_boolean** | **bool** | | [optional] [default to True]
**prefix_ns_integer** | **int** | | [optional]
**prefix_ns_boolean** | **bool** | | [optional]
**prefix_ns_array** | **list[int]** | | [optional]
**prefix_ns_wrapped_array** | **list[int]** | | [optional]

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/python/petstore_api/models/pet.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Pet(object):
'status': 'status'
}

def __init__(self, id=None, category=None, name='doggie', photo_urls=None, tags=None, status=None): # noqa: E501
def __init__(self, id=None, category=None, name=None, photo_urls=None, tags=None, status=None): # noqa: E501
"""Pet - a model defined in OpenAPI""" # noqa: E501

self._id = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TypeHolderExample(object):
'array_item': 'array_item'
}

def __init__(self, string_item='what', number_item=1.234, integer_item=-2, bool_item=True, array_item=[0, 1, 2, 3]): # noqa: E501
def __init__(self, string_item=None, number_item=1.234, integer_item=None, bool_item=None, array_item=None): # noqa: E501
"""TypeHolderExample - a model defined in OpenAPI""" # noqa: E501

self._string_item = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class XmlItem(object):
'prefix_ns_wrapped_array': 'prefix_ns_wrapped_array'
}

def __init__(self, attribute_string='string', attribute_number=1.234, attribute_integer=-2, attribute_boolean=True, wrapped_array=None, name_string='string', name_number=1.234, name_integer=-2, name_boolean=True, name_array=None, name_wrapped_array=None, prefix_string='string', prefix_number=1.234, prefix_integer=-2, prefix_boolean=True, prefix_array=None, prefix_wrapped_array=None, namespace_string='string', namespace_number=1.234, namespace_integer=-2, namespace_boolean=True, namespace_array=None, namespace_wrapped_array=None, prefix_ns_string='string', prefix_ns_number=1.234, prefix_ns_integer=-2, prefix_ns_boolean=True, prefix_ns_array=None, prefix_ns_wrapped_array=None): # noqa: E501
def __init__(self, attribute_string=None, attribute_number=1.234, attribute_integer=None, attribute_boolean=None, wrapped_array=None, name_string=None, name_number=1.234, name_integer=None, name_boolean=None, name_array=None, name_wrapped_array=None, prefix_string=None, prefix_number=1.234, prefix_integer=None, prefix_boolean=None, prefix_array=None, prefix_wrapped_array=None, namespace_string=None, namespace_number=1.234, namespace_integer=None, namespace_boolean=None, namespace_array=None, namespace_wrapped_array=None, prefix_ns_string=None, prefix_ns_number=1.234, prefix_ns_integer=None, prefix_ns_boolean=None, prefix_ns_array=None, prefix_ns_wrapped_array=None): # noqa: E501
"""XmlItem - a model defined in OpenAPI""" # noqa: E501

self._attribute_string = None
Expand Down
Loading