From cde5eb534a763791a6a77204bcfe3ded656c74f2 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Fri, 12 Aug 2016 20:41:58 +0300 Subject: [PATCH] Add special representation for enum with one value (fixes #70) --- lib/components/JsonSchema/json-schema.html | 5 ++++- lib/components/JsonSchema/json-schema.scss | 9 +++++++++ lib/components/JsonSchema/json-schema.spec.ts | 4 ++-- lib/services/schema-helper.service.ts | 4 ++++ package.json | 2 +- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/components/JsonSchema/json-schema.html b/lib/components/JsonSchema/json-schema.html index 4c2ec784..dabb35da 100644 --- a/lib/components/JsonSchema/json-schema.html +++ b/lib/components/JsonSchema/json-schema.html @@ -54,7 +54,10 @@ }"> - {{prop._name}} + + {{prop._name}} + {{prop._enumItem?.val | json}} + diff --git a/lib/components/JsonSchema/json-schema.scss b/lib/components/JsonSchema/json-schema.scss index b5ee3338..a28431ad 100644 --- a/lib/components/JsonSchema/json-schema.scss +++ b/lib/components/JsonSchema/json-schema.scss @@ -223,3 +223,12 @@ li:before { } } } + +.param-enum-value { + padding: 2px; + background-color: #e6ebf6; + + &:before { + content: " = "; + } +} diff --git a/lib/components/JsonSchema/json-schema.spec.ts b/lib/components/JsonSchema/json-schema.spec.ts index 1d633b10..65fed134 100644 --- a/lib/components/JsonSchema/json-schema.spec.ts +++ b/lib/components/JsonSchema/json-schema.spec.ts @@ -44,13 +44,13 @@ describe('Redoc components', () => { component.schema.isTrivial.should.be.true(); }); - it('should use < * > notation for prop without type', () => { + it('should use < anything > notation for prop without type', () => { component.pointer = '#'; (specMgr)._schema = {type: 'object', properties: { test: {} }}; fixture.detectChanges(); - component.schema._properties[0]._displayType.should.be.equal('< * >'); + component.schema._properties[0]._displayType.should.be.equal('< anything >'); }); }); }); diff --git a/lib/services/schema-helper.service.ts b/lib/services/schema-helper.service.ts index b39c077a..1e761c93 100644 --- a/lib/services/schema-helper.service.ts +++ b/lib/services/schema-helper.service.ts @@ -49,6 +49,10 @@ const injectors = { injectTo.enum = propertySchema.enum.map((value) => { return {val: value, type: typeof value}; }); + if (propertySchema.enum && propertySchema.enum.length === 1) { + injectTo._enumItem = propertySchema.enum[0]; + injectTo.enum = null; + } } } }, diff --git a/package.json b/package.json index e123f48f..bf611484 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "redoc", "description": "Swagger-generated API Reference Documentation", - "version": "1.0.1", + "version": "1.1.0", "repository": { "type": "git", "url": "git://github.com/Rebilly/ReDoc"