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

fix(type-safe-api): fix syntax error for python runtime request parameters with descriptions #610

Merged
merged 2 commits into from
Oct 20, 2023

Conversation

cogwirrel
Copy link
Member

@cogwirrel cogwirrel commented Oct 20, 2023

Descriptions in Python request parameters would previously render invalid python syntax as quotes were escaped as ". Use triple curly braces ({{{vendorExtensions.x-py-typing}}}) to ensure these are rendered correctly.

Additionally, field references can only be used once per field in a pydantic model, and since fields with descriptions include the field in the type annotation these would fail at runtime when another field is used in the assignment, ie:

foo: Annotated[StrictStr, Field(..., description="...")] = Field(alias='foo')

The above causes a runtime error (ValueError: `Field` default cannot be set in `Annotated` for ... - pydantic/pydantic#3991 )

We therefore remove the assignment of a Field value, which is ok since the alias is not required as the handler wrapper already constructs a dict with the paramNames as keys rather than the baseNames which are in the raw request. ie we already do:

"{{paramName}}": coerce_parameter("{{baseName}}", ...)

Which means we even load renamed parameters (like a header x-foo-bar from a dictionary which names it as x_foo_bar).

Fixes #609

…eters with descriptions

Descriptions in Python request parameters would previously render invalid python syntax as quotes
were escaped as ". Use triple curly braces to ensure these are rendered correctly.
Additionally, field references can only be used once per field in a pydantic model, and since fields
with descriptions include the field in the type annotation these would fail at runtime when another
field is used in the assignment (ie foo: Annotated[StrictStr, Field(..., description="...")] =
Field(alias='foo') ). We therefore remove the assignment of a Field value, which is ok since the
alias is not required as the handler wrapper already constructs a dict with the "paramName"s as keys
rather than the "baseName"s which are in the raw request.

Fixes #609
@cogwirrel cogwirrel merged commit 4057d69 into mainline Oct 20, 2023
3 checks passed
@cogwirrel cogwirrel deleted the fix/python-request-param-descriptions branch October 20, 2023 03:33
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 this pull request may close these issues.

[BUG] (type-safe-api) Python runtime has invalid code when request parameters have descriptions
2 participants