mirror of
https://github.com/Redocly/redoc.git
synced 2025-02-16 18:00:33 +03:00
parent
597688e720
commit
97e16208d5
|
@ -104,7 +104,7 @@ export class SchemaModel {
|
||||||
this.constraints = humanizeConstraints(schema);
|
this.constraints = humanizeConstraints(schema);
|
||||||
this.displayType = this.type;
|
this.displayType = this.type;
|
||||||
this.displayFormat = this.format;
|
this.displayFormat = this.format;
|
||||||
this.isPrimitive = isPrimitiveType(schema);
|
this.isPrimitive = isPrimitiveType(schema, this.type);
|
||||||
this.default = schema.default;
|
this.default = schema.default;
|
||||||
this.readOnly = !!schema.readOnly;
|
this.readOnly = !!schema.readOnly;
|
||||||
this.writeOnly = !!schema.writeOnly;
|
this.writeOnly = !!schema.writeOnly;
|
||||||
|
|
|
@ -187,6 +187,17 @@ describe('Utils', () => {
|
||||||
};
|
};
|
||||||
expect(isPrimitiveType(schema)).toEqual(false);
|
expect(isPrimitiveType(schema)).toEqual(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should work with externally provided type', () => {
|
||||||
|
const schema = {
|
||||||
|
properties: {
|
||||||
|
a: {
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
expect(isPrimitiveType(schema, 'object')).toEqual(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('openapi mergeParams', () => {
|
describe('openapi mergeParams', () => {
|
||||||
|
|
|
@ -105,18 +105,18 @@ export function detectType(schema: OpenAPISchema): string {
|
||||||
return 'any';
|
return 'any';
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isPrimitiveType(schema: OpenAPISchema) {
|
export function isPrimitiveType(schema: OpenAPISchema, type: string | undefined = schema.type) {
|
||||||
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (schema.type === 'object') {
|
if (type === 'object') {
|
||||||
return schema.properties !== undefined
|
return schema.properties !== undefined
|
||||||
? Object.keys(schema.properties).length === 0
|
? Object.keys(schema.properties).length === 0
|
||||||
: schema.additionalProperties === undefined;
|
: schema.additionalProperties === undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (schema.type === 'array') {
|
if (type === 'array') {
|
||||||
if (schema.items === undefined) {
|
if (schema.items === undefined) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user