Skip to content

patch_function_name_parsing

fastagency.api.openapi.patch_fastapi_code_generator.patch_function_name_parsing #

patch_function_name_parsing() -> None
Source code in fastagency/api/openapi/patch_fastapi_code_generator.py
def patch_function_name_parsing() -> None:
    def function_name(self: Operation) -> str:
        if self.operationId:
            name: str = self.operationId.replace("/", "_")
        else:
            path = re.sub(r"/{|/", "_", self.snake_case_path).replace("}", "")
            name = f"{self.type}{path}"
        return stringcase.snakecase(name)  # type: ignore[no-any-return]

    Operation.function_name = cached_property(function_name)
    Operation.function_name.__set_name__(Operation, "function_name")

    logger.info("Patched Operation.function_name")