-
Notifications
You must be signed in to change notification settings - Fork 0
New DTO
Marc Szymkowiak edited this page Feb 7, 2022
·
1 revision
-
Add a new file
book.py
toapp/dto
and add the following code: -
Import Namespace and fields from flask_restx
from flask_restx import Namespace, fields
-
Add new class for book dto
class BookDto: """The book dto"""
-
Add new namespace for book api and create api(namespace) object
- The namespace value (here book) correspond to the url namespace later (for example http://example.com/book/)
- The description is shown in the swagger ui
api = Namespace("book", description="book related operations")
-
create book model object
- Descripes the name of the json key
- Descripes the datatype of the value
- Descripes if its required or not
- Description for the swagger api
book = api.model( "book", { "isbn": fields.String(required=True, description="book isbn"), "title": fields.String(required=True, description="book title"), "author": fields.String(required=True, description="book author"), }, )
from flask_restx import Namespace, fields
class BookDto:
"""The book dto"""
api = Namespace("book", description="book related operations")
book = api.model(
"book",
{
"isbn": fields.String(required=True, description="book isbn"),
"title": fields.String(required=True, description="book title"),
"author": fields.String(required=True, description="book author"),
},
)