trouble with swagger-js

47 views
Skip to first unread message

clh

unread,
Nov 20, 2013, 5:10:27 PM11/20/13
to swagger-sw...@googlegroups.com
I am getting "swagger.apis.user.createAccount is not a function" in firebug with the code below.
You can see the schema for my user resource below the code snip.
I can console.log the swagger.api.user object and can see the API method "createAccount" in the operationsArray, but for some reason it does not seem to be binding.
Also, I can interact with the API using swagger-ui.
any tips to try and debug this?



<script language="javascript" type="text/javascript">
  $(document).ready(function() {
    window.swagger = new SwaggerApi(
    {
      url: "http://localhost:9000/api-docs",
        success: function() {
          if(swagger.ready === true) {
            var body = {firstName: "bob",lastName: "smith",email: "b...@google.com"};
            swagger.apis.user.createAccount({body: JSON.stringify(body)});
          },
          function(data) {
            console.log("success");
          }
        );
      }
    }
  })
}
</script>









{
    "apiVersion": "0.2",
    "swaggerVersion": "1.2",
    "basePath": "http://192.168.135.128:9000",
    "resourcePath": "/user",
    "produces": [
        "application/json"
    ],
    "apis": [
        {
            "path": "/user/logout",
            "operations": [
                {
                    "method": "GET",
                    "summary": "Logs out current logged in user session",
                    "notes": "",
                    "type": "void",
                    "nickname": "",
                    "parameters": []
                }
            ]
        },
        {
            "path": "/user/createAccount",
            "operations": [
                {
                    "method": "POST",
                    "summary": "Create a new user Account",
                    "notes": "",
                    "type": "User",
                    "nickname": "",
                    "parameters": [
                        {
                            "name": "body",
                            "description": "Created user account",
                            "required": true,
                            "type": "User",
                            "paramType": "body"
                        }
                    ]
                }
            ]
        },
        {
            "path": "/user/{username}",
            "operations": [
                {
                    "method": "GET",
                    "summary": "Get user by user name",
                    "notes": "",
                    "type": "User",
                    "nickname": "",
                    "parameters": [
                        {
                            "name": "username",
                            "description": "The name that needs to be fetched. Use user1 for testing.",
                            "required": true,
                            "type": "string",
                            "paramType": "path"
                        }
                    ],
                    "responseMessages": [
                        {
                            "code": 400,
                            "message": "Invalid username supplied"
                        },
                        {
                            "code": 404,
                            "message": "User not found"
                        }
                    ]
                }
            ]
        },
        {
            "path": "/user/login",
            "operations": [
                {
                    "method": "GET",
                    "summary": "Logs user into the system",
                    "notes": "",
                    "type": "string",
                    "nickname": "",
                    "parameters": [
                        {
                            "name": "username",
                            "description": "The user name for login",
                            "required": true,
                            "type": "string",
                            "paramType": "query"
                        },
                        {
                            "name": "password",
                            "description": "The password for login in clear text",
                            "required": true,
                            "type": "string",
                            "paramType": "query"
                        }
                    ],
                    "responseMessages": [
                        {
                            "code": 400,
                            "message": "Invalid username/password supplied"
                        }
                    ]
                }
            ]
        }
    ],
    "models": {
        "ObjectId": {
            "id": "ObjectId",
            "properties": {
                "_time": {
                    "type": "integer",
                    "format": "int32"
                },
                "_machine": {
                    "type": "integer",
                    "format": "int32"
                },
                "_inc": {
                    "type": "integer",
                    "format": "int32"
                },
                "machine": {
                    "type": "integer",
                    "format": "int32"
                },
                "timeSecond": {
                    "type": "integer",
                    "format": "int32"
                },
                "inc": {
                    "type": "integer",
                    "format": "int32"
                },
                "new": {
                    "type": "boolean"
                },
                "time": {
                    "type": "integer",
                    "format": "int64"
                }
            }
        },
        "User": {
            "id": "User",
            "properties": {
                "username": {
                    "type": "string"
                },
                "firstName": {
                    "type": "string"
                },
                "lastName": {
                    "type": "string"
                },
                "email": {
                    "type": "string"
                },
                "phone": {
                    "type": "string"
                },
                "userStatus": {
                    "type": "integer",
                    "format": "int32",
                    "description": "User Status",
                    "enum": [
                        "1-registered",
                        "2-active",
                        "3-closed"
                    ]
                },
                "password": {
                    "type": "string"
                },
                "id": {
                    "$ref": "ObjectId"
                }
            }
        }
    }
}

clh

unread,
Nov 22, 2013, 10:31:00 AM11/22/13
to swagger-sw...@googlegroups.com
I resolved this.

It was due to my server running on a non-standard port.
I added an Nginx vhost in front of my play2 server and swagger-js started working correctly.

I was surprised that it didn't work on a non-standard port.
Reply all
Reply to author
Forward
0 new messages