Skip to content

FerdinaKusumah/sanic_simple_swagger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sanic OpenAPI (This project is Deprecated)

No longer supported

Real project in https://github.com/huge-success/sanic-openapi

This project just extends functional and fix some bugs Example Swagger UI

Installation

    pip install sanic-simple-swagger

Add OpenAPI and Swagger UI:

    from sanic_simple_swagger import swagger_blueprint, openapi_blueprint
    
    app.blueprint(openapi_blueprint)
    app.blueprint(swagger_blueprint)

You'll now have a Swagger UI at the URL /swagger/index.html.

Your routes will be automatically categorized by their blueprints.

Example

from sanic_simple_swagger import doc

class Student:
    name = str
    address = str

@student.get('/student', strict_slashes=True)
@doc.summary("Show resource")
@doc.description("Display a listing of the resource.")
@doc.deprecated(True) #if the api is deprecated
@doc.produces(content_type='application/json')
@doc.consumes({'name': str}, location='query', description='Student name', example={'name': 'john'})
async def index(request):
    ...

@student.post('/student', strict_slashes=True)
@doc.summary("Create resource")
@doc.description("Store a newly created resource in storage.")
@doc.consumes(Student, location='body' required=True)
@doc.response_success(status=201, description='If successful created')
async def store(request):
    ...

@student.put('/student/<id>', strict_slashes=True)
@doc.summary("Update resource")
@doc.description("Update the specified resource in storage.")
@doc.response_success(status=201, description='If successful updated')
async def update(request, id):
    ...

@student.delete('/student/<id>', strict_slashes=True)
@doc.summary("Remove resource")
@doc.description("Remove the specified resource from storage.")
@doc.response_success(status=201, description='If successful deleted')
async def delete(request, id):
    ...

Configure all the things

app.config['API_VERSION'] = '1.0.0'
app.config['API_TITLE'] = 'Swagger student API'
app.config['API_DESCRIPTION'] = 'This is a sample server Student api.'
app.config['API_TERMS_OF_SERVICE'] = ...
app.config['API_CONTACT_EMAIL'] = ...
app.config['API_LICENSE_NAME'] = 'Apache 2.0'
app.config['API_LICENSE_URL'] = 'http://www.apache.org/licenses/LICENSE-2.0.html'
app.config['schemes'] = ['http', 'https']

Reference

  1. Sanic
  2. Sanic OpenAPI

About

Swagger Documentation for Python sanic

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy