validation error with example
Not certain if it's an issue with python 3.10 or not but I always get a validation error with your example and also the code that is generated from my openapi doc.
I copy/pasted from the README.md to create the PetStoreAPIClient.
pet_client = PetStoreAPIClient(response_handler=JsonResponseHandler, request_formatter=JsonRequestFormatter)
params = PetIdPathParams(petId="petid1")
result = pet_client.show_pet_by_id(path_params=params)
print(result)
(<class 'pydantic.error_wrappers.ValidationError'>, ValidationError(model='ParsingModel[PetIdPathParams]', errors=[{'loc': ('__root__', 'petId'), 'msg': 'field required', 'type': 'value_error.missing'}]), <traceback object at 0x7f2c6db4d980>)
Looks like it's happening around line 36 of https://github.com/mom1/api-client-pydantic/blob/main/apiclient_pydantic/serializers.py but I can't determine if I'm doing something wrong with the generated client, it's py 3.10 compatibility issue, or something is broken in the api-client-pydantic.
Seems it was me doing it wrong.
pet_client = PetStoreAPIClient(response_handler=JsonResponseHandler, request_formatter=JsonRequestFormatter)
result = pet_client.show_pet_by_id(petId="petid1")
Would it be a good idea to modify the template to add None, validator, and **kwargs so the IDE doesn't give warnings?
def show_pet_by_id(self, path_params: PetIdPathParams = ..., **kwargs) -> Pets:
"""Info for a specific pet"""
if not path_params:
raise RuntimeError("path_params are required")
return self.get(Endpoints.show_pet_by_id.format(**path_params))
Looks like flipping this to True will turn on the dots: https://github.com/mom1/apiclient-pydantic-generator/blob/master/apiclient_pydantic_generator/parser.py#L311
Then I can add ,**kwargs here: https://github.com/mom1/apiclient-pydantic-generator/blob/master/apiclient_pydantic_generator/templates/client.jinja2#L11
Are there any downsides to doing this?
I'm sorry, but I'm very busy this month. I'll be happy to look into this, but a little later.
@mom1 no worries. I have it working how I want with local library edits. I just wanted to ensure I was following best practices and try to get things working how I want without the edits.
Looks like it needs to be parametrized.