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

modify query_params and path_params class names

Open brunnels opened this issue 3 years ago • 6 comments

Is there a way to change how the query_params and path_params class names are generated without modifying the parser?

I would like them to be named with the camelcase endpoint name plus the suffix.

Example of what I get now:

    def get_field_values(
        self,
        path_params: FieldNamePathParams,
        query_params: XmlNodeNameParameter1Parameter2Parameter3QueryParams
    ) -> GetFieldValuesResponse:
        """Get Field Values"""
        return self.get(Endpoints.get_field_values, query_params)

what I want:

    def get_field_values(
            self, 
            path_params: GetFieldValuesPathParams,
            query_params: GetFieldValuesQueryParams
    ) -> GetFieldValuesResponse:
        """Get Field Values"""
        return self.get(Endpoints.get_field_values, query_params)

This is how I get it now but would rather not modify the library.

Change https://github.com/mom1/apiclient-pydantic-generator/blob/master/apiclient_pydantic_generator/parser.py#L320

operation_name = re.sub('(?i)response$', '', self._temporary_operation.get('response'))
original_name = self._get_model_name(operation_name, '', suffix=suffix)

brunnels avatar Mar 01 '22 17:03 brunnels

Thank you for your interest in the project.

I think the method using response is not very good. In my case response = List[Pet] the result will be List[Pet]QueryParams.

What do you think of this method?

original_name = self._get_model_name(path[1], '', suffix=suffix)

endpoint = pet/findByStatus models_name = PetFindByStatusQueryParams

mom1 avatar Mar 01 '22 17:03 mom1

@mom1 I will test tomorrow and let you know. Thanks for looking at this.

brunnels avatar Mar 02 '22 00:03 brunnels

@mom1 That almost works but need only the last part of a path like /api/v1/get_field_values/. Something like:

original_name = self._get_model_name(f"{pathlib.Path(path[1]).name}/", '', suffix=suffix)

brunnels avatar Mar 02 '22 11:03 brunnels

Still getting the leading underscore for endpoints with path parameters

brunnels avatar Mar 02 '22 11:03 brunnels

I think the other problem with using the path name is that you could have a GET, POST, and PUT endpoint all with the same path name but each could have different query_params. I think using the operation name is probably the best way to avoid this as they all need to be unique.

brunnels avatar Mar 03 '22 13:03 brunnels

That's right, but here I need to investigate where to get the operation_id

mom1 avatar Mar 08 '22 19:03 mom1