Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify query_params and path_params class names #8

Open
brunnels opened this issue Mar 1, 2022 · 6 comments · May be fixed by #9
Open

modify query_params and path_params class names #8

brunnels opened this issue Mar 1, 2022 · 6 comments · May be fixed by #9

Comments

@brunnels
Copy link

brunnels commented Mar 1, 2022

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)
@mom1
Copy link
Owner

mom1 commented Mar 1, 2022

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 mom1 linked a pull request Mar 1, 2022 that will close this issue
@brunnels
Copy link
Author

brunnels commented Mar 2, 2022

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

@brunnels
Copy link
Author

brunnels commented Mar 2, 2022

@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
Copy link
Author

brunnels commented Mar 2, 2022

Still getting the leading underscore for endpoints with path parameters

@brunnels
Copy link
Author

brunnels commented Mar 3, 2022

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.

@mom1
Copy link
Owner

mom1 commented Mar 8, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants