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

* remove example fallback

* reset test case
This commit is contained in:
William Cheng 2019-02-22 20:44:27 +08:00 committed by GitHub
parent 163b00459f
commit f2002b25da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
59 changed files with 77 additions and 105 deletions

View File

@ -614,14 +614,6 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
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)) {
@ -630,10 +622,6 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
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();
}
@ -641,13 +629,6 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
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())
@ -655,23 +636,10 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
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;

View File

@ -1344,6 +1344,7 @@ definitions:
uuid:
type: string
format: uuid
example: 72f98069-206d-4f12-9f12-3d1e525a8e84
password:
type: string
format: password

View File

@ -1373,6 +1373,7 @@ components:
uuid:
type: string
format: uuid
example: 72f98069-206d-4f12-9f12-3d1e525a8e84
password:
type: string
format: password

View File

@ -1422,6 +1422,7 @@ components:
format: date-time
type: string
uuid:
example: 72f98069-206d-4f12-9f12-3d1e525a8e84
format: uuid
type: string
password:

View File

@ -1422,6 +1422,7 @@ components:
format: date-time
type: string
uuid:
example: 72f98069-206d-4f12-9f12-3d1e525a8e84
format: uuid
type: string
password:

View File

@ -287,7 +287,7 @@ public class FormatTest {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}

View File

@ -287,7 +287,7 @@ public class FormatTest {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}

View File

@ -287,7 +287,7 @@ public class FormatTest {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}

View File

@ -287,7 +287,7 @@ public class FormatTest {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}

View File

@ -286,7 +286,7 @@ public class FormatTest {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}

View File

@ -287,7 +287,7 @@ public class FormatTest {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}

View File

@ -287,7 +287,7 @@ public class FormatTest {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}

View File

@ -307,7 +307,7 @@ public class FormatTest implements Parcelable {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}

View File

@ -303,7 +303,7 @@ public class FormatTest {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}

View File

@ -303,7 +303,7 @@ public class FormatTest {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}

View File

@ -287,7 +287,7 @@ public class FormatTest {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}

View File

@ -318,7 +318,7 @@ public class FormatTest {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}

View File

@ -287,7 +287,7 @@ public class FormatTest {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}

View File

@ -303,7 +303,7 @@ public class FormatTest {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}

View File

@ -297,7 +297,7 @@ public class FormatTest {
* @return uuid
**/
@Valid
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}

View File

@ -297,7 +297,7 @@ public class FormatTest {
* @return uuid
**/
@Valid
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}

View File

@ -297,7 +297,7 @@ public class FormatTest {
* @return uuid
**/
@Valid
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}

View File

@ -303,7 +303,7 @@ public class FormatTest {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}

View File

@ -303,7 +303,7 @@ public class FormatTest {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}

View File

@ -303,7 +303,7 @@ public class FormatTest {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}

View File

@ -287,7 +287,7 @@ public class FormatTest {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}

View File

@ -287,7 +287,7 @@ public class FormatTest {
* Get uuid
* @return uuid
**/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;
}

View File

@ -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]

View File

@ -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)

View File

@ -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]

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -30,12 +30,9 @@ class TestTypeHolderExample(unittest.TestCase):
def testTypeHolderExample(self):
"""Test TypeHolderExample"""
model = TypeHolderExample()
self.assertEqual(model.string_item, 'what')
self.assertEqual(model.number_item, 1.234)
self.assertEqual(model.integer_item, -2)
self.assertEqual(model.bool_item, True)
self.assertEqual(model.array_item, [0, 1, 2, 3])
# FIXME: construct object with mandatory attributes with example values
# model = petstore_api.models.type_holder_example.TypeHolderExample() # noqa: E501
pass
if __name__ == '__main__':

View File

@ -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]

View File

@ -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

View File

@ -54,7 +54,7 @@ public class FormatTest {
@ApiModelProperty(value = "")
private Date dateTime;
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
private UUID uuid;
@ApiModelProperty(required = true, value = "")

View File

@ -314,7 +314,7 @@ public class FormatTest implements Serializable {
* @return uuid
**/
@JsonProperty("uuid")
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;

View File

@ -318,7 +318,7 @@ public class FormatTest {
* @return uuid
**/
@JsonProperty("uuid")
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;

View File

@ -243,7 +243,7 @@ public class FormatTest implements Serializable {
}
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
@JsonProperty("uuid")
public UUID getUuid() {
return uuid;

View File

@ -1494,6 +1494,7 @@ components:
format: date-time
type: string
uuid:
example: 72f98069-206d-4f12-9f12-3d1e525a8e84
format: uuid
type: string
password:

View File

@ -243,7 +243,7 @@ public class FormatTest implements Serializable {
}
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
@JsonProperty("uuid")
public UUID getUuid() {
return uuid;

View File

@ -1494,6 +1494,7 @@ components:
format: date-time
type: string
uuid:
example: 72f98069-206d-4f12-9f12-3d1e525a8e84
format: uuid
type: string
password:

View File

@ -312,7 +312,7 @@ public class FormatTest {
* @return uuid
**/
@JsonProperty("uuid")
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;

View File

@ -312,7 +312,7 @@ public class FormatTest {
* @return uuid
**/
@JsonProperty("uuid")
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;

View File

@ -312,7 +312,7 @@ public class FormatTest {
* @return uuid
**/
@JsonProperty("uuid")
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;

View File

@ -312,7 +312,7 @@ public class FormatTest {
* @return uuid
**/
@JsonProperty("uuid")
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
public UUID getUuid() {
return uuid;

View File

@ -304,7 +304,7 @@ public class FormatTest {
* Get uuid
* @return uuid
*/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
@Valid

View File

@ -304,7 +304,7 @@ public class FormatTest {
* Get uuid
* @return uuid
*/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
@Valid

View File

@ -304,7 +304,7 @@ public class FormatTest {
* Get uuid
* @return uuid
*/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
@Valid

View File

@ -304,7 +304,7 @@ public class FormatTest {
* Get uuid
* @return uuid
*/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
@Valid

View File

@ -304,7 +304,7 @@ public class FormatTest {
* Get uuid
* @return uuid
*/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
@Valid

View File

@ -304,7 +304,7 @@ public class FormatTest {
* Get uuid
* @return uuid
*/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
@Valid

View File

@ -304,7 +304,7 @@ public class FormatTest {
* Get uuid
* @return uuid
*/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
@Valid

View File

@ -304,7 +304,7 @@ public class FormatTest {
* Get uuid
* @return uuid
*/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
@Valid

View File

@ -1554,6 +1554,7 @@ components:
format: date-time
type: string
uuid:
example: 72f98069-206d-4f12-9f12-3d1e525a8e84
format: uuid
type: string
password:

View File

@ -304,7 +304,7 @@ public class FormatTest {
* Get uuid
* @return uuid
*/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
@Valid

View File

@ -304,7 +304,7 @@ public class FormatTest {
* Get uuid
* @return uuid
*/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
@Valid

View File

@ -304,7 +304,7 @@ public class FormatTest {
* Get uuid
* @return uuid
*/
@ApiModelProperty(value = "")
@ApiModelProperty(example = "72f98069-206d-4f12-9f12-3d1e525a8e84", value = "")
@Valid