Skip to content

Commit

Permalink
Add special representation for enum with one value (fixes #70)
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanHotsiy committed Aug 12, 2016
1 parent 0b46186 commit cde5eb5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lib/components/JsonSchema/json-schema.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@
}">
<td class="param-name">
<span class="param-name-wrap" (click)="subSchema.toggle()">
<span class="param-name-content" >{{prop._name}}</span>
<span class="param-name-content">
{{prop._name}}
<span class="param-enum-value" [hidden]="!prop._enumItem"> {{prop._enumItem?.val | json}} </span>
</span>
<svg *ngIf="prop._pointer" xmlns="http://www.w3.org/2000/svg" version="1.1" x="0" y="0" viewBox="0 0 24 24" xml:space="preserve">
<polygon points="17.3 8.3 12 13.6 6.7 8.3 5.3 9.7 12 16.4 18.7 9.7 "/>
</svg>
Expand Down
9 changes: 9 additions & 0 deletions lib/components/JsonSchema/json-schema.scss
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,12 @@ li:before {
}
}
}

.param-enum-value {
padding: 2px;
background-color: #e6ebf6;

&:before {
content: " = ";
}
}
4 changes: 2 additions & 2 deletions lib/components/JsonSchema/json-schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '#';
(<any>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 >');
});
});
});
Expand Down
4 changes: 4 additions & 0 deletions lib/services/schema-helper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit cde5eb5

Please sign in to comment.