0

I am struggling to define a request body in OpenApi. I want to force the user to send me data in the following shape:

{
    "test": {
        "a": "a",
        "b": "b",
        "abc": [
            {
                "type": "abc",
                "name": "name"
            },
            {
                "type": "abc",
                "name": "name"
            }
            ...more
        ]
    }
}

This is what I tried but it does not seem to work:

 schemas:
    SampleRequest:
      required:
        - abc
      properties:
        abc: 
          $ref: "#/components/schemas/ABCType"

    ABCType:
      type: object
      required:
        - test
      properties: 
        test: 
          type: array 
          items:
            type: object
        properties: 
          type: 
            type: string
          name:
            type: string

Any help appreciated. Thank you

1

1 Answer 1

2

With the currect json I couldn't make such sense but created this. This created a json which replicates yours.

ABCType:
  type: object
  additionalProperties: false
  required: 
  - a
  - b
  - abc
  properties:
    a:
      description: A of ABCType
      type: string
    b:
      description: B of ABCType
      type: string
    abc:
      description: Array of ABCType
      type: array
      items:
        $ref: '#/components/schemas/ABCArrayValue'
ABCArrayValue:
  type: object
  additionalProperties: false
  required:
  - type
  - name
  properties:
    type:
      description: Type of this array value
      type: string
    name:
      description: Name of this array value
      type: string
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.