0

The node-restify library allows paths like /foo/:id. Can swagger handle such paths? i.e. something like?

var getFoo = {
    'spec': {
        'description': 'foo library',
        'path': '/foo/:id',
        'summary': 'return foo by id',
        'type': 'string',
        'produces': ['application/json']
    },
    'action': getFooObject()
};
swagger.addGet(getFoo)

When I try this in my app, the http://locahost:3001/api-docs page looks like:

{
    apiVersion: "0.0.1",
    swaggerVersion: "1.2",
    apis: [ 
        {
            path: "/foo"
        }
    ]
}

I tried escaping the double-colon with a \ character. But that didn't make a difference. Also tried replacing single quotes by double quotes. Still no difference. I am using the swagger-node-restify library which is a fork from swagger-node repository. What am I doing wrong?

Prachi
  • 528
  • 8
  • 31

1 Answers1

0

You're describing a swagger 1.2 project, which has multiple files to describe it. You can read more about the swagger 1.2 specification here:

https://github.com/OAI/OpenAPI-Specification/blob/master/versions/1.2.md

Because of that, your API will not be described at the api-docs location. It should be shown at api-docs/foo based on your description above.

note the /api-docs is called the Resource Listing and it points to the Api Declaration, which is hosted relative to api-docs as /foo.

Final note, swagger spec 1.2 is old and the tooling for 2.0 is much better. Consider upgrading your project to swagger-node or other.

fehguy
  • 6,724
  • 25
  • 23
  • I am using a library swagger-node-restify. That's why the swagger version is 1.2. I will try to use swagger-node directly. Let's see. – Prachi Jan 21 '16 at 16:50
  • I tried the path `http://localhost:3001/api-docs/foo`. It does exist, but doesn't have the specification for the getFoo function. – Prachi Jan 21 '16 at 16:56
  • do you see `/{id}` as a path? – fehguy Jan 23 '16 at 04:47