Open MAKOMO opened 1 year ago
thanks for reporting the issue, will try to fix it this weekend.
/modules/openapi-generator/src/main/resources/python/api_client.mustache not all objects include to_dict()
replace:
elif isinstance(obj, dict):
obj_dict = obj
else:
# Convert model obj to dict except
# attributes `openapi_types`, `attribute_map`
# and attributes which value is not None.
# Convert attribute name to json key in
# model definition for request.
obj_dict = obj.to_dict() <------ !!!
return {
key: self.sanitize_for_serialization(val)
for key, val in obj_dict.items()
}
by:
obj_dict = obj.__dict__
__dict__ could not always work.. if object will be nested - so for nested objects:
obj_dict = json.loads(json.dumps(obj, default=lambda o: o.__dict__))
Hi @wing328 @azdolinski , I still kicked the same error here about SecretStr, looks you guys have some discussion and fix, but the issue is still existed while I used the latest master code to generate python binding.
Looks this fix mentioned in https://github.com/OpenAPITools/openapi-generator/pull/17310 not merged
elif isinstance(obj, SecretStr):
return obj.get_secret_value()
What is the current status of this issue? Thanks
can you please file a new PR with the fix instead when you've time?
I noticed @azdolinski has a PR ready for this: https://github.com/azdolinski/openapi-generator/pull/2
Just sharing my experience if it is by some chance of any help to anyone.
# Working:
> docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate -i /local/rest-api-server/src/main/resources/openapi.yaml -g python -o /local/web-client/openapi_client
# Not working:
> docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:v7.4.0 generate -i /local/rest-api-server/src/main/resources/openapi.yaml -g python -o /local/web-client/openapi_client
↑↑↑↑↑↑↑
I mean using just that works, but then when I use the generated client for creating a user, I get the error from the title of this issue.
openapitools/openapi-generator-cli
is equivalent to openapitools/openapi-generator-cli:latest
which I was sure is equal to openapitools/openapi-generator-cli:v7.4.0
at the time of writing. Then I tested and saw the latest
points to a snapshot!
> docker run --rm openapitools/openapi-generator-cli:latest version
7.5.0-SNAPSHOT
Oddly enough this isn't allowed:
> docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:v7.5.0-SNAPSHOT generate -i /local/rest-api-server/src/main/resources/openapi.yaml -g python -o /local/web-client/openapi_client
docker: Error response from daemon: manifest for openapitools/openapi-generator-cli:v7.5.0-SNAPSHOT not found: manifest unknown: manifest unknown.
Does this mean the solution for me is to simply wait until a certain unknow date in the future, and things will work once the openapitools/openapi-generator-cli:v7.5.0
is available?
Seems like I started with my first python/flask project at almost the right time :)
Bug Report Checklist
Description
Calling a method with a credential object holding a password attribute of type string with
format: password
fails in the generated Python client code.openapi-generator version
I tested this on the current v7.0.0-beta as well as with todays trunk using the python (was python-nextgen) generator.
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
fails with