mirror of
https://github.com/Redocly/redoc.git
synced 2025-01-31 10:04:08 +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 class="param-info">
|
||||
<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}}
|
||||
<span class="param-range" *ngIf="prop._range"> {{prop._range}} </span>
|
||||
</span>
|
||||
|
|
|
@ -17,4 +17,19 @@ describe('Spec Helper', () => {
|
|||
(<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';
|
||||
|
||||
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 => {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user