Code Monkey home page Code Monkey logo

Comments (3)

kemingy avatar kemingy commented on August 25, 2024 3

Sorry I misunderstood your question before. Currently, this library doesn't support descriptions for the path variables. You can use function description for the path variables.

One possible way is to add another path model. But I'm not sure if we should validate the input again.

class PathVariables(pydantic.BaseModel):
    source: str = pydantic.Field(..., description='source language')
    target: str

@api.route('/api/<string:source>/<string:target>')
@spec.validate(path=PathVariables)
def index(source, target):
    pass

Feel free to give more feedbacks about this.

from spectree.

kemingy avatar kemingy commented on August 25, 2024

Check this example:

@app.route(
"/api/predict/<string(length=2):source>/<string(length=2):target>", methods=["POST"]
)
@api.validate(
query=Query, json=Data, resp=Response("HTTP_403", HTTP_200=Resp), tags=["model"]
)
def predict(source, target):
"""
predict demo
demo for `query`, `data`, `resp`, `x`
query with
``http POST ':8000/api/predict/zh/en?text=hello' uid=xxx limit=5 vip=false ``
"""
print(f"=> from {source} to {target}") # path
print(f"JSON: {request.context.json}") # Data
print(f"Query: {request.context.query}") # Query
if random() < 0.5:
abort(403)
return jsonify(label=int(10 * random()), score=random())

For the path variables, this library doesn't provide a strong validation with pydantic. It will use the default path converter.

But of course you can still get the correct OpenAPI document for path variables.

from spectree.

parisni avatar parisni commented on August 25, 2024

But of course you can still get the correct OpenAPI document for path variables

Sorry I cannot find out in your example how to add a description to source and target path variable. I can see how to add constraints on them such as length but no description field that would appear in the openapi specs

from spectree.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.