forked from loafle/openapi-generator-original
[python-experimental] Make the array items attribute optional (#6133)
* Make the array items optional * Handle any type schema * Handle any type schema * remove prefix and fullSuffix * Remove prefix and suffix * fix Java code comment * Add code comments, use recursion for any type * Address review comments
This commit is contained in:
@@ -881,22 +881,33 @@ public class PythonClientExperimentalCodegen extends PythonClientCodegen {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string representation of the Python types for the specified schema.
|
||||
* Return a string representation of the Python types for the specified OAS schema.
|
||||
* Primitive types in the OAS specification are implemented in Python using the corresponding
|
||||
* Python primitive types.
|
||||
* Composed types (e.g. allAll, oneOf, anyOf) are represented in Python using list of types.
|
||||
*
|
||||
* The caller should set the prefix and suffix arguments to empty string, except when
|
||||
* getTypeString invokes itself recursively. A non-empty prefix/suffix may be specified
|
||||
* to wrap the return value in a python dict, list or tuple.
|
||||
*
|
||||
* Examples:
|
||||
* - "bool, date, float" The data must be a bool, date or float.
|
||||
* - "[bool, date]" The data must be an array, and the array items must be a bool or date.
|
||||
*
|
||||
* @param p The OAS schema.
|
||||
* @param prefix prepended to the returned value.
|
||||
* @param suffix appended to the returned value.
|
||||
* @return a string representation of the Python types
|
||||
* @return a comma-separated string representation of the Python types
|
||||
*/
|
||||
public String getTypeString(Schema p, String prefix, String suffix) {
|
||||
private String getTypeString(Schema p, String prefix, String suffix) {
|
||||
// this is used to set dataType, which defines a python tuple of classes
|
||||
String fullSuffix = suffix;
|
||||
if (")".equals(suffix)) {
|
||||
fullSuffix = "," + suffix;
|
||||
}
|
||||
if (ModelUtils.isAnyTypeSchema(p)) {
|
||||
return prefix + "bool, date, datetime, dict, float, int, list, str, none_type" + suffix;
|
||||
}
|
||||
// Resolve $ref because ModelUtils.isXYZ methods do not automatically resolve references.
|
||||
if (ModelUtils.isNullable(ModelUtils.getReferencedSchema(this.openAPI, p))) {
|
||||
fullSuffix = ", none_type" + suffix;
|
||||
@@ -910,7 +921,19 @@ public class PythonClientExperimentalCodegen extends PythonClientCodegen {
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
return prefix + "[" + getTypeString(inner, "", "") + "]" + fullSuffix;
|
||||
if (inner == null) {
|
||||
// In OAS 3.0.x, the array "items" attribute is required.
|
||||
// In OAS >= 3.1, the array "items" attribute is optional such that the OAS
|
||||
// specification is aligned with the JSON schema specification.
|
||||
// When "items" is not specified, the elements of the array may be anything at all.
|
||||
// In that case, the return value should be:
|
||||
// "[bool, date, datetime, dict, float, int, list, str, none_type]"
|
||||
// Using recursion to wrap the allowed python types in an array.
|
||||
Schema anyType = new Schema(); // A Schema without any attribute represents 'any type'.
|
||||
return getTypeString(anyType, "[", "]");
|
||||
} else {
|
||||
return prefix + getTypeString(inner, "[", "]") + fullSuffix;
|
||||
}
|
||||
}
|
||||
if (ModelUtils.isFileSchema(p)) {
|
||||
return prefix + "file_type" + fullSuffix;
|
||||
|
||||
@@ -13,8 +13,8 @@ Name | Type | Description | Notes
|
||||
**user_status** | **int** | User Status | [optional]
|
||||
**arbitrary_object** | **bool, date, datetime, dict, float, int, list, str** | test code generation for objects Value must be a map of strings to values. It cannot be the 'null' value. | [optional]
|
||||
**arbitrary_nullable_object** | **bool, date, datetime, dict, float, int, list, str, none_type** | test code generation for nullable objects. Value must be a map of strings to values or the 'null' value. | [optional]
|
||||
**arbitrary_type_value** | **object** | test code generation for any type Value can be any type - string, number, boolean, array or object. | [optional]
|
||||
**arbitrary_nullable_type_value** | **object, none_type** | test code generation for any type Value can be any type - string, number, boolean, array, object or the 'null' value. | [optional]
|
||||
**arbitrary_type_value** | **bool, date, datetime, dict, float, int, list, str, none_type** | test code generation for any type Value can be any type - string, number, boolean, array or object. | [optional]
|
||||
**arbitrary_nullable_type_value** | **bool, date, datetime, dict, float, int, list, str, none_type** | test code generation for any type Value can be any type - string, number, boolean, array, object or the 'null' value. | [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)
|
||||
|
||||
|
||||
@@ -87,8 +87,8 @@ class User(ModelNormal):
|
||||
'user_status': (int,), # noqa: E501
|
||||
'arbitrary_object': (bool, date, datetime, dict, float, int, list, str,), # noqa: E501
|
||||
'arbitrary_nullable_object': (bool, date, datetime, dict, float, int, list, str, none_type,), # noqa: E501
|
||||
'arbitrary_type_value': (object,), # noqa: E501
|
||||
'arbitrary_nullable_type_value': (object, none_type,), # noqa: E501
|
||||
'arbitrary_type_value': (bool, date, datetime, dict, float, int, list, str, none_type,), # noqa: E501
|
||||
'arbitrary_nullable_type_value': (bool, date, datetime, dict, float, int, list, str, none_type,), # noqa: E501
|
||||
}
|
||||
|
||||
@cached_property
|
||||
@@ -164,8 +164,8 @@ class User(ModelNormal):
|
||||
user_status (int): User Status. [optional] # noqa: E501
|
||||
arbitrary_object (bool, date, datetime, dict, float, int, list, str): test code generation for objects Value must be a map of strings to values. It cannot be the 'null' value.. [optional] # noqa: E501
|
||||
arbitrary_nullable_object (bool, date, datetime, dict, float, int, list, str, none_type): test code generation for nullable objects. Value must be a map of strings to values or the 'null' value.. [optional] # noqa: E501
|
||||
arbitrary_type_value (object): test code generation for any type Value can be any type - string, number, boolean, array or object.. [optional] # noqa: E501
|
||||
arbitrary_nullable_type_value (object, none_type): test code generation for any type Value can be any type - string, number, boolean, array, object or the 'null' value.. [optional] # noqa: E501
|
||||
arbitrary_type_value (bool, date, datetime, dict, float, int, list, str, none_type): test code generation for any type Value can be any type - string, number, boolean, array or object.. [optional] # noqa: E501
|
||||
arbitrary_nullable_type_value (bool, date, datetime, dict, float, int, list, str, none_type): test code generation for any type Value can be any type - string, number, boolean, array, object or the 'null' value.. [optional] # noqa: E501
|
||||
"""
|
||||
|
||||
self._data_store = {}
|
||||
|
||||
Reference in New Issue
Block a user