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

Add documantation for customization of path object #25

Closed
silberjan opened this issue Dec 5, 2016 · 6 comments
Closed

Add documantation for customization of path object #25

silberjan opened this issue Dec 5, 2016 · 6 comments

Comments

@silberjan
Copy link

silberjan commented Dec 5, 2016

Currently, I see no way of editing the path object inside the servcie. Only the definitions get parsed.

It would be great to add some information to the path object e.g. to set possible responses.

it could look something like this:

class MessagesService {

  constructor(options) {
    this.options = options || {};

    this.docs = {
      description: 'A service to send messages',
      definitions: {
        messages: { (...) }
      }
      path: {
        messages: {
          create: {   // Anything inside would override the default config for "/messages".post
            description: 'Custom POST description',
            responses: {
              '201': {
                description: 'New Message was created'
              }
            }
          }
        }
      }
    }
  }

  (...)
}
@arddor
Copy link

arddor commented Dec 7, 2016

This is something which I also discovered recently while looking closer at the sequelize example:

const doc = {
  description: 'Operations about Users.',
  definitions: {
    'UserPaginate': swagger.definition({
      attributes: {
        data: Sequelize.ARRAY('users')
      }
    }, {
      extends: ['paginate']
    })
  },
  definition: swagger.definition(model),
  securities: ['find'],
  find: {
    parameters: [{
      description: 'Get examples by name',
      in : 'query',
      required: false,
      name: 'email',
      type: 'string'
    }],
    responses: {
      '200': {
        description: 'successful operation',
        schema: {
          '$ref': '#/definitions/UserPaginate'
        }
      }
    }
  }
};

As you see you can define response with find, get, ...
I would say that there should be some more documentation to make that clear

@silberjan
Copy link
Author

Oh thats exactly what i need. Thanks @arddor !

Documentation for that feature would be really helpful ;)

@silberjan silberjan changed the title Make path object customizable for services Add documantation for customization of path object Dec 7, 2016
@daffl
Copy link
Member

daffl commented Dec 9, 2016

If someone would like to add the documentation (just a quick example or paragraph with an explanation) feel free to edit the README. It'll then just become part of the main docs with the official release.

@akshay2604
Copy link

akshay2604 commented Apr 2, 2017

If someone can post a basic documentation for this, it will be really helpful.

I am currently doing this.

  const doc = {
    path: {
      '/api/xbcBusinesses': { // <--- not sure about this
         description: 'A service for business',
         find: {
            parameters: [{
            description: 'Get examples by name',
            in : 'query',
            required: false,
            name: 'email',
            type: 'string'
         }],
         },
          create: { 
            description: 'Custom POST description',
            responses: {
              '201': {
                description: 'New Business was created'
              }
            }
          }
      }
    }
  }

and register it here.

app.use('/api/xbcBusinesses',Object.assign(service(options), {
      docs: doc
}));

This is the response i am getting.

image

Obviously I am not able to get the doc here.

Also I am not able to get the swagger.definition part from above. Where is swagger defined?

@josx
Copy link

josx commented May 23, 2017

My example using mongoose :

  const doc = {
     find: {
       parameters: [{
         description: 'Search model by string',
         in: 'query',
         required: false,
         name: '$text[$search]',
         type: 'string'
       }],
     },
     get: {
       parameters: [{
         description: 'Search mode by id',
         in: 'path',
         required: true,
         name: '_id',
         type: 'string'
       }],
     }
   };

@Mairu
Copy link
Collaborator

Mairu commented May 24, 2019

This is all configurable by now. Documentation and examples were added with version 1.0.0.

@Mairu Mairu closed this as completed May 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants