Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def check_web_framework_and_marshmallow_plugin(web_framework_plugin, **kwargs_for_add_path):
"""Check schemas passed in web framework view function docstring are parsed by MarshmallowPlugin"""
spec = APISpec(
title='Swagger Petstore',
version='1.0.0',
plugins=[web_framework_plugin(), MarshmallowPlugin()],
openapi_version='2.0',
)
spec.add_path(**kwargs_for_add_path)
expected = {
'type': 'object',
'properties': {
'id': {'type': 'integer', 'format': 'int32', 'description': 'Pet id', 'readOnly': True},
'name': {'type': 'string', 'description': 'Pet name'},
},
'required': ['name'],
}
assert spec.to_dict()['paths']['/hello']['get']['responses'][200]['schema'] == expected
def test_schema_uses_ref_if_available_name_resolver_returns_none_v2(self):
def resolver(schema):
return None
spec = APISpec(
title="Test auto-reference",
version="0.1",
openapi_version="2.0",
plugins=(MarshmallowPlugin(schema_name_resolver=resolver),),
)
spec.components.schema("Pet", schema=PetSchema)
spec.path(
path="/pet", operations={"get": {"responses": {200: {"schema": PetSchema}}}}
)
get = get_paths(spec)["/pet"]["get"]
assert get["responses"]["200"]["schema"] == build_ref(spec, "schema", "Pet")
def test_resolve_schema_dict_auto_reference(self, schema):
def resolver(schema):
schema_cls = common.resolve_schema_cls(schema)
return schema_cls.__name__
spec = APISpec(
title="Test auto-reference",
version="0.1",
openapi_version="2.0",
plugins=(MarshmallowPlugin(schema_name_resolver=resolver),),
)
with pytest.raises(KeyError):
get_schemas(spec)
spec.components.schema("analysis", schema=schema)
spec.path(
"/test",
operations={
"get": {
"responses": {
"200": {"schema": build_ref(spec, "schema", "analysis")}
}
}
},
)
definitions = get_schemas(spec)
def make_apispec(title='flask-apispec', version='v1'):
return APISpec(
title=title,
version=version,
plugins=[MarshmallowPlugin()],
)
def _create_api_spec(version):
return APISpec(
title=current_app.appbuilder.app_name,
version=version,
openapi_version="3.0.2",
info=dict(description=current_app.appbuilder.app_name),
plugins=[MarshmallowPlugin()],
servers=[{'url': "/api/{}".format(version)}]
)
def __init__(self, aiohttp_app):
self.aiohttp_app = aiohttp_app
self.apispec = apispec.APISpec(
title='Caldera API',
version=self.get_version(),
openapi_version='3.0.2',
plugins=[MarshmallowPlugin()],
)
description: ""
operationId: "api_spec"
consumes:
- "application/json"
produces:
- "application/json"
parameters:
responses:
200:
description: "Success"
"""
spec = APISpec(
title="Channelstream API",
version="0.7.0",
openapi_version="2.0.0",
plugins=(MarshmallowPlugin(),),
)
spec.components.schema("ConnectBody", schema=schemas.ConnectBodySchema)
spec.components.schema("SubscribeBody", schema=schemas.SubscribeBodySchema)
spec.components.schema("UnsubscribeBody", schema=schemas.UnsubscribeBodySchema)
spec.components.schema("UserStateBody", schema=schemas.UserStateBodySchema)
spec.components.schema(
"MessagesBody", schema=schemas.MessageBodySchema(many=True)
)
spec.components.schema("MessageBody", schema=schemas.MessageBodySchema())
spec.components.schema(
"MessageEditBody", schema=schemas.MessageEditBodySchema(many=True)
)
spec.components.schema(
"MessagesDeleteBody", schema=schemas.MessagesDeleteBodySchema(many=True)
)
spec.components.schema("DisconnectBody", schema=schemas.DisconnectBodySchema)
from collections import defaultdict
from apispec.ext.flask import FlaskPlugin
from apispec.ext.marshmallow import MarshmallowPlugin
import flask
from .operation import Operation
# -----------------------------------------------------------------------------
RESTY_PLUGIN_NAME = 'resty'
# -----------------------------------------------------------------------------
class FlaskRestyPlugin(MarshmallowPlugin):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._rules = {
rule.rule: rule for rule in flask.current_app.url_map.iter_rules()
}
def path_helper(self, path, view, **kwargs):
"""Path helper for Flask-RESTy views.
:param view: An `ApiView` object.
"""
super().path_helper(
path=path,
view=view,
**kwargs