Ejemplo n.º 1
0
def get_all_described_paths():
    """
    fetch the description of all api routes that have an 'OPTIONS' endpoint
    """
    swagger = Swagger()
    for endpoint, rules in app.url_map._rules_by_endpoint.items():
        for rule in rules:
            if 'OPTIONS' not in rule.methods or rule.provide_automatic_options:
                continue

            if rule.hide:
                # we might want to hide some rule
                continue

            view_function = app.view_functions.get(endpoint)
            if view_function is not None:
                view_class = view_function.view_class
                resource = view_class()
                schema_path = make_schema(resource=resource, rule=rule)

                # the definitions are stored aside and referenced in the response
                swagger.definitions.update(schema_path.definitions)

                formated_rule = format_args(rule.rule)

                # we trim the base path
                formated_rule = base_path_regexp.sub('', formated_rule)

                swagger.paths[formated_rule] = schema_path

    return swagger
Ejemplo n.º 2
0
    def api_description(self, **kwargs):
        """
        return the API description

        Note: when the migration to swagger is completed, we can rename this function 'options'
        but for the moment we don't want all DocumentedResource to have an 'options' method
        """
        args = self.parsers["options"].parse_args()
        options_response = jormungandr.app.make_default_options_response()
        if not args['schema']:
            return options_response
        from flask import request
        schema = make_schema(resource=self, rule=request.url_rule)
        return SwaggerOptionPathSerializer(schema).data, 200, {'Allow': options_response.allow}