1

I am looking to represent the following JSON Object in OpenAPI:

 {
   "name": "filter name",
   "type": "type of filter",
   "depends_on": "parent filter",

    // the value can be :
   "values": ["value 1", "value 2", ...]   

   // or
   "value": {
      "parent 1" : ["value 1", "value 2", ...],
      "parent 2": [ "value 3", "value 4", ...],
      ..... 
    }
 }

I have tried to use the following spec

Filters:
      type: object
      properties:
        name:
          type: string
        type:
          type: string
        depends_on:
          type: string
        values:
          type: object
          additionalProperties:
            oneOf:
              - integer
              - string

but it didn't work as expected.

Can anyone help me with this

1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Dec 20, 2021 at 21:07

1 Answer 1

2

Solved using oneOf: I found the solution here

    Filters:
      type: object
      properties:
        name:
          type: string
        type:
          type: string
        depends_on:
          type: string
        values:
          oneOf:
            - type: object
              properties:
                parent value:
                  type: array
                  items:
                    type: string
                    example: "value 1"
            - type: array
              items:
                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.