theoomoregbee / sails-hook-swagger-generator

A tool to help generate Swagger specification documentation based on OAS 3.0 for Sails APIs
MIT License
78 stars 33 forks source link

Custom Route Configuration - not working as expected #29

Closed RotemBot closed 6 years ago

RotemBot commented 6 years ago

This is my route definition:

'POST /api/v1/projects/:project_id/assignments': {
    controller: 'AssignmentController',
    action: 'create',
    swagger: {
      summary: 'Creating a new Annotation Assignment',
      description: 'Create a new annotation assignment and assign tasks to annotators',
      body: {
        title: {
          type: 'string',
          required: true
        },
        description: {
          type: 'string',
          required: true
        },
        dataset_id: {
          type: 'string',
          required: true
        },
        sample_dataset: {
          type: 'string',
          required: true
        },
        annotators: {
          type: 'json',
          required: true
        }
      },
      parameters: [{
        in: 'path',
        name: 'project_id',
        required: true,
        type: 'integer',
        description: 'ID of the current project'
      }]
    }
  }

This is what I get in the Swagger UI: image

theoomoregbee commented 6 years ago

Can you be more explicit

RotemBot commented 6 years ago

The body parameters don't match the parameters I defined

RotemBot commented 6 years ago

How do I override/cancel the default 'body'?

theoomoregbee commented 6 years ago

Do you have a model for Assignment? if so check if the body matches it

RotemBot commented 6 years ago

Yes, of course I have a model assignment. I know it matches it, I want to override the default.

theoomoregbee commented 6 years ago

oh I see, the problem is body is not overriding models. Will look into it later today

RotemBot commented 6 years ago

Thanks!

RotemBot commented 6 years ago

Also, in this example, I need 'annotators' to be an array, or json object. As you can see, it is not reflected in the result. How do I do that?

theoomoregbee commented 6 years ago

you can use array as type https://swagger.io/docs/specification/data-models/data-types/

RotemBot commented 6 years ago

That doesn't work, because then you need to specify the items' type (i.e. 'string'). I've tried doing that with and without specifying items, and it did not work.

This is what happens: image

Any chance you can give a full example of defining an array param through custom routes, and what it looks like in the swagger UI?

RotemBot commented 6 years ago

@theo4u Any update on the problem with body? And please can you give a full example of defining a string array as a param? (Not how to do it in a swagger file, but in a custom route definition).

theoomoregbee commented 6 years ago

going to look into this later today