Modeling List of Maps in openapi

Viewed 158

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"

1 Answers

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'
Related