Skip to content

Commit

Permalink
fixup! apply feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nabdelgadir committed May 16, 2019
1 parent 1734293 commit 8172c46
Showing 1 changed file with 187 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,188 +208,246 @@ describe('controller spec', () => {
});
});

it('allows operations to provide definition of referenced models through #/components/schema', () => {
class MyController {
@get('/todos', {
responses: {
'200': {
description: 'Array of Category model instances',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/Todo',
definitions: {
Todo: {
title: 'Todo',
properties: {
title: {type: 'string'},
context('reference models via spec', () => {
it('allows operations to provide definitions of referenced models through #/components/schema', () => {
class MyController {
@get('/todos', {
responses: {
'200': {
description: 'Array of Category model instances',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/Todo',
definitions: {
Todo: {
title: 'Todo',
properties: {
title: {type: 'string'},
},
},
},
},
},
},
},
},
},
})
async find(): Promise<object[]> {
return []; // dummy implementation, it's never called
})
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 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',
const globalSchemas = (spec.components || {}).schemas;
expect(globalSchemas).to.deepEqual({
Todo: {
title: 'Todo',
properties: {
title: {
type: 'string',
},
},
},
},
});
});
});

it('allows operations to provide definition of referenced models through #/definitions', () => {
class MyController {
@get('/todos', {
responses: {
'200': {
description: 'Array of Category model instances',
content: {
'application/json': {
schema: {
$ref: '#/definitions/Todo',
definitions: {
Todo: {
title: 'Todo',
properties: {
title: {type: 'string'},
it('allows operations to provide definitions of referenced models through #/definitions', () => {
class MyController {
@get('/todos', {
responses: {
'200': {
description: 'Array of Category model instances',
content: {
'application/json': {
schema: {
$ref: '#/definitions/Todo',
definitions: {
Todo: {
title: 'Todo',
properties: {
title: {type: 'string'},
},
},
},
},
},
},
},
},
},
})
async find(): Promise<object[]> {
return []; // dummy implementation, it's never called
})
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: '#/definitions/Todo',
});
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: '#/definitions/Todo',
});

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

it('returns an empty object when it cannot find definition of referenced model', () => {
class MyController {
@get('/todos', {
responses: {
'200': {
description: 'Array of Category model instances',
content: {
'application/json': {
schema: {
$ref: '#/definitions/Todo',
definitions: {},
it('returns undefined when it cannot find definition of referenced model', () => {
class MyController {
@get('/todos', {
responses: {
'200': {
description: 'Array of Category model instances',
content: {
'application/json': {
schema: {
$ref: '#/definitions/Todo',
},
},
},
},
},
})
async find(): Promise<object[]> {
return []; // dummy implementation, it's never called
}
}

const spec = getControllerSpec(MyController);
const globalSchemas = (spec.components || {}).schemas;
expect(globalSchemas).to.be.undefined();
});

it('gets definition from outside the method decorator when it is not provided', () => {
@api({
paths: {},
components: {
schemas: {
Todo: {
title: 'Todo',
properties: {
title: {
type: 'string',
},
},
},
},
},
})
async find(): Promise<object[]> {
return []; // dummy implementation, it's never called
class MyController {
@get('/todos', {
responses: {
'200': {
description: 'Array of Category model instances',
content: {
'application/json': {
schema: {
$ref: '#/definitions/Todo',
definitions: {},
},
},
},
},
},
})
async find(): Promise<object[]> {
return []; // dummy implementation, it's never called
}
}
}

const spec = getControllerSpec(MyController);
const globalSchemas = (spec.components || {}).schemas;
expect(globalSchemas).to.be.empty();
});
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: '#/definitions/Todo',
});

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',
const globalSchemas = (spec.components || {}).schemas;
expect(globalSchemas).to.deepEqual({
Todo: {
title: 'Todo',
properties: {
title: {
type: 'string',
},
},
},
});
});

it('allows a class to reference schemas at @api level', () => {
@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',
components: {
schemas: {
Todo: {
title: 'Todo',
properties: {
title: {
type: 'string',
},
},
},
},
},
},
})
class MyController {
async find(): Promise<object[]> {
return []; // dummy implementation, it's never called
})
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 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',
const globalSchemas = (spec.components || {}).schemas;
expect(globalSchemas).to.deepEqual({
Todo: {
title: 'Todo',
properties: {
title: {
type: 'string',
},
},
},
},
});
});
});

Expand Down

0 comments on commit 8172c46

Please sign in to comment.