-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
squashed: oas2/oas3 fixes, cleanup, docs,
* fix(oas2): encourage better swagger2 spec without user configuration by setting required-by-spec defaults * clean: start to make oas2 blueprint.py and oas3 blueprint.py share behaviour * fix(oas3): adjust typo during original implementation that might mess up class based view * clean: remove deprecated/invalid dockerfile * feat: add types sto openapi * feat: add OS related section to .gitignore * fix: use Any for Array items * build: fix broken tox conf * loosen pyyaml requirement * feat: add oas3 example * docs: huge-success -> sanic-org * fix: oas3 spec fixes * style * update setup.py classifiers * dont set optional field operationId with bad value * fix: use SecurityScheme * wip: refactor routing parsing logic out of blueprint generation func * Revert "fix: use SecurityScheme" This reverts commit c815b71. * mark secured notimplemented * style Co-authored-by: artcg <arthurgoldbergfwd@gmail.com>
- Loading branch information
Showing
36 changed files
with
622 additions
and
504 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
## Cars | ||
|
||
[Source](https://github.com/sanic-org/sanic-openapi/tree/master/examples/cars) | ||
|
||
This example shows how to use Sanic-OpenAPI with Sanic's Blueprint and model all the data into Sanic-OpenAPI's fields. | ||
|
||
To run this example, please make sure you have already install `sanic` and `sanic-openapi`. | ||
Or, run the install command: | ||
|
||
```shell | ||
pip install sanic sanic-openapi | ||
``` | ||
|
||
And, you can run this example by: | ||
|
||
```shell | ||
python main.py | ||
``` | ||
|
||
Now, check <http://localhost:8000/swagger> and you should see the swagger like: | ||
![](./swagger.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from data import test_car, test_success | ||
from models import Car, Status | ||
from sanic.blueprints import Blueprint | ||
from sanic.response import json | ||
|
||
from sanic_openapi import openapi | ||
|
||
blueprint = Blueprint('Car', '/car') | ||
|
||
|
||
@blueprint.get("/", strict_slashes=True) | ||
@openapi.summary("Fetches all cars") | ||
@openapi.description("Really gets the job done fetching these cars. I mean, really, wow.") | ||
@openapi.response(200, {"application/json" : [Car]}) | ||
def car_list(request): | ||
return json([test_car]) | ||
|
||
|
||
@blueprint.get("/<car_id:int>", strict_slashes=True) | ||
@openapi.summary("Fetches a car") | ||
@openapi.response(200, {"application/json" : Car}) | ||
def car_get(request, car_id): | ||
return json(test_car) | ||
|
||
|
||
@blueprint.put("/<car_id:int>", strict_slashes=True) | ||
@openapi.summary("Updates a car") | ||
@openapi.body( | ||
{ "application/json" : Car }, | ||
description="Body description", | ||
required=True, | ||
) | ||
@openapi.parameter("AUTHORIZATION", str, location="header") | ||
@openapi.response(200, {"application/json" : Car}) | ||
def car_put(request, car_id): | ||
return json(test_car) | ||
|
||
|
||
@blueprint.delete("/<car_id:int>", strict_slashes=True) | ||
@openapi.summary("Deletes a car") | ||
@openapi.response(204, {"application/json" : Status}) | ||
def car_delete(request, car_id): | ||
return json(test_success) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import json | ||
|
||
from data import test_driver, test_success | ||
from models import Driver, Status | ||
from sanic.blueprints import Blueprint | ||
from sanic.response import json | ||
|
||
from sanic_openapi import openapi | ||
|
||
blueprint = Blueprint('Driver', '/driver') | ||
|
||
|
||
@blueprint.get("/", strict_slashes=True) | ||
@openapi.summary("Fetches all drivers") | ||
@openapi.response(200, {"application/json" : [Driver]}) | ||
def driver_list(request): | ||
return json([test_driver]) | ||
|
||
|
||
@blueprint.get("/<driver_id:int>", strict_slashes=True) | ||
@openapi.summary("Fetches a driver") | ||
@openapi.response(200, {"application/json" : Driver}) | ||
def driver_get(request, driver_id): | ||
return json(test_driver) | ||
|
||
|
||
@blueprint.put("/<driver_id:int>", strict_slashes=True) | ||
@openapi.summary("Updates a driver") | ||
@openapi.body( | ||
{ "application/json" : Driver }, | ||
description="Body description", | ||
required=True, | ||
) | ||
@openapi.response(200, {"application/json" : Driver}) | ||
def driver_put(request, driver_id): | ||
return json(test_driver) | ||
|
||
|
||
@blueprint.delete("/<driver_id:int>", strict_slashes=True) | ||
@openapi.summary("Deletes a driver") | ||
@openapi.response(204, {"application/json" : Status}) | ||
def driver_delete(request, driver_id): | ||
return json(test_success) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import json | ||
|
||
from data import test_garage, test_success | ||
from models import Car, Garage, Status | ||
from sanic.blueprints import Blueprint | ||
from sanic.response import json | ||
|
||
from sanic_openapi import openapi | ||
|
||
blueprint = Blueprint('Garage', '/garage') | ||
|
||
|
||
@blueprint.get("/", strict_slashes=True) | ||
@openapi.summary("Fetches the garage") | ||
@openapi.response(200, {"application/json" : Garage}) | ||
async def get_garage(request): | ||
return json(test_garage) | ||
|
||
|
||
@blueprint.get("/cars", strict_slashes=True) | ||
@openapi.summary("Fetches the cars in the garage") | ||
@openapi.body( | ||
{ "application/json" : {"doors": int} }, | ||
description="Body description", | ||
required=True, | ||
) | ||
@openapi.response(200, {"application/json" : {"cars": [Car]}}) | ||
async def get_cars(request): | ||
return json(test_garage.get('cars')) | ||
|
||
|
||
@blueprint.put("/car", strict_slashes=True) | ||
@openapi.summary("Adds a car to the garage") | ||
@openapi.body( | ||
{ "application/json" : Car }, | ||
description="Body description", | ||
required=True, | ||
) | ||
@openapi.response(204, {"application/json" : Status}) | ||
async def add_car(request): | ||
return json(test_success) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from data import test_manufacturer, test_success | ||
from models import Driver, Status | ||
from sanic.blueprints import Blueprint | ||
from sanic.response import json | ||
|
||
from sanic_openapi import openapi | ||
|
||
blueprint = Blueprint('Manufacturer', '/manufacturer') | ||
|
||
|
||
@blueprint.get("/", strict_slashes=True) | ||
@openapi.summary("Fetches all manufacturers") | ||
@openapi.response(200, {"application/json" : [Driver]}) | ||
def manufacturer_list(request): | ||
return json([test_manufacturer]) | ||
|
||
|
||
@blueprint.get("/<manufacturer_id:int>", strict_slashes=True) | ||
@openapi.summary("Fetches a manufacturer") | ||
@openapi.response(200, {"application/json" : Driver}) | ||
def manufacturer_get(request, manufacturer_id): | ||
return json(test_manufacturer) | ||
|
||
|
||
@blueprint.put("/<manufacturer_id:int>", strict_slashes=True) | ||
@openapi.summary("Updates a manufacturer") | ||
@openapi.body( | ||
{ "application/json" : Driver }, | ||
description="Body description", | ||
required=True, | ||
) | ||
@openapi.response(200, {"application/json" : Driver}) | ||
def manufacturer_put(request, manufacturer_id): | ||
return json(test_manufacturer) | ||
|
||
|
||
@blueprint.delete("/<manufacturer_id:int>", strict_slashes=True) | ||
@openapi.summary("Deletes a manufacturer") | ||
@openapi.response(200, {"application/json" : Status}) | ||
def manufacturer_delete(request, manufacturer_id): | ||
return json(test_success) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from sanic.blueprints import Blueprint | ||
from sanic.response import json | ||
from sanic.views import HTTPMethodView | ||
|
||
from sanic_openapi import openapi | ||
|
||
blueprint = Blueprint('Repair', '/repair') | ||
from data import test_station | ||
from models import Station | ||
|
||
|
||
class RepairStation(HTTPMethodView): | ||
@openapi.summary("Fetches all repair stations") | ||
@openapi.response(200, {"application/json" : [Station]}) | ||
def get(self, request): | ||
return json([test_station]) | ||
|
||
@openapi.summary("make an appointment") | ||
@openapi.description("submit necessary information for appointment") | ||
def post(self, request): | ||
return json(request.json) | ||
|
||
|
||
blueprint.add_route(RepairStation.as_view(), "/station", strict_slashes=True) |
Oops, something went wrong.