在OpenAPI YAML中指定动态键

发布于 2025-02-03 20:22:32 字数 950 浏览 4 评论 0原文

我想创建一个这样的响应结构,其中fieldProfile(配置文件类型)或摘要框架是可选的。 IE外键是动态和可选的

{
    "fieldProfile": [
        "metric1",
        "metric2",
        "metric3"
    ],
    "summaryProfile": [
        "metric1",
        "metric2",
        "metric3"
    ]
}

,或者

{
    "fieldProfile": [
        "metric1",
        "metric2",
        "metric3"
    ]
} // Here Summary Profile is removed, similarly we can have a response of summaryProfile or have both in response

我正在创建这样的响应模式,但是在这里,我希望Metrictype(FieldProfile/SummaryProfile)成为指标的关键(METRIC列表)。

ProfileMetrics:
  description: List of metrics available in Field Profile
  type: object
  required:
    - metricType
    - metrics
  properties:
    metrics:
      type: array
      items:
        type: object
        required:
          - metricName
        properties:
          metricName:
            type: string

任何帮助都将受到赞赏

I want to create a response structure like this where either fieldProfile (profile type) or summaryProfile is optional. i.e outer key is dynamic and optional

{
    "fieldProfile": [
        "metric1",
        "metric2",
        "metric3"
    ],
    "summaryProfile": [
        "metric1",
        "metric2",
        "metric3"
    ]
}

Or

{
    "fieldProfile": [
        "metric1",
        "metric2",
        "metric3"
    ]
} // Here Summary Profile is removed, similarly we can have a response of summaryProfile or have both in response

I am creating the response schema like this, but here I want the metricType (fieldProfile/summaryProfile) to be the key for metrics (metric list).

ProfileMetrics:
  description: List of metrics available in Field Profile
  type: object
  required:
    - metricType
    - metrics
  properties:
    metrics:
      type: array
      items:
        type: object
        required:
          - metricName
        properties:
          metricName:
            type: string

Any help is appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你对谁都笑 2025-02-10 20:22:32

您的架构可以定义如下:

MySchema:
  type: object
  properties:
    fieldProfile:
      type: array
      items:
        type: string
    summaryProfile:
      type: array
      items:
        type: string

  # At least fieldProfile or summaryProfile (or both) must be present
  minProperties: 1

而不是minproperties:1,您可以使用此anyof + 必需构造,它将达到相同的效果在此示例中:

  anyOf:
    - required: [fieldProfile]
    - required: [summaryProfile]

Your schema can be defined as follows:

MySchema:
  type: object
  properties:
    fieldProfile:
      type: array
      items:
        type: string
    summaryProfile:
      type: array
      items:
        type: string

  # At least fieldProfile or summaryProfile (or both) must be present
  minProperties: 1

Instead of minProperties: 1, you can use this anyOf + required construct, it will achieve the same effect in this example:

  anyOf:
    - required: [fieldProfile]
    - required: [summaryProfile]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文