OpenAPI中地图的建模列表

发布于 2025-01-30 19:49:40 字数 572 浏览 3 评论 0原文

我需要从 *.YAML定义文件中生成对象。我的最终目标是生成POJO,如下所示:

public class MyGeneratedPojo {

    private List<Map<String, MyInternalObject>> internalProperties;
}

我知道我可以使用其他杂货来对地图进行建模。或者我可以做这样的事情:

MyGeneratedPojo:
  properties:
    type: array
    items:
      $ref: '#/.../MyInternalMapDefinition'

MyInternalMapDefinition:
  type: object
  additionalProperties:
    type: array
    items:
      $ref: '#/.../MyInternalMapDefinition'

我不喜欢的是“ MyInternalMapDefinition”定义。无论如何,是否可以将其定义/模型为“ MyGeneratedPojo”的一部分

I need to generate object from *.yaml definitions file. My end goal is generated POJO like in example below:

public class MyGeneratedPojo {

    private List<Map<String, MyInternalObject>> internalProperties;
}

I know that I could use additionalProperties in order to model the map. Or I could do something like this:

MyGeneratedPojo:
  properties:
    type: array
    items:
      $ref: '#/.../MyInternalMapDefinition'

MyInternalMapDefinition:
  type: object
  additionalProperties:
    type: array
    items:
      $ref: '#/.../MyInternalMapDefinition'

What I don't like is this "MyInternalMapDefinition" definition. Is there anyway to define/model it as part of "MyGeneratedPojo"

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

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

发布评论

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

评论(1

超可爱的懒熊 2025-02-06 19:49:40

我不喜欢的是这个“ MyInternalMapDefinition”定义。无论如何,是否可以将其定义/模型为“ MyGeneratedPojo”的一部分

您可以在内部架构中进行内装:

MyGeneratedPojo:
  type: object
  properties:
    internalProperties:
      type: array       # List<...>
      items:
        type: object    # Map<String, MyInternalObject>
        additionalProperties:
          $ref: '#/components/schemas/MyInternalObject'

What I don't like is this "MyInternalMapDefinition" definition. Is there anyway to define/model it as part of "MyGeneratedPojo"

You can inline the inner schema:

MyGeneratedPojo:
  type: object
  properties:
    internalProperties:
      type: array       # List<...>
      items:
        type: object    # Map<String, MyInternalObject>
        additionalProperties:
          $ref: '#/components/schemas/MyInternalObject'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文