openapi中的地图建模列表

Modeling List of Maps in openapi

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

public class MyGeneratedPojo {

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

我知道我可以使用 additionalProperties 来为地图建模。或者我可以这样做:

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

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

我不喜欢这个“MyInternalMapDefinition”定义。无论如何 define/model 它作为“MyGeneratedPojo”的一部分

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

您可以内联内部模式:

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