Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/ContentItems/ContentItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class ContentItems extends React.Component<{
render() {
const items = this.props.items;
if (items.length === 0) {
return null;
return <MiddlePanel compact={false}>Cannot find path or webhooks items</MiddlePanel>;
}
return items.map(item => {
return <ContentItem key={item.id} item={item} />;
Expand Down
14 changes: 12 additions & 2 deletions src/services/OpenAPIParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,22 @@ export class OpenAPIParser {
subSchema.type !== undefined
) {
console.warn(
`Incompatible types in allOf at "${$ref}": "${receiver.type}" and "${subSchema.type}"`,
`Incompatible types in allOf at "${$ref}": "${receiver.type}" and "${subSchema.type}"`, //check maybe need delete
);
}

if (subSchema.type !== undefined) {
receiver.type = subSchema.type;
if (Array.isArray(subSchema.type) && receiver.type)
receiver.type = receiver.type?.concat(...subSchema.type)
else
receiver.type = subSchema.type;
}

if (subSchema.enum !== undefined) {
if (Array.isArray(subSchema.enum) && receiver.enum)
receiver.enum = receiver.enum?.concat(...subSchema.enum)
else
receiver.enum = subSchema.enum;
}

if (subSchema.properties !== undefined) {
Expand Down
36 changes: 35 additions & 1 deletion src/services/models/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
pluralizeType,
sortByField,
sortByRequired,
mergeObjects,
} from '../../utils/';

import { l } from '../Labels';
Expand Down Expand Up @@ -105,7 +106,7 @@ export class SchemaModel {
this.title =
schema.title || (isNamedDefinition(this.pointer) && JsonPointer.baseName(this.pointer)) || '';
this.description = schema.description || '';
this.type = schema.type || detectType(schema);
this.type = (Array.isArray(schema.type) && schema.type) || (schema.type || detectType(schema));
this.format = schema.format;
this.enum = schema.enum || [];
this.example = schema.example;
Expand All @@ -131,10 +132,21 @@ export class SchemaModel {
? this.type.map(item => item === null ? 'null' : item).join(' or ')
: this.type;

if (!!schema.nullable) {
if (Array.isArray(this.type)) this.type.push('null');
else this.type = [this.type, 'null'];
}

this.displayType = Array.isArray(this.type) ? this.type.join(' or ') : this.type; // null problem here

if (this.isCircular) {
return;
}

if (schema.if || schema.then || schema.else) {
this.initConditionalOperators(schema, parser);
}

if (!isChild && getDiscriminator(schema) !== undefined) {
this.initDiscriminator(schema, parser);
return;
Expand Down Expand Up @@ -339,6 +351,28 @@ export class SchemaModel {
return innerSchema;
});
}

private initConditionalOperators(schema: OpenAPISchema, parser: OpenAPIParser) {
const { if: ifOperator, else: elseOperator, then: thenOperator, ...clearSchema} = schema;
if ((!ifOperator && !thenOperator) || (!ifOperator && !elseOperator)) return;

const groupedOperators = [mergeObjects({}, clearSchema, { allOf: [ifOperator, thenOperator] }), mergeObjects({}, clearSchema, elseOperator)]

this.oneOf = groupedOperators.map((variant, idx) => {
const merged = parser.mergeAllOf(parser.deref(variant || {}), this.pointer + '/oneOf/' + idx);
const title = merged.title || this.title;
const result = new SchemaModel(
parser,
{
...merged,
title,
} as OpenAPISchema,
this.pointer + '/oneOf/' + idx,
this.options,
);
return result;
})
}
}

function buildFields(
Expand Down
4 changes: 4 additions & 0 deletions src/types/open-api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ export interface OpenAPISchema {
minProperties?: number;
enum?: any[];
example?: any;

if?: OpenAPISchema;
else?: OpenAPISchema;
then?: OpenAPISchema;
const?: string;
}

Expand Down
Loading