From 256583bdb59ea3818f35622c365df9d4250f19b3 Mon Sep 17 00:00:00 2001 From: Anna Bodnia Date: Fri, 5 Feb 2016 16:02:01 +0200 Subject: [PATCH] tests #1186 Render primitive types in "Response Class" --- .../javascript/view/partials/signature.js | 4 +-- test/unit/view/partials/signatureSpec.js | 35 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/main/javascript/view/partials/signature.js b/src/main/javascript/view/partials/signature.js index c99a7c0d..1e7fbd77 100644 --- a/src/main/javascript/view/partials/signature.js +++ b/src/main/javascript/view/partials/signature.js @@ -745,8 +745,8 @@ SwaggerUi.partials.signature = (function () { switch (type) { case 'object': return 'Object is not a primitive'; - case 'array' : return 'Array[' + items.type + ']'; - default: return type; + case 'array' : return 'Array[' + (items.format || items.type) + ']'; + default: return schema.format || type; } }; diff --git a/test/unit/view/partials/signatureSpec.js b/test/unit/view/partials/signatureSpec.js index b170216d..64ebaacd 100644 --- a/test/unit/view/partials/signatureSpec.js +++ b/test/unit/view/partials/signatureSpec.js @@ -650,4 +650,39 @@ describe('SwaggerUi.partials.signature tests', function () { }); }); }); + + describe('method getPrimitiveSignature', function () { + it('returns warning message when type is object', function () { + expect(sut.getPrimitiveSignature({type: 'object'})).to.equal('Object is not a primitive'); + }); + + it('returns array with items.format when passing array', function () { + var schema = { + type: 'array', + items: { + format: 'format', + type: 'type' + } + }; + expect(sut.getPrimitiveSignature(schema)).to.equal('Array[format]'); + }); + + it('returns array with items.type when passing array without items.format', function () { + var schema = { + type: 'array', + items: { + type: 'type' + } + }; + expect(sut.getPrimitiveSignature(schema)).to.equal('Array[type]'); + }); + + it('returns format of primitive', function () { + expect(sut.getPrimitiveSignature({type: 'type', format: 'format'})).to.equal('format'); + }); + + it('returns type of primitive if format is not passed', function () { + expect(sut.getPrimitiveSignature({type: 'type'})).to.equal('type'); + }); + }); });