mirror of
https://github.com/Redocly/redoc.git
synced 2025-02-07 21:40:32 +03:00
Add safe guards array without items (fixes #199)
This commit is contained in:
parent
ee36392164
commit
5f909cac47
|
@ -68,7 +68,7 @@
|
||||||
</td>
|
</td>
|
||||||
<td class="param-info">
|
<td class="param-info">
|
||||||
<div>
|
<div>
|
||||||
<span class="param-type {{prop.type}}" [ngClass]="{'with-hint': prop._displayTypeHint, 'tuple': prop._isTuple}"
|
<span class="param-type {{prop.type}}" [ngClass]="{'with-hint': prop._displayTypeHint, 'tuple': prop._isTuple, 'array': prop._isArray}"
|
||||||
title="{{prop._displayTypeHint}}"> {{prop._displayType}} {{prop._displayFormat}}
|
title="{{prop._displayTypeHint}}"> {{prop._displayType}} {{prop._displayFormat}}
|
||||||
<span class="param-range" *ngIf="prop._range"> {{prop._range}} </span>
|
<span class="param-range" *ngIf="prop._range"> {{prop._range}} </span>
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -17,4 +17,19 @@ describe('Spec Helper', () => {
|
||||||
(<jasmine.Spy>console.warn).and.callThrough();
|
(<jasmine.Spy>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();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { WarningsService } from './warnings.service';
|
||||||
import * as slugify from 'slugify';
|
import * as slugify from 'slugify';
|
||||||
|
|
||||||
interface PropertyPreprocessOptions {
|
interface PropertyPreprocessOptions {
|
||||||
childFor: string;
|
childFor?: string;
|
||||||
skipReadOnly?: boolean;
|
skipReadOnly?: boolean;
|
||||||
discriminator?: string;
|
discriminator?: string;
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,7 @@ const injectors = {
|
||||||
return propertySchema.type === 'array' && !Array.isArray(propertySchema.items);
|
return propertySchema.type === 'array' && !Array.isArray(propertySchema.items);
|
||||||
},
|
},
|
||||||
inject: (injectTo, propertySchema = injectTo, propPointer) => {
|
inject: (injectTo, propertySchema = injectTo, propPointer) => {
|
||||||
|
if (!propertySchema.items) propertySchema.items = {};
|
||||||
if (!(SchemaHelper.detectType(propertySchema.items) === 'object')) {
|
if (!(SchemaHelper.detectType(propertySchema.items) === 'object')) {
|
||||||
injectTo._isArray = true;
|
injectTo._isArray = true;
|
||||||
injectTo._pointer = propertySchema.items._pointer
|
injectTo._pointer = propertySchema.items._pointer
|
||||||
|
@ -207,7 +208,11 @@ export class SchemaHelper {
|
||||||
static preprocessProperties(schema:any, pointer:string, opts: PropertyPreprocessOptions) {
|
static preprocessProperties(schema:any, pointer:string, opts: PropertyPreprocessOptions) {
|
||||||
let requiredMap = {};
|
let requiredMap = {};
|
||||||
if (schema.required) {
|
if (schema.required) {
|
||||||
|
if (Array.isArray(schema.required)) {
|
||||||
schema.required.forEach(prop => requiredMap[prop] = true);
|
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 => {
|
let props = schema.properties && Object.keys(schema.properties).map(propName => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user