diff --git a/lib/components/JsonSchema/json-schema.html b/lib/components/JsonSchema/json-schema.html index d1377c59..e764f016 100644 --- a/lib/components/JsonSchema/json-schema.html +++ b/lib/components/JsonSchema/json-schema.html @@ -11,7 +11,7 @@
{{prop._name}} | @@ -28,7 +28,7 @@|
-
|
diff --git a/lib/components/JsonSchema/json-schema.js b/lib/components/JsonSchema/json-schema.js
index 4434b935..05e964af 100644
--- a/lib/components/JsonSchema/json-schema.js
+++ b/lib/components/JsonSchema/json-schema.js
@@ -11,7 +11,7 @@ import JsonPointer from '../../utils/JsonPointer';
templateUrl: './lib/components/JsonSchema/json-schema.html',
styleUrls: ['./lib/components/JsonSchema/json-schema.css'],
directives: [JsonSchema, Tabs, Tab],
- inputs: ['isArray', 'final', 'nestOdd']
+ inputs: ['isArray', 'final', 'nestOdd', 'childFor']
})
@Reflect.metadata('parameters', [[SchemaManager], [ElementRef]])
export default class JsonSchema extends BaseComponent {
@@ -27,6 +27,8 @@ export default class JsonSchema extends BaseComponent {
subSchema.active = false;
});
subClass.active = true;
+ this.derivedEmtpy = false;
+ if (subClass.empty) this.derivedEmtpy = true;
}
unwrapArray(schema) {
@@ -54,13 +56,13 @@ export default class JsonSchema extends BaseComponent {
runInjectors(schema, schema, schema._pointer || this.pointer);
schema.derived = schema.derived || [];
- if (schema.derived.length) schema.derived[0].active = true;
if (!schema.isTrivial) {
this.prepareObjectPropertiesData(schema);
}
this.schema = schema;
+ if (schema.derived.length) this.selectDerived(schema.derived[0]);
}
prepareObjectPropertiesData(schema) {
@@ -74,9 +76,16 @@ export default class JsonSchema extends BaseComponent {
let propertySchema = schema.properties[prop];
let propPointer = JsonPointer.join(schema._pointer || this.pointer, ['properties', prop]);
propertySchema = JsonSchema.injectPropertyData(propertySchema, prop, propPointer);
+ // stop endless discriminator recursion
+ if (propertySchema._pointer === this.childFor) {
+ propertySchema._pointer = null;
+ }
propertySchema.required = !!requiredMap[prop];
propertySchema.isDiscriminator = (schema.discriminator === prop);
- if (propertySchema.isDiscriminator) discriminatorFieldIdx = idx;
+ if (propertySchema.isDiscriminator) {
+ discriminatorFieldIdx = idx;
+ propertySchema.enum = null;
+ }
return propertySchema;
});
// Move discriminator field to the end of properties list
diff --git a/lib/components/JsonSchema/json-schema.scss b/lib/components/JsonSchema/json-schema.scss
index e32c0628..a24d883f 100644
--- a/lib/components/JsonSchema/json-schema.scss
+++ b/lib/components/JsonSchema/json-schema.scss
@@ -61,6 +61,12 @@ json-schema[nesteven="true"] {
> .params-wrap > .param:first-of-type > .param-name:before, > .params-wrap > .param:last-of-type > .param-name:after {
border-color: $side-menu-active-bg-color;
}
+
+ > .params-wrap > .param:last-of-type, > .params-wrap > .param.last {
+ > .param-name:after {
+ border-color: $side-menu-active-bg-color;
+ }
+ }
}
.param.complex > .param-info {
@@ -128,9 +134,14 @@ json-schema[nesteven="true"] {
.discriminator-info {
font-weight: $regular;
margin-bottom: 10px;
+
+ > span {
+ font-size: 0.9em;
+ font-weight: $light;
+ }
}
-.discriminator-wrap > td {
+.discriminator-wrap:not(.empty) > td {
//border-left: $line-border;
padding: 0;
position: relative;
diff --git a/lib/utils/SchemaManager.js b/lib/utils/SchemaManager.js
index b3f9dca4..3ba6f650 100644
--- a/lib/utils/SchemaManager.js
+++ b/lib/utils/SchemaManager.js
@@ -179,7 +179,11 @@ export default class SchemaManager {
});
if (idx < 0) continue;
- res.push({name: defName, $ref: `#/definitions/${defName}`});
+ let empty = false;
+ if (subTypes.length === 1) {
+ empty = true;
+ }
+ res.push({name: defName, $ref: `#/definitions/${defName}`, empty});
}
return res;
}
diff --git a/package.json b/package.json
index f76e15a8..38e974ba 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "redoc",
"description": "Swagger-generated API Reference Documentation",
- "version": "0.7.11",
+ "version": "0.7.12",
"repository": {
"type": "git",
"url": "git://github.com/Rebilly/ReDoc"
@@ -15,7 +15,8 @@
"branch-release": "git reset --hard && branch-release",
"unit": "gulp test",
"e2e": "gulp e2e",
- "deploy": "build/prepare_deploy.sh && deploy-to-gh-pages demo"
+ "deploy": "build/prepare_deploy.sh && deploy-to-gh-pages demo",
+ "github-release": "gulp github-release"
},
"keywords": [
"OpenAPI",
diff --git a/tests/unit/SchemaManager.spec.js b/tests/unit/SchemaManager.spec.js
index 1ec4ec87..e436093d 100644
--- a/tests/unit/SchemaManager.spec.js
+++ b/tests/unit/SchemaManager.spec.js
@@ -238,7 +238,7 @@ describe('Utils', () => {
let deriveDefs = schemaMgr.findDerivedDefinitions('#/definitions/Pet');
deriveDefs.should.be.instanceof(Array);
deriveDefs.should.not.be.empty();
- deriveDefs.should.be.deepEqual([{name: 'Cat', $ref: '#/definitions/Cat'}, {name: 'Dog', $ref: '#/definitions/Dog'}]);
+ deriveDefs.should.be.deepEqual([{name: 'Cat', empty: false, $ref: '#/definitions/Cat'}, {name: 'Dog', empty: false, $ref: '#/definitions/Dog'}]);
});
it('should return emtpy array for definitions that dont have discriminator', () => {