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

inline parameter enhance with python-experimental fix #12397

Original file line number Diff line number Diff line change
Expand Up @@ -4581,9 +4581,14 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
String parameterModelName = null;

if (parameter.getSchema() != null) {
parameterModelName = getParameterDataType(parameter ,parameter.getSchema());
parameterSchema = ModelUtils.getReferencedSchema(openAPI, parameter.getSchema());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This changing results means that unaliasSchema is working differently than ModelUtils.getReferencedSchema for these parameter schemas.
Investigate the details of this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is happening because if an enum schema is referenced, the schema with the reference is returned. This assumes that the generator generates a typed reference to that enum model.

CodegenProperty prop = fromProperty(parameter.getName(), parameterSchema);
parameterSchema = parameter.getSchema();
parameterModelName = getParameterDataType(parameter, parameterSchema);
CodegenProperty prop;
if (getUseInlineModelResolver()) {
prop = fromProperty(parameter.getName(), ModelUtils.getReferencedSchema(openAPI, parameterSchema));
} else {
prop = fromProperty(parameter.getName(), parameterSchema);
}
codegenParameter.setSchema(prop);
} else if (parameter.getContent() != null) {
Content content = parameter.getContent();
Expand All @@ -4592,8 +4597,8 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
}
Map.Entry<String, MediaType> entry = content.entrySet().iterator().next();
codegenParameter.contentType = entry.getKey();
parameterModelName = getParameterDataType(parameter, entry.getValue().getSchema());
parameterSchema = ModelUtils.getReferencedSchema(openAPI, entry.getValue().getSchema());
parameterSchema = entry.getValue().getSchema();
parameterModelName = getParameterDataType(parameter, parameterSchema);
} else {
parameterSchema = null;
}
Expand All @@ -4620,11 +4625,14 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)

parameterSchema = unaliasSchema(parameterSchema, Collections.emptyMap());
if (parameterSchema == null) {
LOGGER.warn("warning! Schema not found for parameter \" {} \", using String", parameter.getName());
parameterSchema = new StringSchema().description("//TODO automatically added by openapi-generator due to missing type definition.");
LOGGER.warn("warning! Schema not found for parameter \" {} \"", parameter.getName());
finishUpdatingParameter(codegenParameter, parameter);
return codegenParameter;
}
if (getUseInlineModelResolver()) {
parameterSchema = ModelUtils.getReferencedSchema(openAPI, parameterSchema);
}

