Exemplo n.º 1
0
    def resolve_operation_id(self, operation):
        """
        Resolves the operationId in snake_case using a mechanism similar to RestyResolver.

        eg. `GET /api/factoids` is resolved to `api.factoids.get_factoids()` because the operationId is `getFactoids`.

        Uses RestyResolver as fallback for missing operationIds.
        """
        if operation.operation_id:
            operation_id = RestyResolver.resolve_operation_id(self, operation)
            pythonic_operation_id = re.sub(r'([A-Z])',
                                           lambda m: '_' + m.group(1).lower(),
                                           operation_id)
            path_match = re.search(
                r'^/?(?P<resource_name>([\w\-](?<!/))*)(?P<trailing_slash>/*)(?P<extended_path>.*)$',
                operation.path)
            resource_name = path_match.group('resource_name')
            return self.default_module_name + '.' + resource_name + "." + pythonic_operation_id

        return self.resolve_operation_id_using_rest_semantics(operation)
Exemplo n.º 2
0
    def resolve_operation_id(self, operation):
        """
        Resolves the operationId using REST semantics unless explicitly configured in the spec
        Once resolved with REST semantics the view_name is capitalised and has 'View' added
        to it so it now matches the Class names of the MethodView

        :type operation: connexion.operations.AbstractOperation
        """
        if operation.operation_id:
            # If operation_id is defined then use the higher level API to resolve
            return RestyResolver.resolve_operation_id(self, operation)

        # Use RestyResolver to get operation_id for us (follow their naming conventions/structure)
        operation_id = self.resolve_operation_id_using_rest_semantics(
            operation)
        module_name, view_base, meth_name = operation_id.rsplit(".", 2)
        if re.search(r"\{.*\}$", operation.path):
            view_suffix = "View"
        else:
            view_suffix = "ListView"

        view_name = self.singularize(view_base.capitalize()) + view_suffix

        return "{}.{}.{}".format(module_name, view_name, meth_name)