question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to Use Schema with Path Parameter?

See original GitHub issue

In the example below, I am trying to figure out how to use the ClientSchema to correctly document and validate ClientResource.get. Is this possible?

ma = flask_marshmallow.Marshmallow()

class ClientSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = Client
    clientId  = ma.auto_field(description='The ID of the client', 
                                            required=True,
                                            validate=validate.Range(min=1))
                                            )

@bp.route('/<int:clientId>')
class ClientResource(MethodView):

    def get(self, *args, **kwargs):
        pass

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
lafrechcommented, Jan 27, 2021

I did think that the parameter converters could be employed to solve this issue, but I’m not familiar with werkzeug so really don’t know how to do this.

My example above should do what you want.

I understand the will to centralize.

I’d choose my way other yours because sending clientId twice to the view func kinda sucks while my method only leaves a bit of documentation in the call to route which is not that bad.

Yours should work too.

0reactions
Anti-Distinctlymintycommented, Jan 27, 2021

I rely on werkzeug path parameter converters for the validation, and if I define a custom path parameter converter, I register it in flask-smorest to get automatic documentation as explained in https://flask-smorest.readthedocs.io/en/latest/openapi.html#register-custom-path-parameter-converters.

I did think that the parameter converters could be employed to solve this issue, but I’m not familiar with werkzeug so really don’t know how to do this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Describing Parameters - Swagger
In OpenAPI, a path parameter is defined using in: path . ... To describe the parameter contents, you can use either the schema...
Read more >
Path Parameters - FastAPI
You can declare the type of a path parameter in the function, using standard Python type ... And because the generated schema is...
Read more >
OpenAPI Path Parameters referencing Component Properties
1 Answer 1 · Put the $ref inside the parameter schema . · Replace #components with #/components . · Enclose the reference values...
Read more >
API Schemas – Path, Query, and Body parameters - Encore.dev
Path parameters are specified by the path field in the //encore:api annotation. To specify a placeholder variable, use :name and add a function...
Read more >
SET PATH - Db2 SQL - IBM
SET CURRENT PATH = , 1 schema-name SYSTEM PATH SESSION_USER USER CURRENT PATH CURRENT PACKAGE PATH host-variable string-constant.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found