Skip to content

Commit

Permalink
test: test for @api decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
nabdelgadir committed May 16, 2019
1 parent d38df35 commit 1734293
Showing 1 changed file with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import {model, property} from '@loopback/repository';
import {expect} from '@loopback/testlab';
import {
api,
ControllerSpec,
get,
getControllerSpec,
Expand Down Expand Up @@ -332,6 +333,66 @@ describe('controller spec', () => {
expect(globalSchemas).to.be.empty();
});

it('allows a class to provide definitions of referenced models through #/components/schemas', () => {
@api({
paths: {
'/todos': {
get: {
'x-operation-name': 'find',
'x-controller-name': 'MyController',
responses: {
'200': {
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/Todo',
},
},
},
},
},
},
},
},
components: {
schemas: {
Todo: {
title: 'Todo',
properties: {
title: {
type: 'string',
},
},
},
},
},
})
class MyController {
async find(): Promise<object[]> {
return []; // dummy implementation, it's never called
}
}

const spec = getControllerSpec(MyController);
const opSpec: OperationObject = spec.paths['/todos'].get;
const responseSpec = opSpec.responses['200'].content['application/json'];
expect(responseSpec.schema).to.deepEqual({
$ref: '#/components/schemas/Todo',
});

const globalSchemas = (spec.components || {}).schemas;
expect(globalSchemas).to.deepEqual({
Todo: {
title: 'Todo',
properties: {
title: {
type: 'string',
},
},
},
});
});

describe('x-ts-type', () => {
@model()
class MyModel {
Expand Down

0 comments on commit 1734293

Please sign in to comment.