Forum Discussion

aevans04's avatar
aevans04
New Member
5 years ago

Schema with an Array of Objects doesn't show correct object type in array

I am trying to create schema for array of objects and have produced a simple test with the JSON below (sorry that this wysiwyg doesn't format it well). For testing I paste the below into swagger online editor  https://editor.swagger.io/#/ (it converts my JSON to YAML. didn't want to post YAML into this forum wysiwyg because it was removing tabs).

It shows the CatalogsArray has being an array of objects with type name = CatalogsArray (but it does have the proper Catalog type fields) instead of having type name = Catalog:

 

CatalogsArray [

  CatalogsArray{
    id integer
    title string
  }

]

 

If I reference the Catalog type for lastcatalog field in object called CatalogUser then type name = Catalog assigned to lastcatalog field is correct:

 

CatalogUser{
  username string
  lastcatalog Catalog{
                        id integer
                        title string
                    }
}

 

Anybody have any idea if there is something else I have to define when setting up array of objects to get proper object type name to show up?

 

{
"openapi": "3.0.0",
"info": {
"version": "1.0.0",
"title": "Testing Array of Objects"
},
"paths": {},
"components": {
"schemas": {
"Catalog": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"title": {
"type": "string"
}
}
},
"CatalogUser": {
"type": "object",
"properties": {
"username": {
"type": "string"
},
"lastcatalog": {
"$ref": "#/components/schemas/Catalog"
}
}
},
"CatalogsArray": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Catalog"
}
}
}
}
}