Esempio n. 1
0
    def init_swagger(self):
        # only initialize once
        if self._doc:
            return

        info_block = swagger.Info(title=self.api_title, version=self.api_version)
        if "API_LICENSE_NAME" in self.config:
            license_block = swagger.License(
                name=self.config["API_LICENSE_NAME"],
                url=self.config.get("API_LICENSE_URL"),
            )
            info_block.license = license_block
        if "API_CONTACT_NAME" in self.config:
            contact_block = swagger.Contact(name=self.config["API_CONTACT_NAME"])
            contact_block.email = self.config.get("API_CONTACT_EMAIL")
            contact_block.url = self.config.get("API_CONTACT_URL")
            info_block.contact = contact_block

        self._doc = swagger.OpenApi(
            version=self.open_api_version,
            info=info_block,
            paths=swagger.Paths(),
        )
        self.add_url_rule("/openapi.json", view_func=self.register_json_path, methods=["GET"])
        self.add_url_rule("/openapi.yaml", view_func=self.register_yaml_path, methods=["GET"])
Esempio n. 2
0
                type="string",
                format="email",
            ),
        ),
        swagger.QueryParameter(name="age",
                               description="age of user",
                               schema=swagger.Integer()),
    ],
    responses={"200": swagger.ResponseObject(description="Echos whatever")},
)

info = swagger.Info(
    title="Test",
    version="1.2.2",
    contact=swagger.Contact(name="nuke",
                            email="*****@*****.**",
                            url="https://github.com/kulgan"),
    license=swagger.License(name="Apache 2.0",
                            url="https://www.example.com/license"),
)

tags = [
    swagger.Tag(name="getEcho",
                description="gets echos no matter where they are hiding"),
    swagger.Tag(name="postEcho",
                description="posts echos to hidden locations"),
]

servers = [
    swagger.Server(
        url="https://{sample}.sample/com",
Esempio n. 3
0
import flask

from flaskdoc import jo, swagger

blp = flask.Blueprint("inventory", __name__, url_prefix="/inventory")
info = swagger.Info(
    title="Test",
    version="1.2.2",
    contact=swagger.Contact(name="Rowland",
                            email="r.ogra@daemonmailer"
                            "+++.com",
                            url="https://github.com/kulgan"),
    license=swagger.License(name="Apache 2.0",
                            url="https://www.example.com/license"),
)
servers = [swagger.Server(url="http://localhost:15172")]
tags = [
    swagger.Tag(name="admin", description="Secured Admin-Only calls"),
    swagger.Tag(name="developers",
                description="Operations available to regular developers"),
]


@jo.schema()
class Manufacturer(object):
    name = jo.string(example="ACME Corporation", required=True)
    phone = jo.string(example="408-867-5309")
    homepage = jo.string(str_format="url", example="https://www.acme-corp.com")


@jo.schema(camel_case_props=True)
Esempio n. 4
0
    update_pet_spec,
    update_user_spec,
    upload_image_spec,
)

pet = flask.Blueprint("pet", __name__, url_prefix="/pet")
store = flask.Blueprint("store", __name__, url_prefix="/store")
user = flask.Blueprint("user", __name__, url_prefix="/user")
info = swagger.Info(
    title="Swagger Petstore",
    version="1.0.5",
    description="This is a sample server Petstore server.  You can find out more about Swagger at ["
    "http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger]("
    "http://swagger.io/irc/).  For this sample, you can use the api key `special-key` to test the "
    "authorization filters.",
    contact=swagger.Contact(
        email="*****@*****.**",
    ),
    license=swagger.License(
        name="Apache 2.0",
        url="http://www.apache.org/licenses/LICENSE-2.0.html",
    ),
    terms_of_service="http://swagger.io/terms/",
)
external_docs = swagger.ExternalDocumentation(
    description="Find out more about Swagger", url="http://swagger.io"
)
servers = [
    swagger.Server(url="https://petstore.swagger.io/v2"),
    swagger.Server(url="http://petstore.swagger.io/v2"),
]
tags = [
Esempio n. 5
0
import flask

from flaskdoc import swagger

api = flask.Blueprint("api-examples",
                      __name__,
                      url_prefix="/api-with-examples")

info = swagger.Info(title="Simple API Overview", version="2.0.0")

examples = {
    "foo":
    swagger.Example(
        value={
            "versions": [
                {
                    "status":
                    "CURRENT",
                    "updated":
                    "2011-01-21T11:33:21Z",
                    "id":
                    "v2.0",
                    "links": [{
                        "href": "http://127.0.0.1:8774/v2/",
                        "rel": "self"
                    }],
                },
                {
                    "status":
                    "EXPERIMENTAL",
                    "updated":
Esempio n. 6
0
import flask

from flaskdoc import swagger
from flaskdoc.examples.link_example import specs

api = flask.Blueprint("link-example", __name__, url_prefix="/link-example")

info = swagger.Info(title="Link Example", version="1.0.0")

links = {
    "UserRepositories":
    swagger.Link(operation_id="getRepositoriesByName",
                 parameters={"username": "******"}),
    "UserRepository":
    swagger.Link(
        operation_id="getRepository",
        parameters={
            "username": "******",
            "slug": "$response.body#/slug"
        },
    ),
    "RepositoryPullRequests":
    swagger.Link(
        operation_id="getPullRequestByRepository",
        parameters={
            "username": "******",
            "slug": "$response.body#/slug"
        },
    ),
    "PullRequestMerge":
    swagger.Link(