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

[Feature] Allow for extra keywords in a routes' parameter specifications #107

Closed
jonathanlintott opened this issue Mar 3, 2021 · 3 comments · Fixed by #115
Closed

[Feature] Allow for extra keywords in a routes' parameter specifications #107

jonathanlintott opened this issue Mar 3, 2021 · 3 comments · Fixed by #115
Labels
enhancement New feature or request

Comments

@jonathanlintott
Copy link

The specification keywords for routes are currently hardcoded to only generate name, in, schema, required, description as is dictated here, specifically this block of code:

params.append(
    {
        "name": name,
        "in": "query",
        "schema": schema,
        "required": name in query.get("required", []),
        "description": schema.get("description", ""),
    }
)

However there are other keywords that might want to be added for different routes and models. For example the style and explode keywords as explained here. It would be beneficial to have some way for this to be passed in on a model-by-model basis for different routes. Something akin to the following:

params.append(
    {
        "name": name,
        "in": "query",
        "schema": schema,
        "required": name in query.get("required", []),
        "description": schema.get("description", ""),
        **extra_spec_kwargs
    }
)

Although I'm not sure what the best way to provide extra_spec_kwargs would be with the current API.

@jonathanlintott jonathanlintott changed the title [Feature] Allow for extra keywords in route parameter specifications [Feature] Allow for extra keywords in a routes' parameter specifications Mar 3, 2021
@kemingy
Copy link
Member

kemingy commented Mar 5, 2021

Thanks for your advice.

One way to implement this is to use the pydantic.Field(extra).

from pydantic import BaseModel, Field


class MyModel(BaseModel):
    name: str = Field(..., explode=True, style="label")

So we can get the details from MyModel.schema().

@jonathanlintott
Copy link
Author

jonathanlintott commented Mar 5, 2021

Such that the parse_params function would change to do something like:

extra = {label: schema.pop(label) for label in ("explode", "style", "allowReserved") if label in schema}
params.append(
    {
        "name": name,
        "in": "query",
        "schema": schema,
        "required": name in query.get("required", []),
        "description": schema.get("description", ""),
        **extra
    }
)

If I've understood you correctly?

@kemingy
Copy link
Member

kemingy commented Mar 5, 2021

Yeah. LGTM. If you want to create a PR for this, that'll be great if you can also add some test cases.

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

Successfully merging a pull request may close this issue.

2 participants