Beispiel #1
0
def _register_method(app, interface, method_name, signature):
    swag = swag_from(create_spec(method_name, signature))
    executor_function = swag(create_executor_function(interface, method_name))
    app.add_url_rule('/' + method_name,
                     method_name,
                     executor_function,
                     methods=['POST'])
Beispiel #2
0
def test_create_spec__no_file():
    field = Field('field', int, False)
    spec = create_spec('mymethod', Signature([field], field))

    assert spec == {
        "summary": "Calls 'mymethod' method on model",
        'requestBody': {
            'required': True,
            "content": {
                "application/json": {
                    'schema': {
                        'type': 'object',
                        'properties': {
                            'field': {
                                'type': 'integer'
                            }
                        }
                    }
                }
            }
        },
        'responses': {
            '200': {
                'description': 'successful response',
                "content": {
                    "application/json": {
                        'schema': {
                            'type': 'object',
                            'properties': {
                                'data': {
                                    'type': 'integer'
                                },
                                'ok': {
                                    'type': 'boolean'
                                }
                            }
                        }
                    }
                }
            },
            '400': {
                'description': 'incorrect request',
                "content": {
                    "application/json": {
                        'schema': {
                            'type': 'object',
                            'properties': {
                                'error': {
                                    'type': 'string'
                                },
                                'ok': {
                                    'type': 'boolean'
                                }
                            }
                        }
                    }
                }
            }
        }
    }
Beispiel #3
0
def _register_method(app, interface, method_name, signature):
    spec = create_spec(method_name, signature)

    executor_function = create_executor_function(interface, method_name, spec)
    swag = swag_from(spec, validation=VALIDATE)
    executor_function = swag(executor_function)

    app.add_url_rule('/' + method_name, method_name, executor_function, methods=['POST'])
Beispiel #4
0
def create_interface_routes(app, interface: Interface):
    for method in interface.exposed_methods():
        sig = interface.exposed_method_signature(method)
        rlogger.debug('registering %s with input type %s and output type %s',
                      method, sig.args, sig.output)

        spec = create_spec(method, sig)
        executor_function = create_executor_function(interface, method, spec)
        app.router.add_post('/' + method, executor_function)
Beispiel #5
0
def test_create_spec__with_file():
    field = Field('field', BytesDatasetType(), False)
    spec = create_spec('mymethod', Signature([field], field), 'iface_name',
                       'method_doc')

    assert spec == {
        "summary":
        "Calls 'mymethod' method on iface_name. Method description: method_doc",
        'requestBody': {
            'required': True,
            'content': {
                'multipart/form-data': {
                    'schema': {
                        'type': 'object',
                        'properties': {
                            'field': {
                                'type': 'string',
                                'format': 'binary'
                            }
                        }
                    }
                }
            }
        },
        'responses': {
            '200': {
                "description": "successful response",
                'content': {
                    'multipart/form-data': {
                        'type': 'string',
                        'format': 'binary'
                    }
                }
            },
            '400': {
                'description': 'incorrect request',
                "content": {
                    "application/json": {
                        'schema': {
                            'type': 'object',
                            'properties': {
                                'error': {
                                    'type': 'string'
                                },
                                'ok': {
                                    'type': 'boolean'
                                }
                            }
                        }
                    }
                }
            }
        }
    }
Beispiel #6
0
def _register_method(app, interface, method_name, signature):
    from flasgger import swag_from

    swag = swag_from(
        create_spec(method_name, signature, str(Interface),
                    interface.exposed_method_docs(method_name)))
    executor_function = swag(create_executor_function(interface, method_name))
    app.add_url_rule('/' + method_name,
                     method_name,
                     executor_function,
                     methods=['POST'])
Beispiel #7
0
def test_create_spec__with_file():
    field = Field('field', FilelikeDatasetType(), False)
    spec = create_spec('mymethod', Signature([field], field))

    assert spec == {
        'definitions': {
            'error': {
                'type': 'object',
                'properties': {
                    'error': {
                        'type': 'string'
                    },
                    'ok': {
                        'type': 'boolean'
                    }
                }
            }
        },
        'parameters': [{
            'description': 'field',
            'in': 'formData',
            'name': 'field',
            'required': True,
            'type': 'file'
        }],
        'responses': {
            '200': {
                "description": "resp descr",
                'content': {
                    '*/*': {
                        'type': 'string',
                        'format': 'binary'
                    }
                }
            },
            '400': {
                'description': 'resp descr',
                'schema': {
                    '$ref': '#/definitions/error'
                }
            }
        },
        'summary':
        'mymethod'
    }
Beispiel #8
0
def test_create_spec__no_file():
    field = Field('field', int, False)
    spec = create_spec('mymethod', Signature([field], field))

    assert spec == {
        'definitions': {
            'error': {
                'type': 'object',
                'properties': {
                    'error': {
                        'type': 'string'
                    },
                    'ok': {
                        'type': 'boolean'
                    }
                }
            },
            'request_mymethod': {
                'type': 'object',
                'properties': {
                    'field': {
                        'type': 'integer'
                    }
                }
            },
            'response_mymethod': {
                'type': 'object',
                'properties': {
                    'data': {
                        'type': 'integer'
                    },
                    'ok': {
                        'type': 'boolean'
                    }
                }
            }
        },
        'parameters': [{
            'in': 'body',
            'name': 'body',
            'required': True,
            'schema': {
                '$ref': '#/definitions/request_mymethod'
            }
        }],
        'responses': {
            '200': {
                'description': 'resp descr',
                'schema': {
                    '$ref': '#/definitions/response_mymethod'
                }
            },
            '400': {
                'description': 'resp descr',
                'schema': {
                    '$ref': '#/definitions/error'
                }
            }
        },
        'summary':
        'mymethod'
    }