Skip to content

Commit

Permalink
Merge branch 'patch-1' of https://github.com/tiholic/swagger into tih…
Browse files Browse the repository at this point in the history
…olic-patch-1
  • Loading branch information
kamilmysliwiec committed Oct 24, 2024
2 parents 1a0e944 + bbb112d commit c951592
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 3 deletions.
52 changes: 52 additions & 0 deletions e2e/api-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,58 @@
}
]
}
},
"/api/cats/download": {
"get": {
"responses": {
"200": {
"description": "binary file for download",
"content": {
"application/pdf": {
"schema": {
"type": "string",
"format": "binary"
}
},
"image/jpeg": {
"schema": {
"type": "string",
"format": "binary"
}
}
}
}
},
"tags": [
"cats"
],
"security": [
{
"key2": [],
"key1": []
},
{
"bearer": []
},
{
"basic": []
}
],
"operationId": "CatsController_download",
"summary": "",
"parameters": [
{
"name": "header",
"in": "header",
"description": "Test",
"required": false,
"schema": {
"default": "test",
"type": "string"
}
}
]
}
}
},
"info": {
Expand Down
14 changes: 14 additions & 0 deletions e2e/src/cats/cats.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,18 @@ export class CatsController {
maxLength: 100
} as any)
getWithRandomQuery(@Query('type') type: string) {}

@Get('download')
@ApiOperation({
responses: {
'200': {
description: 'binary file for download',
content: {
'application/pdf': { schema: { type: 'string', format: 'binary' } },
'image/jpeg': { schema: { type: 'string', format: 'binary' } }
}
}
}
})
download() {}
}
15 changes: 15 additions & 0 deletions e2e/validate-schema.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,19 @@ describe('Validate OpenAPI schema', () => {
expect(api.components.schemas).toHaveProperty('Person');
expect(api.components.schemas).toHaveProperty('Cat');
});

it('should consider explicit config over auto-detected schema', async () => {
const document = SwaggerModule.createDocument(app, options);
expect(document.paths['/api/cats/download'].get.responses).toEqual({
'200': {
description: 'binary file for download',
content: {
'application/pdf': {
schema: { type: 'string', format: 'binary' }
},
'image/jpeg': { schema: { type: 'string', format: 'binary' } }
}
}
})
});
});
6 changes: 3 additions & 3 deletions lib/swagger-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export class SwaggerTransformer {
({ root }: Record<'root', any>) => root.method
);
return mapValues(keyByMethod, (route: any) => {
return {
...omit(route.root, ['method', 'path']),
...omit(route, 'root')
return {
...omit(route, 'root'),
...omit(route.root, ['method', 'path'])
};
});
});
Expand Down

0 comments on commit c951592

Please sign in to comment.