feathersjs-ecosystem / feathers-swagger

Add documentation to your FeatherJS services and feed them to Swagger UI.
MIT License
225 stars 64 forks source link

Allow each method of a service to define docs. #52

Closed cpsubrian closed 7 years ago

cpsubrian commented 7 years ago

Simple change that allows for an alternative syntax in services that in some cases would read better (IMO). Example (with a theoretical decorator that we could even ship):

@docs({
  description: 'My cool service.'
})
class MyService {
  @docs({
    description: 'Create the cool thing.',
    parameters: [],
    responses: {}
  })
  create () {
    // Do the thing
  }

  @docs({
    description: 'Find cool things.',
    parameters: [],
    responses: {}
  })
  find () {
    // Do the thing
  }
}

Or just use getters in a clever fashion.

class MyService {
  get docs () {
    return {
      description: 'My cool service.'
    }
  }

  get create () {
    return Object.assign(this._create, {
      docs: {
        description: 'Create the cool thing.',
        parameters: [],
        responses: {}
      }
    })
  }
  _create () {
    // Do the thing
  }

  get find () {
    return Object.assign(this._find, {
      docs: {
        description: 'Find cool things.',
        parameters: [],
        responses: {}
      }
    })
  }
  _find () {
    // Do the thing
  }
}