Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use "models" as a tag #858

Closed
DavidBiesack opened this issue Jan 27, 2015 · 3 comments
Closed

Cannot use "models" as a tag #858

DavidBiesack opened this issue Jan 27, 2015 · 3 comments

Comments

@DavidBiesack
Copy link

If you add a tag named "models" to an API and tag a method with it, swagger-ui throws an exception.

swagger-client.js:466 Uncaught TypeError: Cannot read property 'push' of undefined
 operationGroup.apis.push(operationObject);

here, operationGroup.apis is undefined

I tracked this down to swagger-client.js line 458 which does:

operationGroup = this[tag];

but this.tag is not an operations group, it is the list of models (schemas) in the API.
(in this example A : Model, B : Model )

Unfortunately, this conflicts with SwaggerClient.models

This also means that any other field of the SwaggerClient object may not be used as a tag.

This should probably be stored elswwhere, such as this.operationGroups[tag]

operationGroup = this.operationGroups.[tag];

to avoid conflicting with the other members of SwaggerClient (such as basePath, title, etc.)

Here is a sample swagger.json file that causes this:

{
    "swagger" : "2.0",
    "info" : {
    "title" : "issue with a tag named 'models'",
    "contact" : {
        "name" : "David Biesack",
        "email" : "David.Biesack@sas.com"
    },
    "version" : "1"
    },
    "tags" : [{ "name" : "tag1",
        "description" : ""
          },
              { "name" : "models",
                "description" : "TODO: add description of models"
              }
         ],
    "host" : "www.example.com",
    "basePath" : "/",
    "schemes" : ["http"],
    "paths" : {
    "/" : {
        "get" : {
        "tags" : ["tag1"],
        "summary" : "Return a list of links to the top level collections in this REST API, as well as links to create new instances in the top level collections.",
        "produces" : ["application/xml",
                  "application/json"],
        "responses" : {
            "200" : {
            "description" : "REST API resource collection links."
            }
        }
        }
    },
    "/models/{modelId}" : {
        "head" : {
        "tags" : ["models"],
        "summary" : "get headers for a model",
        "parameters" : [{
            "name" : "modelId",
            "in" : "path",
            "type" : "string",
            "required" : true,
            "description" : "String containing the id of the model."
        }
                   ],
        "responses" : {
            "200" : {
            "description" : "Return a specific model resource status code."
            },
            "403" : {
            "description" : "The project is not locked by the current user."
            },
            "404" : {
            "description" : "Not found."
            },
            "423" : {
            "description" : "The project is locked by a different user."
            }
        }
        }
    }
    },

    "definitions" : {
    "A" : {
        "id" : "A",
        "title" : "Resource A",
        "properties" : {
        "id" : {
            "type" : "string",
            "description" : "The id."
        }
        },
        "B" : {
                "id" : "B",
        "title" : "Resource B",
        "properties" : {
            "context" : {
            "type" : "string",
            "description" : "The context"
            }
        }
        }
        }
    }
}
@fehguy fehguy added this to the v2.1.0-M2 milestone Jan 28, 2015
@mohsen1
Copy link
Contributor

mohsen1 commented Mar 4, 2015

This is a duplicate of #802. The issue is in underlying swagger-js library. swagger-api/swagger-js#194 is for addressing this issue.

Closing as duplicate

@whitlockjc
Copy link
Contributor

This should be fixed in the latest develop_2.0 build of swagger-js.

@zdila
Copy link

zdila commented May 25, 2015

See #1061: It is caused for tag info. Client version is 2.1.8-M1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants