Skip to content

Commit

Permalink
squashed: oas3 docs and support for multiple servers in oas3 spec
Browse files Browse the repository at this point in the history
* feat: inital new doc supporting oas2 and oas3

* docs: add new images

* fix: support multiple schemas

* docs: add configurations

* docs: add index pages

* docs: update README with OAS3
  • Loading branch information
astagi committed Apr 1, 2021
1 parent 2c731ec commit 4a1b29b
Show file tree
Hide file tree
Showing 42 changed files with 862 additions and 150 deletions.
36 changes: 32 additions & 4 deletions README.md
Expand Up @@ -41,17 +41,17 @@ app.blueprint(swagger_blueprint)
You'll now have a Swagger UI at the URL `/swagger/` and an OpenAPI 2.0 spec at `/swagger/swagger.json`.
Your routes will be automatically categorized by their blueprints.

## Example
## OpenAPI 2

Here is an example to use Sanic-OpenAPI:
Here is an example to use Sanic-OpenAPI 2:

```python
from sanic import Sanic
from sanic.response import json
from sanic_openapi import swagger_blueprint
from sanic_openapi import openapi2_blueprint

app = Sanic(name="AwesomeApi")
app.blueprint(swagger_blueprint)
app.blueprint(openapi2_blueprint)


@app.route("/")
Expand All @@ -67,6 +67,34 @@ if __name__ == "__main__":
And you can get your Swagger document at <http://localhost:8000/swagger> like this:
![](docs/_static/images/hello_world_example.png)

## OpenAPI 3

⚠️ Sanic OpenAPI 3 support is experimental. This feature may be subject to change in future releases.

Here is an example to use Sanic-OpenAPI 3:

```python
from sanic import Sanic
from sanic.response import json
from sanic_openapi import openapi3_blueprint

app = Sanic(name="AwesomeApi")
app.blueprint(openapi3_blueprint)


@app.route("/")
async def test(request):
return json({"hello": "world"})


if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000)

```

And you can get your Swagger document at <http://localhost:8000/swagger> like this:
![](docs/_static/images3/hello_world_example.png)

## Documentation

Please check the documentation on [Readthedocs](https://sanic-openapi.readthedocs.io)
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/images3/blueprint_example.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/images3/configurations/API_HOST.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/images3/decorators/description.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/images3/decorators/produces.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/images3/decorators/sumary.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/images3/decorators/tag.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/images3/hello_world_example.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 3 additions & 34 deletions docs/index.md
Expand Up @@ -21,41 +21,10 @@ Or, use master banch from GitHub with latest features:
pip install git+https://github.com/sanic-org/sanic-openapi.git
```

## Getting Started
## Getting started

Here is an example to use Sanic-OpenAPI:

```python
from sanic import Sanic
from sanic.response import json
from sanic_openapi import swagger_blueprint

app = Sanic()
app.blueprint(swagger_blueprint)


@app.route("/")
async def test(request):
return json({"hello": "world"})


if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000)

```

And you can get your Swagger document at <http://localhost:8000/swagger> like this:
![](_static/images/hello_world_example.png)

## Contents

* [Document Routes](sanic_openapi/document_routes)
* [Configurations](sanic_openapi/configurations)
* [Decorators](sanic_openapi/decorators)
* [Fields](sanic_openapi/fields)
* [API Factory](sanic_openapi/api_factory)
* [Examples](sanic_openapi/examples)
* [API Reference](sanic_openapi/api_reference)
* [Sanic OpenAPI 2](/sanic_openapi2/index)
* [Sanic OpenAPI 3 (Experimental)](/sanic_openapi3/index)

## Indices and tables

Expand Down
Expand Up @@ -3,16 +3,7 @@
## sanic_openapi.doc

```eval_rst
.. automodule:: sanic_openapi.doc
:members:
:undoc-members:
:show-inheritance:
```

## sanic_openapi.swagger

```eval_rst
.. automodule:: sanic_openapi.swagger
.. automodule:: sanic_openapi.openapi2.doc
:members:
:undoc-members:
:show-inheritance:
Expand All @@ -21,7 +12,7 @@
## sanic_openapi.api

```eval_rst
.. automodule:: sanic_openapi.api
.. automodule:: sanic_openapi.openapi2.api
:members:
:undoc-members:
:show-inheritance:
Expand Down
Expand Up @@ -21,10 +21,10 @@ By default, Swagger will use exactly the same host which served itself as the AP

```python
from sanic import Sanic
from sanic_openapi import swagger_blueprint
from sanic_openapi import openapi2_blueprint

app = Sanic()
app.blueprint(swagger_blueprint)
app.blueprint(openapi2_blueprint)
app.config["API_HOST"] = "petstore.swagger.io"

```
Expand All @@ -41,10 +41,10 @@ By default, Swagger will use exactly the same host which served itself as the AP

```python
from sanic import Sanic
from sanic_openapi import swagger_blueprint
from sanic_openapi import openapi2_blueprint

app = Sanic()
app.blueprint(swagger_blueprint)
app.blueprint(openapi2_blueprint)
app.config["API_BASEPATH"] = "/api"

```
Expand All @@ -61,10 +61,10 @@ By default, Swagger will use exactly the same host which served itself as the AP

