×

OpenShift Serverless Logic 使用 `kogito.sw.operationIdStrategy` 属性生成用于调用 OpenAPI 文档中定义的服务的 REST 客户端。此属性决定如何为 REST 客户端配置导出配置键。

`kogito.sw.operationIdStrategy` 属性支持以下值:`FILE_NAME`、`FULL_URI`、`FUNCTION_NAME` 和 `SPEC_TITLE`。

FILE_NAME

OpenShift Serverless Logic 使用 OpenAPI 文档文件名创建配置键。该键基于文件名,其中特殊字符将被替换为下划线。

示例配置
quarkus.rest-client.stock_portfolio_svc_yaml.url=https://127.0.0.1:8282/ (1)
1 OpenAPI 文件路径为 `src/main/resources/openapi/stock-portfolio-svc.yaml`。生成的配置 REST 客户端 URL 的键为 `stock_portfolio_svc_yaml`
FULL_URI

OpenShift Serverless Logic 使用 OpenAPI 文档的完整 URI 路径作为配置键。完整的 URI 将被清理以形成键。

无服务器工作流示例
{
    "id": "myworkflow",
    "functions": [
        {
          "name": "myfunction",
          "operation": "https://my.remote.host/apicatalog/apis/123/document"
        }
    ]
    ...
}
示例配置
quarkus.rest-client.apicatalog_apis_123_document.url=https://127.0.0.1:8282/ (1)
1 URI 路径为 `https://my.remote.host/apicatalog/apis/123/document`。生成的配置 REST 客户端 URL 的键为 `apicatalog_apis_123_document`。
FUNCTION_NAME

OpenShift Serverless Logic 将工作流 ID 和引用 OpenAPI 文档的函数名称组合起来生成配置键。

无服务器工作流示例
{
    "id": "myworkflow",
    "functions": [
        {
          "name": "myfunction",
          "operation": "https://my.remote.host/apicatalog/apis/123/document"
        }
    ]
    ...
}
示例配置
quarkus.rest-client.myworkflow_myfunction.url=https://127.0.0.1:8282/ (1)
1 工作流 ID 为 `myworkflow`。函数名称为 `myfunction`。生成的配置 REST 客户端 URL 的键为 `myworkflow_myfunction`。
SPEC_TITLE

OpenShift Serverless Logic 使用 OpenAPI 文档中的 `info.title` 值创建配置键。标题将被清理以形成键。

OpenAPI 文档示例
openapi: 3.0.3
info:
  title: stock-service API
  version: 2.0.0-SNAPSHOT
paths:
  /stock-price/{symbol}:
...
示例配置
quarkus.rest-client.stock-service_API.url=https://127.0.0.1:8282/ (1)
1 OpenAPI 文档标题为 `stock-service API`。生成的配置 REST 客户端 URL 的键为 `stock-service_API`。

使用 URI 别名

作为 `kogito.sw.operationIdStrategy` 属性的替代方案,您可以使用 `workflow-uri-definitions` 自定义扩展为 URI 分配别名。此别名简化了配置过程,可用作 REST 客户端设置和函数定义中的配置键。

`workflow-uri-definitions` 扩展允许您将 URI 映射到别名,您可以在整个工作流和配置文件中引用该别名。这种方法提供了一种集中管理 URI 及其配置的方式。

前提条件
  • 您可以访问具有在 OpenShift Container Platform 中创建应用程序和其他工作负载的相应角色和权限的 OpenShift Serverless Logic 项目。

  • 您可以访问 OpenAPI 规范文件。

步骤
  1. 将 `workflow-uri-definitions` 扩展添加到您的工作流。在此扩展中,为您的 URI 创建别名。

    工作流示例
    {
      "extensions": [
        {
          "extensionid": "workflow-uri-definitions", (1)
          "definitions": {
            "remoteCatalog": "https://my.remote.host/apicatalog/apis/123/document" (2)
          }
        }
      ],
      "functions": [ (3)
        {
          "name": "operation1",
          "operation": "remoteCatalog#operation1"
        },
        {
          "name": "operation2",
          "operation": "remoteCatalog#operation2"
        }
      ]
    }
1 将扩展 ID 设置为 `workflow-uri-definitions`。
2 通过将 `remoteCatalog` 别名映射到 URI(例如 `https://my.remote.host/apicatalog/apis/123/document` URI)来设置别名定义。
3 使用带有操作标识符(例如 `operation1` 和 `operation2` 操作标识符)的 `remoteCatalog` 别名设置函数操作。
  1. 在 `application.properties` 文件中,使用工作流中定义的别名配置 REST 客户端。

    属性示例
    quarkus.rest-client.remoteCatalog.url=https://127.0.0.1:8282/

    在之前的示例中,配置键设置为quarkus.rest-client.remoteCatalog.url,URL 设置为https://127.0.0.1:8282/,REST 客户端通过引用remoteCatalog 别名来使用该 URL。

  2. 在您的工作流程中,在定义操作 URI 的函数时使用此别名。

    示例工作流程(续)
    {
      "functions": [
        {
          "name": "operation1",
          "operation": "remoteCatalog#operation1"
        },
        {
          "name": "operation2",
          "operation": "remoteCatalog#operation2"
        }
      ]
    }