Skip to content
This repository has been archived by the owner on Sep 14, 2022. It is now read-only.

Nested Model Reference Cap? #151

Closed
GStipick opened this issue Aug 5, 2014 · 2 comments
Closed

Nested Model Reference Cap? #151

GStipick opened this issue Aug 5, 2014 · 2 comments

Comments

@GStipick
Copy link

GStipick commented Aug 5, 2014

Hello swagger users,

I was wondering if there has been any resolution to the issue presented here: swagger-api/swagger-ui#463

Recap of above link:
Using swagger-node-express there seems to be a nesting cap of 1 layer deep. E.G. If you use a model within a model, the second model will not be loaded and not appear in neither swagger-ui nor in the raw JSON output that describes the API and its models.

I believe that this is more of a swagger-node-express issue due to the JSON output not containing the second layered model as expected.

It seems that this issue may be related as well: #85

Example (example given in swagger-api/swagger-ui#463 is very similar):

newProjectObject references projectReturn which then references projectWithSource

  • newProjectObject -> projectReturn -> projectWithSource

    exports.models = {
        "projectWithSource":{
            "id":"projectWithSource",
            "properties":{
                "project_id":{
                    "type":"integer",
                    "format": "int32",
                    "description": "Unique id for the project"
                },
                "name":{
                    "type":"string",
                    "description":"Unique name for the project"
                },
                "description":{
                    "type":"string",
                    "description":"Description of the project.  Can be an empty string."
                },
                "created-date":{
                    "type":"string",
                    "format":"date-time",
                    "description":"Date the project was created"
                },
                "created_source":{
                    "type":"string",
                    "description":"Source from which the project was created"
                }
            },
            "required":[
                "project_id",
                "name",
                "description",
                "created-date",
                "created_source"
            ]
        },
    
        "projectReturn":{
            "id":"projectReturn",
            "properties":{
                "data":{
                    "type":"array",
                    "items":{
                        "$ref":"projectWithSource"                    
                    }
                },
                "count":{
                    "type":"integer",
                    "format": "int32",
                    "description":"How many responses were found"
                },
                "success":{
                    "type":"string",
                    "description":"true or false"
                }
            },
            "required":[
                "data",
                "count",
                "success"
            ]
        },
    
        "newProjectObj":{
            "id":"newProjectObj",
            "properties":{
                "projectObj":{
                    "$ref":"projectReturn"                    
                },
                "customAttr":{
                    "type":"array",
                    "description":"Array of custom defined attributes",
                    "items":{
    
                    }
                }
            },
            "required":[
                "projectObj",
                "customAttr"
            ]
        }
    };
    

The above result shows as the following in swagger-ui:
image

The JSON representation given by swagger-node-express is as follows:

{
     apiVersion:"0.0.1",
     swaggerVersion:"1.2",
     basePath:"http://localhost:8002",
     resourcePath:"/newProjectService",
     description:"(NewProject) - Project folder/file creation",
     apis:[
        {
           path:"/newProjectService",
           operations:[
              {
                 method:"POST",
                 summary:"Helps create a new Project",
                 notes:"Creates a project folder with template '.xlsm' and '.csv' files for the client to input their custom data.",
                 parameters:[
                    {
                       paramType:"body",
                       name:"body",
                       description:"projectObj properties to be updated",
                       type:"newProjectObj",
                       required:true
                    }
                 ],
                 type:"success",
                 nickname:"newProject",
                 responseMessages:[
                    {
                       code:404,
                       message:" not found"
                    }
                 ]
              }
           ]
        }
     ],
     models:{
        newProjectObj:{
           id:"newProjectObj",
           properties:{
              projectObj:{
                 $ref:"projectReturn"
              },
              customAttr:{
                 type:"array",
                 description:"Array of custom defined attributes",
                 items:{

                 }
              }
           },
           required:[
              "projectObj",
              "customAttr"
           ]
        },
        success:{
           id:"success",
           properties:{
              success:{
                 type:"string",
                 description:"True or False"
              }
           },
           required:[
              "success"
           ]
        },
        projectReturn:{
           id:"projectReturn",
           properties:{
              data:{
                 type:"array",
                 items:{
                    $ref:"projectWithSource"
                 }
              },
              count:{
                 type:"integer",
                 format:"int32",
                 description:"How many responses were found"
              },
              success:{
                 type:"string",
                 description:"true or false"
              }
           },
           required:[
              "data",
              "count",
              "success"
           ]
        }
     }
  }

Conclusion - As you can see, the model 'projectWithSource' is missing.

If you refer back to swagger-api/swagger-ui#463 and look at my comment at the bottom, the model will load as long as some other property has a link to it that is 1 layer deep.

If anyone has any advice on whether this is a bug, or I am not doing this correctly, please let me know. Thanks.

@fehguy
Copy link
Contributor

fehguy commented Aug 12, 2014

this has been reported before, will use your model as a test

@fehguy
Copy link
Contributor

fehguy commented Oct 31, 2014

the cap for nesting is really about recursion and duplication of the same model type. So I believe it's working as designed--please post any UI feedback into the swagger-ui project.

@fehguy fehguy closed this as completed Oct 31, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants