Skip to content

Commit

Permalink
Merge d8e4a84 into 4e653bb
Browse files Browse the repository at this point in the history
  • Loading branch information
derdeka committed Sep 6, 2019
2 parents 4e653bb + d8e4a84 commit 522b669
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
Expand Up @@ -3,7 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {OperationObject} from '@loopback/rest';
import {OperationObject, OpenApiSpec} from '@loopback/rest';
import {Client, expect} from '@loopback/testlab';
import * as _ from 'lodash';
import {
Expand Down Expand Up @@ -189,4 +189,30 @@ describe('booter-lb3app', () => {
await client.get('/coffee').expect(404);
});
});

context('using specTransformer to modify OpenAPI spec', () => {
before(async () => {
({app, client} = await setupApplication({
lb3app: {
path: '../fixtures/lb3app/server/server',
specTransformer: (spec: OpenApiSpec): OpenApiSpec =>
_.merge(spec, {
paths: {
'/CoffeeShops': {
post: {
summary: 'just a very simple modification',
},
},
},
}),
},
}));
});

it('does apply the spec modification', () => {
const spec = app.restServer.getApiSpec();
const createOp: OperationObject = spec.paths['/api/CoffeeShops'].post;
expect(createOp.summary).to.eql('just a very simple modification');
});
});
});
7 changes: 6 additions & 1 deletion packages/booter-lb3app/src/lb3app.booter.ts
Expand Up @@ -101,7 +101,11 @@ export class Lb3AppBooter implements Booter {
// swagger2openapi options
});

return result.openapi as OpenApiSpec;
let spec = result.openapi as OpenApiSpec;
if (typeof this.options.specTransformer === 'function') {
spec = this.options.specTransformer(spec);
}
return spec;
}

private mountFullApp(lb3App: Lb3Application, spec: OpenApiSpec) {
Expand All @@ -128,6 +132,7 @@ export interface Lb3AppBooterOptions {
path: string;
mode: 'fullApp' | 'restRouter';
restApiRoot: string;
specTransformer?: (spec: OpenApiSpec) => OpenApiSpec;
}

interface Lb3Application extends ExpressApplication {
Expand Down

0 comments on commit 522b669

Please sign in to comment.