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

Fix extra whitespace if no versionPrefix is passed in config. #48

Merged
merged 1 commit into from
Apr 1, 2017

Conversation

cpsubrian
Copy link
Contributor

If no versionPrefix is passed in the config, then things like tags in the docs will have extra whitespace. Like:

{
  // ... stuff
  "tags": [
    {
      "name": "auth ", // <--- extra whitespace
      "description": "A auth service",
      "externalDocs": {}
    },
    {
      "name": "users ",  // <--- extra whitespace
      "description": "A users service",
      "externalDocs": {}
    }
  ],
  // ... more stuff
}

@cpsubrian
Copy link
Contributor Author

Normally, you'd be overriding this stuff, but might as well offer clean defaults. 😄

@daffl daffl merged commit 37a2c8c into feathersjs-ecosystem:master Apr 1, 2017
@daffl
Copy link
Member

daffl commented Apr 1, 2017

Thank you for the PRs. Both released as v0.3.5

@cpsubrian
Copy link
Contributor Author

@daffl No problem, thanks for the quick merge! I'm sure there will be more, just diving in here. Migrating an app to feathers that used to be a more custom app utilizing swaggerize-express. Lots to cover heh.

One quick thought while I have your attention: Wondering if a library of swagger docs for some of the core features makes sense, either as part of this or not. For example, I'm working up stuff like:

import _ from 'lodash'

// Since we don't have control over the creation of the auth services, we need
// to modify the root docs instead.
export default function () {
  const app = this

  // Fix the token refresh path.
  app.docs.paths['/auth/token/refresh'] = app.docs.paths['/auth/token/{id}']
  delete app.docs.paths['/auth/token/{id}']
  delete app.docs.paths['/auth/local/{id}']

  // Merge in docs.
  _.merge(app.docs, {
    paths: {
      '/auth/token': {
        post: {
          description: 'Authenticate with a JWT token.',
          responses: {
            '200': {
              description: 'An authentication response',
              schema: {
                $ref: '#/definitions/authentication'
              }
            }
          }
        }
      },
      '/auth/token/refresh': {
        description: 'Request a refreshed access token.',
        responses: {
          '200': {
            description: 'A refresh response',
            schema: {
              $ref: '#/definitions/refresh'
            }
          }
        }
      },
      '/auth/local': {
        post: {
          description: 'Authenticate with an email and password.',
          responses: {
            '200': {
              description: 'An authentication response',
              schema: {
                $ref: '#/definitions/authentication'
              }
            }
          }
        }
      }
    },
    definitions: {
      local: {
        description: 'The body to send to the local authentication endpoint.',
        type: 'object',
        required: ['email', 'password'],
        properties: {
          email: {
            type: 'string',
            format: 'email',
            description: 'The email address to authenticate.'
          },
          password: {
            type: 'string',
            description: 'The password to authenticate.'
          }
        }
      },
      token: {
        description: 'The body to send to the token authentication endpoint.',
        type: 'object',
        required: ['token'],
        properties: {
          token: {
            type: 'string',
            description: 'The JWT token to authenticate.'
          }
        }
      },
      authentication: {
        description: 'Successful authentication response',
        type: 'object',
        properties: {
          token: {
            type: 'string',
            description: 'The JWT authentication token'
          },
          data: {
            $ref: '#/definitions/user'
          }
        },
        example: {
          token: 'XXX.YYY.ZZZ',
          data: {
            id: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
            username: 'bob',
            email: 'bob@theguy.com',
            createdAt: '2017-03-31T00:03:07.423Z',
            updatedAt: '2017-03-31T00:03:07.423Z'
          }
        }
      },
      tokenPayload: {
        description: 'A token payload',
        type: 'object',
        properties: {
          'id': {type: 'string', description: 'The authenticated user id'},
          'iat': {type: 'integer'},
          'exp': {type: 'integer'},
          'iss': {type: 'string'},
          'token': {type: 'string'}
        },
        example: {
          'id': 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
          'iat': 1490998028,
          'exp': 1491084428,
          'iss': 'action-compass',
          'token': 'XXX.YYY.ZZZ'
        }
      },
      refresh: {
        description: 'Successful refresh response',
        type: 'object',
        properties: {
          'query': {
            type: 'object',
            properties: {
              'token': {type: 'string'}
            }
          },
          'provider': {type: 'string'},
          'token': {type: 'string'},
          'data': {
            $ref: '#/definitions/tokenPayload'
          }
        },
        example: {
          'query': {
            'token': 'XXX.YYY.ZZZ'
          },
          'provider': 'rest',
          'token': 'XXX.YYY.ZZZ',
          'data': {
            'id': 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
            'iat': 1490998028,
            'exp': 1491084428,
            'iss': 'action-compass',
            'token': 'XXX.YYY.ZZZ'
          }
        }
      }
    }
  })

  // Fix tag.
  _.extend(_.find(app.docs.tags, {name: 'auth'}), {
    name: 'Authentication',
    description: 'User Authentication'
  })
}

@daffl
Copy link
Member

daffl commented Apr 3, 2017

Not a bad idea. Let's create a separate issue to keep track of creating defaults for additional existing functionality.

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

Successfully merging this pull request may close these issues.

None yet

2 participants