Skip to content

Path parameters as function positional arguments #429

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

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve sort of path parameters
Also fix typo

Co-authored-by: Dylan Anthony <43723790+dbanty@users.noreply.github.com>
  • Loading branch information
tsotnikov and dbanty authored May 25, 2021
commit a5b6e5fe3b303738a75e0c6c8ff964ec33a3ae0b
10 changes: 6 additions & 4 deletions openapi_python_client/parser/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,17 @@ def _add_parameters(
@staticmethod
def _sort_parameters(*, endpoint: "Endpoint", path: str) -> Union["Endpoint", ParseError]:
endpoint = deepcopy(endpoint)
parameters_form_path = re.findall(_PATH_PARAM_REGEX, path)
parameters_from_path = re.findall(_PATH_PARAM_REGEX, path)
try:
endpoint.path_parameters.sort(key=lambda p: parameters_from_path.index(p.name))
except ValueError:
pass # We're going to catch the difference down below
path_parameter_names = [p.name for p in endpoint.path_parameters]
if sorted(parameters_form_path) != sorted(path_parameter_names):
if parameters_from_path != path_parameter_names:
return ParseError(
data=endpoint.path_parameters,
detail="Incorrect path templating (Path parameters do not match with path)",
)

endpoint.path_parameters.sort(key=lambda p: parameters_form_path.index(p.name))
return endpoint

@staticmethod
Expand Down