apiclient-pydantic-generator icon indicating copy to clipboard operation
apiclient-pydantic-generator copied to clipboard

validation error with example

Open brunnels opened this issue 3 years ago • 5 comments

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.

brunnels avatar Mar 02 '22 14:03 brunnels

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))

brunnels avatar Mar 03 '22 12:03 brunnels

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?

brunnels avatar Mar 03 '22 14:03 brunnels

I'm sorry, but I'm very busy this month. I'll be happy to look into this, but a little later.

mom1 avatar Mar 03 '22 15:03 mom1

@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.

brunnels avatar Mar 03 '22 16:03 brunnels

Looks like it needs to be parametrized.

mom1 avatar Mar 08 '22 19:03 mom1