ModelUtils.syncValidationProperties(parameterSchema, codegenParameter);
codegenParameter.setTypeProperties(parameterSchema);
codegenParameter.setComposedSchemas(getComposedSchemas(parameterSchema));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,11 @@ public interface IJsonSchemaValidationProperties {
* @param p the schema which contains the type info
*/
default void setTypeProperties(Schema p) {
if (ModelUtils.isModelWithPropertiesOnly(p)) {
setIsModel(true);
} else if (ModelUtils.isTypeObjectSchema(p)) {
if (ModelUtils.isTypeObjectSchema(p)) {
setIsMap(true);
if (ModelUtils.isModelWithPropertiesOnly(p)) {
setIsModel(true);
}
} else if (ModelUtils.isArraySchema(p)) {
setIsArray(true);
} else if (ModelUtils.isFileSchema(p) && !ModelUtils.isStringSchema(p)) {
Expand Down Expand Up @@ -221,6 +222,9 @@ default void setTypeProperties(Schema p) {
setIsNull(true);
} else if (ModelUtils.isAnyType(p)) {
setIsAnyType(true);
if (ModelUtils.isModelWithPropertiesOnly(p)) {
setIsModel(true);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2446,6 +2446,7 @@ To test the collection format in query parameters
```python
import petstore_api
from petstore_api.api import fake_api
from petstore_api.model.string_with_validation import StringWithValidation
from pprint import pprint
# Defining the host is optional and defaults to http://petstore.swagger.io:80/v2
# See configuration.py for a list of all supported configuration parameters.
Expand Down Expand Up @@ -2537,10 +2538,10 @@ Type | Description | Notes
**[str]** | |

#### RefParamSchema

Type | Description | Notes
Type | Description | Notes
------------- | ------------- | -------------
**str** | |
[**StringWithValidation**](StringWithValidation.md) | |


### Return Types, Responses

Expand Down Expand Up @@ -2622,7 +2623,7 @@ mapBean | MapBeanSchema | | optional
#### MapBeanSchema
Type | Description | Notes
------------- | ------------- | -------------
[**{str: (bool, date, datetime, dict, float, int, list, str, none_type)}**](Foo.md) | |
[**Foo**](Foo.md) | |


### Return Types, Responses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,32 @@

_path = '/foo'
_method = 'GET'
SchemaFor0ResponseBodyApplicationJson = Schema


class SchemaFor0ResponseBodyApplicationJson(
DictSchema
):

@classmethod
@property
def string(cls) -> typing.Type['Foo']:
return Foo


def __new__(
cls,
*args: typing.Union[dict, frozendict, ],
string: typing.Union['Foo', Unset] = unset,
_configuration: typing.Optional[Configuration] = None,
**kwargs: typing.Type[Schema],
) -> 'SchemaFor0ResponseBodyApplicationJson':
return super().__new__(
cls,
*args,
string=string,
_configuration=_configuration,
**kwargs,
)


@dataclass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,137 @@
)

# body param
SchemaForRequestBodyApplicationXWwwFormUrlencoded = Schema


class SchemaForRequestBodyApplicationXWwwFormUrlencoded(
DictSchema
):
_required_property_names = set((
))


class integer(
_SchemaValidator(
inclusive_maximum=100,
inclusive_minimum=10,
),
IntSchema
):
pass


class int32(
_SchemaValidator(
inclusive_maximum=200,
inclusive_minimum=20,
),
Int32Schema
):
pass
int64 = Int64Schema


class number(
_SchemaValidator(
inclusive_maximum=543.2,
inclusive_minimum=32.1,
),
NumberSchema
):
pass


class _float(
_SchemaValidator(
inclusive_maximum=987.6,
),
Float32Schema
):
pass
locals()['float'] = _float
del locals()['_float']


class double(
_SchemaValidator(
inclusive_maximum=123.4,
inclusive_minimum=67.8,
),
Float64Schema
):
pass


class string(
_SchemaValidator(
regex=[{
'pattern': r'[a-z]', # noqa: E501
'flags': (
re.IGNORECASE
)
}],
),
StrSchema
):
pass


class pattern_without_delimiter(
_SchemaValidator(
regex=[{
'pattern': r'^[A-Z].*', # noqa: E501
}],
),
StrSchema
):
pass
byte = StrSchema
binary = BinarySchema
date = DateSchema
dateTime = DateTimeSchema


class password(
_SchemaValidator(
max_length=64,
min_length=10,
),
StrSchema
):
pass
callback = StrSchema


def __new__(
cls,
*args: typing.Union[dict, frozendict, ],
integer: typing.Union[integer, Unset] = unset,
int32: typing.Union[int32, Unset] = unset,
int64: typing.Union[int64, Unset] = unset,
string: typing.Union[string, Unset] = unset,
binary: typing.Union[binary, Unset] = unset,
date: typing.Union[date, Unset] = unset,
dateTime: typing.Union[dateTime, Unset] = unset,
password: typing.Union[password, Unset] = unset,
callback: typing.Union[callback, Unset] = unset,
_configuration: typing.Optional[Configuration] = None,
**kwargs: typing.Type[Schema],
) -> 'SchemaForRequestBodyApplicationXWwwFormUrlencoded':
return super().__new__(
cls,
*args,
integer=integer,
int32=int32,
int64=int64,
string=string,
binary=binary,
date=date,
dateTime=dateTime,
password=password,
callback=callback,
_configuration=_configuration,
**kwargs,
)


request_body_body = api_client.RequestBody(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,82 @@ class RequestHeaderParams(RequestRequiredHeaderParams, RequestOptionalHeaderPara
schema=EnumHeaderStringSchema,
)
# body param
SchemaForRequestBodyApplicationXWwwFormUrlencoded = Schema


class SchemaForRequestBodyApplicationXWwwFormUrlencoded(
DictSchema
):


class enum_form_string_array(
ListSchema
):


class _items(
_SchemaEnumMaker(
enum_value_to_name={
">": "GREATER_THAN",
"$": "DOLLAR",
}
),
StrSchema
):

@classmethod
@property
def GREATER_THAN(cls):
return cls(">")

@classmethod
@property
def DOLLAR(cls):
return cls("$")


class enum_form_string(
_SchemaEnumMaker(
enum_value_to_name={
"_abc": "_ABC",
"-efg": "EFG",
"(xyz)": "XYZ",
}
),
StrSchema
):

@classmethod
@property
def _ABC(cls):
return cls("_abc")

@classmethod
@property
def EFG(cls):
return cls("-efg")

@classmethod
@property
def XYZ(cls):
return cls("(xyz)")


def __new__(
cls,
*args: typing.Union[dict, frozendict, ],
enum_form_string_array: typing.Union[enum_form_string_array, Unset] = unset,
enum_form_string: typing.Union[enum_form_string, Unset] = unset,
_configuration: typing.Optional[Configuration] = None,
**kwargs: typing.Type[Schema],
) -> 'SchemaForRequestBodyApplicationXWwwFormUrlencoded':
return super().__new__(
cls,
*args,
enum_form_string_array=enum_form_string_array,
enum_form_string=enum_form_string,
_configuration=_configuration,
**kwargs,
)


request_body_body = api_client.RequestBody(
Expand Down
Loading