Closed gbmarc1 closed 3 years ago
None should not be used as a default value because any property required or optional may or may not be Nullable.
None should not be used as a default value because any property required or optional may or may not be Nullable.
What do you think of a new class? Such as Empty
class Empty:
pass
@convert_js_args_to_python_args
def __init__(self, name, description, id=Empty(), created_on=Empty(), modified_on=Empty(), inactive_on=Empty(), status=Empty(), status_last_change=Empty(), *args, **kwargs):
Including a placeholder value like that could work but
readOnly functionality is dependent on the context in which the payload is instantiated.
the property is marked as readOnly being true and is in the required list, the required will take effect on the response only. A property MUST NOT be marked as both readOnly and writeOnly being true. Default value is false.
That wording means that instantiating the models in different contexts needs different method signatures.
So my suggestion would be to break out a separate method to instantiate classes in the two contexts.
__init__
could be used for the toServer contextWe already use the parameter spec_property_naming to indicate that the code is in the context of from_server
I think you are right. The init constructor should be used for the to_server context and another constructor for the from_server. I was looking for another feature "deserialization" in the models to convert a dict to an instance of the model. I suggest to name the method "from_dict". A bit like this:
Model instantiation is not only done with dictionaries. We also have array models and primitive model. Primitive models are made if there are validation or enum constraints. So we are instantiating models from openapi data, not just dicts.
Some examples:
We need all of those model types because endpoints can return refed component schemas for:
If we did not make the list and primitive model types, then we would leave out the enum and validation constraints.
ok sounds a good plan. I can try to implement that next week
Thank you
Could I have a reference that explain what is the difference between normal
/composed
/simple
models?
ModelNormal models are classes that store object schemas ModelSimple models are classes that store int/str/list/date/datetime schemas and they are only generated if there is a validation or enum constraint or if the model is a list model ModelComposed models are classes that store composed schemas Also described in code in the class definitions: https://github.com/OpenAPITools/openapi-generator/blob/master/samples/openapi3/client/petstore/python/petstore_api/model_utils.py#L288
Composed schemas are not always of type object. They can be any type. For example oneOf different array definitions.
Adding the classification Enhancement: Feature
because the feature readOnly parameters has not yet been implemented in python
Solved in #9409
Bug Report Checklist
@spacether
Python generator
Description
I have a POST endpoint and the request body and response body use the same schema definition as below.
Dataset
has multiplereadOnly
parameters that must be present in the response, but should not be provided in the request.I can instantiate the
Dataset
model providingNone
to the parameters that are readOnly and without verifying the model's input (_check_type=False
). However, post request still fails (404 bad request) because params are still present with None values.openapi-generator version
5.1.1
OpenAPI declaration file content or url
Generation Details
generate -i openapi/openapi.yaml -g "python" --package-name ex_ai_hub_api_client2 -p packageVersion=0.2.0
Steps to reproduce
Related issues/PRs
Suggest a fix
I suggest the following 3 modifications:
__init__
forreadOnly=True
parameters fromto
readOnly=True
andnullable=False
parameters when value isNone
.