File: header_demo.py

package info (click to toggle)
flask-openapi3 4.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,976 kB
  • sloc: python: 4,754; sh: 17; makefile: 15; javascript: 5
file content (30 lines) | stat: -rw-r--r-- 773 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# -*- coding: utf-8 -*-
# @Author  : llc
# @Time    : 2021/12/26 15:07

from pydantic import BaseModel, Field

from flask_openapi3 import Info, Tag
from flask_openapi3 import OpenAPI

info = Info(title='header API', version='1.0.0')
app = OpenAPI(__name__, info=info)

book_tag = Tag(name='book', description='Some Book')


class Headers(BaseModel):
    hello: str = Field("what's up", max_length=12, description='sds')
    # required
    # hello: str = Field(..., max_length=12, description='sds')
    x_hello: str = Field(..., max_length=12, description='Header with alias to support dash', alias="x-hello")


@app.get('/book', tags=[book_tag])
def get_book(header: Headers):
    print(header)
    return header.hello


if __name__ == '__main__':
    app.run(debug=True)