1

How to write an OpenAPI definition for the following JSON? Bazically it is an array consisting of two objects with similar attributes but different fields.

[
  {
    "studentname": "somename",
    "studentrollno": "somerollno",
    "studentsubjects": [
      {
        "level": "third",
        "physics": "xyz",
        "maths": "somevalue"
      },
      {
        "level": "second",
        "physics": "abc",
        "maths": "somevalue11"
      }
    ],
    "studentresult": "pass"
  },
  {
    "studentname": "newname",
    "studentrollno": "newrollno",
    "studentsubjects": [
      {
        "level": "third",
        "physics": "xyz",
        "maths": "somevalue"
      },
      {
        "level": "second",
        "physics": "abc",
        "maths": "somevalue11"
      }
    ],
    "studentresult": "fail"
  }
]
 type: array
    items:
        type: object
        properties:
            studentname:
                type: string
                example: somename
            studentrollno:
                type: string
                example: somerollno
            studentsubjects:
                type: array
                items:
                    type:object
                    properties:
                        level:
                            type: string
                            example: third
                        physics:
                            type: string
                            example: xyz
                        maths:
                            type: string
                            example: somevalue
        type: object

This is how i have written , i have written it for the first object in studentsubjects array , but not able to code it for second object in the same array , when i am trying to do it , it is throwing me erro saying duplication of type at last line

3
  • Can you please post what you've tried so far and what part you're having problems with? Do you use OpenAPI 2.0 (swagger: '2.0') or OpenAPI 3 (openapi: 3.x.x)? See if this helps: How to describe an array of objects, How to describe nested models. Commented Jan 5, 2022 at 20:58
  • I use openapi: 3 Commented Jan 6, 2022 at 4:54
  • sure , i have posted my code which you can refer Commented Jan 10, 2022 at 5:39

0

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.