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

theBeginner
  • 85
  • 10
  • 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](https://stackoverflow.com/q/46167981/113116), [How to describe nested models](https://stackoverflow.com/q/26287962/113116). – Helen Jan 05 '22 at 20:58
  • I use openapi: 3 – theBeginner Jan 06 '22 at 04:54
  • sure , i have posted my code which you can refer – theBeginner Jan 10 '22 at 05:39

0 Answers0