本文整理汇总了Python中apispec.APISpec方法的典型用法代码示例。如果您正苦于以下问题:Python apispec.APISpec方法的具体用法?Python apispec.APISpec怎么用?Python apispec.APISpec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apispec
的用法示例。
在下文中一共展示了apispec.APISpec方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_query_schema
# 需要导入模块: import apispec [as 别名]
# 或者: from apispec import APISpec [as 别名]
def get_query_schema() -> dict:
"""
Get a dictionary representation of the FlowmachineQuerySchema api spec.
This will contain a schema which defines all valid query types that can be run.
Returns
-------
dict
"""
spec = APISpec(
title="FlowAPI",
version="1.0.0",
openapi_version="3.0.2",
plugins=[MarshmallowPlugin()],
)
spec.components.schema("FlowmachineQuerySchema", schema=FlowmachineQuerySchema)
return spec.to_dict()["components"]["schemas"]
示例2: make_apispec
# 需要导入模块: import apispec [as 别名]
# 或者: from apispec import APISpec [as 别名]
def make_apispec(title='flask-apispec', version='v1', openapi_version='2.0'):
return APISpec(
title=title,
version=version,
openapi_version=openapi_version,
plugins=[MarshmallowPlugin()],
)
示例3: spec
# 需要导入模块: import apispec [as 别名]
# 或者: from apispec import APISpec [as 别名]
def spec(marshmallow_plugin):
return APISpec(
title='title',
version='v1',
openapi_version='2.0',
plugins=[marshmallow_plugin],
)
示例4: test_error_if_spec_does_not_have_marshmallow_plugin
# 需要导入模块: import apispec [as 别名]
# 或者: from apispec import APISpec [as 别名]
def test_error_if_spec_does_not_have_marshmallow_plugin(app):
bad_spec = APISpec(
title='title',
version='v1',
openapi_version='2.0',
plugins=[], # oh no! no MarshmallowPlugin
)
with pytest.raises(RuntimeError):
ViewConverter(app=app, spec=bad_spec)
with pytest.raises(RuntimeError):
ResourceConverter(app=app, spec=bad_spec)
示例5: init_app
# 需要导入模块: import apispec [as 别名]
# 或者: from apispec import APISpec [as 别名]
def init_app(self, app, **kwargs):
app.config.setdefault("APISPEC_TITLE", "{{cookiecutter.project_name}}")
app.config.setdefault("APISPEC_VERSION", "1.0.0")
app.config.setdefault("OPENAPI_VERSION", "3.0.2")
app.config.setdefault("SWAGGER_JSON_URL", "/swagger.json")
app.config.setdefault("SWAGGER_UI_URL", "/swagger-ui")
app.config.setdefault("SWAGGER_URL_PREFIX", None)
self.spec = APISpec(
title=app.config["APISPEC_TITLE"],
version=app.config["APISPEC_VERSION"],
openapi_version=app.config["OPENAPI_VERSION"],
plugins=[MarshmallowPlugin(), FlaskRestfulPlugin()],
**kwargs
)
blueprint = Blueprint(
"swagger",
__name__,
template_folder="./templates",
url_prefix=app.config["SWAGGER_URL_PREFIX"],
)
blueprint.add_url_rule(
app.config["SWAGGER_JSON_URL"], "swagger_json", self.swagger_json
)
blueprint.add_url_rule(
app.config["SWAGGER_UI_URL"], "swagger_ui", self.swagger_ui
)
app.register_blueprint(blueprint)
示例6: spec
# 需要导入模块: import apispec [as 别名]
# 或者: from apispec import APISpec [as 别名]
def spec(request):
return APISpec(
title="Swagger Petstore",
version="1.0.0",
openapi_version=request.param,
plugins=(TornadoPlugin(),),
)
示例7: spec
# 需要导入模块: import apispec [as 别名]
# 或者: from apispec import APISpec [as 别名]
def spec(request):
return APISpec(
title="Swagger Petstore",
version="1.0.0",
openapi_version=request.param,
plugins=(FlaskPlugin(),),
)
示例8: spec
# 需要导入模块: import apispec [as 别名]
# 或者: from apispec import APISpec [as 别名]
def spec(request):
return APISpec(
title="Swagger Petstore",
version="1.0.0",
openapi_version=request.param,
plugins=(BottlePlugin(),),
)
示例9: init_spec
# 需要导入模块: import apispec [as 别名]
# 或者: from apispec import APISpec [as 别名]
def init_spec(self, spec: APISpec):
super().init_spec(spec)
self.spec = spec
示例10: spec_factory
# 需要导入模块: import apispec [as 别名]
# 或者: from apispec import APISpec [as 别名]
def spec_factory():
def _spec(app):
return APISpec(
title="Swagger Petstore",
version="1.0.0",
openapi_version="3.0.2",
description="This is a sample Petstore server. You can find out "
'more about Swagger at <a href="https://swagger.io"> '
"http://swagger.wordnik.com</a> or on irc.freenode.net, #swagger."
'For this sample, you can use the api key "special-key" to test '
"the authorization filters",
plugins=[FalconPlugin(app)],
)
return _spec
示例11: __init__
# 需要导入模块: import apispec [as 别名]
# 或者: from apispec import APISpec [as 别名]
def __init__(self, api_root):
self.api_root = api_root
self.api_map = defaultdict(dict)
self.funcs = defaultdict(dict)
self.curr_tag = ''
self.spec = APISpec(
title='Webrecorder',
version='1.0.0',
openapi_version='3.0.0',
info=dict(
description='Webrecorder API. This API includes all features available and in use by the frontend.'
),
plugins=[]
)
self.admin_spec = APISpec(
title='Webrecorder',
version='1.0.0',
openapi_version='3.0.0',
info=dict(
description='Webrecorder API (including Admin). This API includes all features available in Webrecorder, including admin and stats APIs.'
),
plugins=[]
)
self.err_400 = self.make_err_response('Invalid Request Param')
self.err_404 = self.make_err_response('Object Not Found')
self.err_403 = self.make_err_response('Invalid Authorization')
self.any_obj = self.make_any_response()
示例12: add_apispec_components
# 需要导入模块: import apispec [as 别名]
# 或者: from apispec import APISpec [as 别名]
def add_apispec_components(self, api_spec: APISpec) -> None:
for schema in self.openapi_spec_component_schemas:
api_spec.components.schema(
schema.__name__, schema=schema,
)
super().add_apispec_components(api_spec)
示例13: __init__
# 需要导入模块: import apispec [as 别名]
# 或者: from apispec import APISpec [as 别名]
def __init__(
self,
url="/api/docs/swagger.json",
app=None,
request_data_name="data",
swagger_path=None,
static_path='/static/swagger',
error_callback=None,
in_place=False,
prefix='',
schema_name_resolver=resolver,
**kwargs
):
self.plugin = MarshmallowPlugin(schema_name_resolver=schema_name_resolver)
self.spec = APISpec(plugins=(self.plugin,), openapi_version="2.0", **kwargs)
self.url = url
self.swagger_path = swagger_path
self.static_path = static_path
self._registered = False
self._request_data_name = request_data_name
self.error_callback = error_callback
self.prefix = prefix
self._index_page = None
if app is not None:
self.register(app, in_place)
示例14: _init_spec
# 需要导入模块: import apispec [as 别名]
# 或者: from apispec import APISpec [as 别名]
def _init_spec(
self, *, flask_plugin=None, marshmallow_plugin=None,
extra_plugins=None, openapi_version=None, **options
):
# Plugins
self.flask_plugin = flask_plugin or FlaskPlugin()
self.ma_plugin = marshmallow_plugin or MarshmallowPlugin()
plugins = [self.flask_plugin, self.ma_plugin]
plugins.extend(extra_plugins or ())
# APISpec options
openapi_version = self._app.config.get(
'OPENAPI_VERSION', openapi_version)
if openapi_version is None:
raise OpenAPIVersionNotSpecified(
'The OpenAPI version must be specified, either as '
'"OPENAPI_VERSION" app parameter or as '
'"openapi_version" spec kwarg.')
openapi_major_version = int(openapi_version.split('.')[0])
if openapi_major_version < 3:
base_path = self._app.config.get('APPLICATION_ROOT')
options.setdefault('basePath', base_path)
options.setdefault(
'produces', [DEFAULT_RESPONSE_CONTENT_TYPE, ])
options.setdefault(
'consumes', [DEFAULT_REQUEST_BODY_CONTENT_TYPE, ])
options.update(self._app.config.get('API_SPEC_OPTIONS', {}))
# Instantiate spec
self.spec = apispec.APISpec(
self._app.name,
self._app.config.get('API_VERSION', '1'),
openapi_version=openapi_version,
plugins=plugins,
**options,
)
# Register custom fields in spec
for args in self._fields:
self._register_field(*args)
# Register custom converters in spec
for args in self._converters:
self._register_converter(*args)
# Register Upload field properties function
self.ma_plugin.converter.add_attribute_function(uploadfield2properties)
# Register OpenAPI command group
self._app.cli.add_command(openapi_cli)