diff --git a/lib/components/JsonSchema/json-schema.html b/lib/components/JsonSchema/json-schema.html
index da41e5f4..c60b7a28 100644
--- a/lib/components/JsonSchema/json-schema.html
+++ b/lib/components/JsonSchema/json-schema.html
@@ -68,7 +68,7 @@
- {{prop._displayType}} {{prop._displayFormat}}
{{prop._range}}
diff --git a/lib/services/schema-helper.service.spec.ts b/lib/services/schema-helper.service.spec.ts
index 041bfe59..46c43a49 100644
--- a/lib/services/schema-helper.service.spec.ts
+++ b/lib/services/schema-helper.service.spec.ts
@@ -17,4 +17,19 @@ describe('Spec Helper', () => {
(console.warn).and.callThrough();
});
});
+
+ describe('preprocessProperties', () => {
+ it('should not throw when type array and items are not defined', () => {
+ let schema = {
+ type: 'object',
+ properties: {
+ prop1: {
+ type: 'array'
+ }
+ }
+ };
+
+ (() => SchemaHelper.preprocessProperties(schema, '#/', {})).should.not.throw();
+ });
+ });
});
diff --git a/lib/services/schema-helper.service.ts b/lib/services/schema-helper.service.ts
index 3fc16333..613b85f3 100644
--- a/lib/services/schema-helper.service.ts
+++ b/lib/services/schema-helper.service.ts
@@ -5,7 +5,7 @@ import { WarningsService } from './warnings.service';
import * as slugify from 'slugify';
interface PropertyPreprocessOptions {
- childFor: string;
+ childFor?: string;
skipReadOnly?: boolean;
discriminator?: string;
}
@@ -54,6 +54,7 @@ const injectors = {
return propertySchema.type === 'array' && !Array.isArray(propertySchema.items);
},
inject: (injectTo, propertySchema = injectTo, propPointer) => {
+ if (!propertySchema.items) propertySchema.items = {};
if (!(SchemaHelper.detectType(propertySchema.items) === 'object')) {
injectTo._isArray = true;
injectTo._pointer = propertySchema.items._pointer
@@ -207,7 +208,11 @@ export class SchemaHelper {
static preprocessProperties(schema:any, pointer:string, opts: PropertyPreprocessOptions) {
let requiredMap = {};
if (schema.required) {
- schema.required.forEach(prop => requiredMap[prop] = true);
+ if (Array.isArray(schema.required)) {
+ schema.required.forEach(prop => requiredMap[prop] = true);
+ } else {
+ WarningsService.warn(`required must be an array: "${typeof schema.required}" found at ${pointer}`);
+ }
}
let props = schema.properties && Object.keys(schema.properties).map(propName => {
diff --git a/lib/services/schema-normalizer.service.ts b/lib/services/schema-normalizer.service.ts
index 61cd728b..433d03a8 100644
--- a/lib/services/schema-normalizer.service.ts
+++ b/lib/services/schema-normalizer.service.ts
@@ -29,7 +29,7 @@ export class SchemaNormalizer {
if (opts.childFor) this._dereferencer.visit(opts.childFor);
if (schema['x-redoc-normalized']) return schema;
- let res = SchemaWalker.walk(schema, ptr, (subSchema, ptr) => {
+ let res = SchemaWalker.walk(schema, ptr, (subSchema, ptr) => {
let resolved = this._dereferencer.dereference(subSchema, ptr);
if (resolved.allOf) {
resolved._pointer = resolved._pointer || ptr;
|