Skip to content

Commit

Permalink
feat(rest): add disableOASConsolidator option to rest server
Browse files Browse the repository at this point in the history
Signed-off-by: Douglas McConnachie <[email protected]>
  • Loading branch information
dougal83 committed Mar 28, 2020
1 parent 2993ffc commit 0c04248
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ import {
requestBody,
} from '@loopback/openapi-v3';
import {model, property} from '@loopback/repository';
import {expect, validateApiSpec} from '@loopback/testlab';
import {
expect,
givenHttpServerConfig,
validateApiSpec,
} from '@loopback/testlab';
import {
createControllerFactoryForClass,
RestComponent,
RestServer,
RestServerConfig,
} from '../../..';
import {RestTags} from '../../../keys';
import {TestInfoSpecEnhancer} from './fixtures/info.spec.extension';
Expand Down Expand Up @@ -387,6 +392,26 @@ describe('RestServer.getApiSpec()', () => {
expect(spec.info).to.eql(EXPECTED_SPEC_INFO);
});

context('options', () => {
it('disables consolidator if disableOASConsolidator is set to true', async () => {
const options: {rest: RestServerConfig} = {
rest: {openApiSpec: {disableOASConsolidator: true}},
};
options.rest = givenHttpServerConfig(options.rest);
app = new Application(options);
app.component(RestComponent);
server = await app.getServer(RestServer);
await server.start();

// consolidation enhancer to be unset
const enhancer = await server.OASEnhancer.getEnhancerByName(
'loopback.consolidate.schemas',
);
expect(enhancer).to.be.undefined();
await server.stop();
});
});

async function givenApplication() {
app = new Application();
app.component(RestComponent);
Expand Down
10 changes: 9 additions & 1 deletion packages/rest/src/rest.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ export class RestServer extends Context implements Server, HttpServerLike {
* Register core built in OAS Enhancers
*/
registerCoreEnhancers() {
this.add(createBindingFromClass(ConsolidationEnhancer));
if (!this.config.openApiSpec.disableOASConsolidator) {
this.add(createBindingFromClass(ConsolidationEnhancer));
}
}

protected _setupRequestHandlerIfNeeded() {
Expand Down Expand Up @@ -1075,6 +1077,12 @@ export interface OpenApiSpecOptions {
* Set this flag to disable the endpoint for OpenAPI spec
*/
disabled?: true;

/**
* Set this flag to `true` to disable OAS schema consolidation. If not set,
* the value defaults to `false`.
*/
disableOASConsolidator?: boolean;
}

export interface ApiExplorerOptions {
Expand Down

0 comments on commit 0c04248

Please sign in to comment.