```python
from sanic import Sanic
from sanic_openapi import swagger_blueprint
from sanic_openapi import openapi2_blueprint

app = Sanic()
app.blueprint(swagger_blueprint)
app.blueprint(openapi2_blueprint)
app.config["API_SCHEMES"] = ["https"]

```
Expand All @@ -86,10 +86,10 @@ For more detail of those additional information, please check the [document](htt

```python
from sanic import Sanic
from sanic_openapi import swagger_blueprint
from sanic_openapi import openapi2_blueprint

app = Sanic()
app.blueprint(swagger_blueprint)
app.blueprint(openapi2_blueprint)
app.config["API_VERSION"] = "0.1.0"

```
Expand All @@ -106,11 +106,11 @@ For more detail of those additional information, please check the [document](htt

```python
from sanic import Sanic
from sanic_openapi import swagger_blueprint
from sanic_openapi import openapi2_blueprint

app = Sanic()
app.blueprint(swagger_blueprint)
app.config["API_TITLE"] = "Sanci-OpenAPI"
app.blueprint(openapi2_blueprint)
app.config["API_TITLE"] = "Sanic-OpenAPI"

```

Expand All @@ -126,10 +126,10 @@ For more detail of those additional information, please check the [document](htt

```python
from sanic import Sanic
from sanic_openapi import swagger_blueprint
from sanic_openapi import openapi2_blueprint

app = Sanic()
app.blueprint(swagger_blueprint)
app.blueprint(openapi2_blueprint)
app.config["API_DESCRIPTION"] = "An example Swagger from Sanic-OpenAPI"

```
Expand All @@ -146,10 +146,10 @@ For more detail of those additional information, please check the [document](htt

```python
from sanic import Sanic
from sanic_openapi import swagger_blueprint
from sanic_openapi import openapi2_blueprint

app = Sanic()
app.blueprint(swagger_blueprint)
app.blueprint(openapi2_blueprint)
app.config["API_TERMS_OF_SERVICE"] = "https://github.com/sanic-org/sanic-openapi/blob/master/README.md"

```
Expand All @@ -166,10 +166,10 @@ For more detail of those additional information, please check the [document](htt

```python
from sanic import Sanic
from sanic_openapi import swagger_blueprint
from sanic_openapi import openapi2_blueprint

app = Sanic()
app.blueprint(swagger_blueprint)
app.blueprint(openapi2_blueprint)
app.config["API_CONTACT_EMAIL"] = "foo@bar.com"

```
Expand All @@ -186,10 +186,10 @@ For more detail of those additional information, please check the [document](htt

python
from sanic import Sanic
from sanic_openapi import swagger_blueprint
from sanic_openapi import openapi2_blueprint

app = Sanic()
app.blueprint(swagger_blueprint)
app.blueprint(openapi2_blueprint)
app.config["API_LICENSE_NAME"] = "MIT"


Expand All @@ -206,10 +206,10 @@ For more detail of those additional information, please check the [document](htt

```python
from sanic import Sanic
from sanic_openapi import swagger_blueprint
from sanic_openapi import openapi2_blueprint

app = Sanic()
app.blueprint(swagger_blueprint)
app.blueprint(openapi2_blueprint)
app.config["API_LICENSE_URL"] = "https://github.com/sanic-org/sanic-openapi/blob/master/LICENSE"

```
Expand All @@ -229,10 +229,10 @@ If your API have to access with authentication, Swagger can provide related conf
from sanic import Sanic
from sanic.response import json

from sanic_openapi import swagger_blueprint
from sanic_openapi import openapi2_blueprint

app = Sanic()
app.blueprint(swagger_blueprint)
app.blueprint(openapi2_blueprint)
app.config["API_SECURITY"] = [{"BasicAuth": []}]
app.config["API_SECURITY_DEFINITIONS"] = {"BasicAuth": {"type": "basic"}}

Expand All @@ -257,10 +257,10 @@ If your API have to access with authentication, Swagger can provide related conf
from sanic import Sanic
from sanic.response import json

from sanic_openapi import swagger_blueprint
from sanic_openapi import openapi2_blueprint

app = Sanic()
app.blueprint(swagger_blueprint)
app.blueprint(openapi2_blueprint)
app.config["API_SECURITY"] = [{"ApiKeyAuth": []}]
app.config["API_SECURITY_DEFINITIONS"] = {
"ApiKeyAuth": {"type": "apiKey", "in": "header", "name": "X-API-KEY"}
Expand All @@ -284,10 +284,10 @@ If your API have to access with authentication, Swagger can provide related conf
from sanic import Sanic
from sanic.response import json

from sanic_openapi import swagger_blueprint
from sanic_openapi import openapi2_blueprint

app = Sanic()
app.blueprint(swagger_blueprint)
app.blueprint(openapi2_blueprint)
app.config["API_SECURITY"] = [{"ApiKeyAuth": []}]
app.config["API_SECURITY_DEFINITIONS"] = {
"ApiKeyAuth": {"type": "apiKey", "in": "query", "name": "api_key"}
Expand All @@ -312,10 +312,10 @@ If your API have to access with authentication, Swagger can provide related conf
from sanic import Sanic
from sanic.response import json

from sanic_openapi import swagger_blueprint
from sanic_openapi import openapi2_blueprint

app = Sanic()
app.blueprint(swagger_blueprint)
app.blueprint(openapi2_blueprint)
app.config["API_SECURITY"] = [{"OAuth2": []}]
app.config["API_SECURITY_DEFINITIONS"] = {
"OAuth2": {
Expand Down Expand Up @@ -347,10 +347,10 @@ By default, Sanic registers URIs both with and without a trailing `/`. You may s
from sanic import Sanic
from sanic.response import json

from sanic_openapi import swagger_blueprint
from sanic_openapi import openapi2_blueprint

app = Sanic()
app.blueprint(swagger_blueprint)
app.blueprint(openapi2_blueprint)


@app.get("/test")
Expand All @@ -370,10 +370,10 @@ By default, Sanic registers URIs both with and without a trailing `/`. You may s
from sanic import Sanic
from sanic.response import json

from sanic_openapi import swagger_blueprint
from sanic_openapi import openapi2_blueprint

app = Sanic()
app.blueprint(swagger_blueprint)
app.blueprint(openapi2_blueprint)
app.config["API_URI_FILTER"] = "slash"


Expand All @@ -394,10 +394,10 @@ By default, Sanic registers URIs both with and without a trailing `/`. You may s
from sanic import Sanic
from sanic.response import json

from sanic_openapi import swagger_blueprint
from sanic_openapi import openapi2_blueprint

app = Sanic()
app.blueprint(swagger_blueprint)
app.blueprint(openapi2_blueprint)
app.config["API_URI_FILTER"] = "all"


Expand Down

0 comments on commit 4a1b29b

Please sign in to comment.