Skip to content

Commit

Permalink
run yarn format
Browse files Browse the repository at this point in the history
  • Loading branch information
yamishav committed Apr 27, 2020
1 parent 891be8c commit 082ce93
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 24 deletions.
52 changes: 28 additions & 24 deletions src/generateSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ export function getOperation(route: IRoute): oa.OperationObject {
const operation: oa.OperationObject = {
operationId: getOperationId(route),
parameters: [
... getHeaderParams(route),
... getPathParams(route),
... getQueryParams(route)
...getHeaderParams(route),
...getPathParams(route),
...getQueryParams(route)
],
requestBody: getRequestBody(route) || undefined,
responses: getResponses(route),
Expand Down Expand Up @@ -64,7 +64,7 @@ export function getPaths(routes: IRoute[]): oa.PathObject {
}))

// @ts-ignore: array spread
return _.merge(... routePaths)
return _.merge(...routePaths)
}

/**
Expand Down Expand Up @@ -127,7 +127,7 @@ export function getPathParams(route: IRoute): oa.ParameterObject[] {
if (meta) {
const metaSchema = getParamSchema(meta)
param.schema =
'type' in metaSchema ? { ... param.schema, ... metaSchema }: metaSchema
'type' in metaSchema ? { ...param.schema, ...metaSchema } : metaSchema
}

return param
Expand Down Expand Up @@ -173,26 +173,26 @@ export function getRequestBody(route: IRoute): oa.RequestBodyObject | void {
const bodyParamsSchema: oa.SchemaObject | null =
bodyParamMetas.length > 0
? bodyParamMetas.reduce(
(acc: oa.SchemaObject, d) => ({
... acc,
properties: {
... acc.properties,
[d.name!]: getParamSchema(d)
},
required: isRequired(d, route)
? [... (acc.required || []), d.name!]
: acc.required
}),
{ properties: {}, required: [], type: 'object' }
)
(acc: oa.SchemaObject, d) => ({
...acc,
properties: {
...acc.properties,
[d.name!]: getParamSchema(d)
},
required: isRequired(d, route)
? [...(acc.required || []), d.name!]
: acc.required
}),
{ properties: {}, required: [], type: 'object' }
)
: null

const bodyMeta = route.params.find(d => d.type === 'body')

if (bodyMeta) {
const bodySchema = getParamSchema(bodyMeta)
const { $ref } =
'items' in bodySchema && bodySchema.items ? bodySchema.items: bodySchema
'items' in bodySchema && bodySchema.items ? bodySchema.items : bodySchema

return {
content: {
Expand Down Expand Up @@ -221,15 +221,15 @@ export function getContentType(route: IRoute): string {
? 'application/json'
: 'text/html; charset=utf-8'
const contentMeta = _.find(route.responseHandlers, { type: 'content-type' })
return contentMeta ? contentMeta.value: defaultContentType
return contentMeta ? contentMeta.value : defaultContentType
}

/**
* Return the status code of given route.
*/
export function getStatusCode(route: IRoute): string {
const successMeta = _.find(route.responseHandlers, { type: 'success-code' })
return successMeta ? successMeta.value + '': '200'
return successMeta ? successMeta.value + '' : '200'
}

/**
Expand Down Expand Up @@ -279,7 +279,7 @@ export function getTags(route: IRoute): string[] {
export function expressToOpenAPIPath(expressPath: string) {
const tokens = pathToRegexp.parse(expressPath)
return tokens
.map(d => (_.isString(d) ? d: `${d.prefix}{${d.name}}`))
.map(d => (_.isString(d) ? d : `${d.prefix}{${d.name}}`))
.join('')
}

Expand All @@ -289,7 +289,7 @@ export function expressToOpenAPIPath(expressPath: string) {
*/
function isRequired(meta: { required?: boolean }, route: IRoute) {
const globalRequired = _.get(route.options, 'defaults.paramOptions.required')
return globalRequired ? meta.required !== false: !!meta.required
return globalRequired ? meta.required !== false : !!meta.required
}

/**
Expand All @@ -300,8 +300,12 @@ function getParamSchema(
param: ParamMetadataArgs
): oa.SchemaObject | oa.ReferenceObject {
const { explicitType, index, object, method } = param
const reflectedTypes = Reflect.getMetadata('design:paramtypes', object, method);
if (reflectedTypes.length <= index) return {};
const reflectedTypes = Reflect.getMetadata(
'design:paramtypes',
object,
method
)
if (reflectedTypes.length <= index) return {}
const type = reflectedTypes[index]
if (_.isFunction(type) && type.name === 'Array') {
const items = explicitType
Expand Down
32 changes: 32 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,11 @@ convert-source-map@^1.4.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.5.0.tgz#9acd70851c6d5dfdd93d9282e5edf94a03ff46b5"

cookie@^0.4.0:
version "0.4.1"
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.4.1.tgz#afd713fe26ebd21ba95ceb61f9a8116e50a537d1"
integrity sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA==

copy-descriptor@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d"
Expand Down Expand Up @@ -1275,6 +1280,18 @@ glob@^7.1.3:
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@^7.1.4:
version "7.1.6"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6"
integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==
dependencies:
fs.realpath "^1.0.0"
inflight "^1.0.4"
inherits "2"
minimatch "^3.0.4"
once "^1.3.0"
path-is-absolute "^1.0.0"

globals@^11.1.0:
version "11.12.0"
resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e"
Expand Down Expand Up @@ -2845,6 +2862,16 @@ rimraf@^3.0.0:
dependencies:
glob "^7.1.3"

routing-controllers@^0.8.0:
version "0.8.1"
resolved "https://registry.yarnpkg.com/routing-controllers/-/routing-controllers-0.8.1.tgz#d53c35e05d0f0863ee25bd77c3fe41fc09fa39f5"
integrity sha512-dOgt0kiriKMH1swenPX73tU3Mxvlb+1N/sFLSgEpwbK314POrQF+dJGOZVoKv2ya5do1k4aUzSV5xi0K3ykdyw==
dependencies:
cookie "^0.4.0"
glob "^7.1.4"
reflect-metadata "^0.1.13"
template-url "^1.0.0"

rsvp@^4.8.4:
version "4.8.5"
resolved "https://registry.yarnpkg.com/rsvp/-/rsvp-4.8.5.tgz#c8f155311d167f68f21e168df71ec5b083113734"
Expand Down Expand Up @@ -3181,6 +3208,11 @@ [email protected]:
stream-events "^1.0.5"
uuid "^3.3.2"

template-url@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/template-url/-/template-url-1.0.0.tgz#d9456bee70cac6617b462a7b08db29fb813a0b09"
integrity sha1-2UVr7nDKxmF7Rip7CNsp+4E6Cwk=

test-exclude@^5.2.3:
version "5.2.3"
resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-5.2.3.tgz#c3d3e1e311eb7ee405e092dac10aefd09091eac0"
Expand Down

0 comments on commit 082ce93

Please sign in to comment.