fix: merge reference for openapi 3.1 (#2063)

This commit is contained in:
Alex Varchuk 2022-07-05 13:19:30 +03:00 committed by GitHub
parent e26c8b23d9
commit 87541e45dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 2 deletions

View File

@ -1181,6 +1181,7 @@ components:
type: object type: object
properties: properties:
id: id:
type: number
description: Tag ID description: Tag ID
$ref: '#/components/schemas/Id' $ref: '#/components/schemas/Id'
name: name:

View File

@ -823,6 +823,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"discriminator": Object { "discriminator": Object {
"propertyName": "type", "propertyName": "type",
}, },
"format": undefined,
"parentRefs": Array [ "parentRefs": Array [
"#/components/schemas/Pet", "#/components/schemas/Pet",
], ],
@ -1643,6 +1644,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"discriminator": Object { "discriminator": Object {
"propertyName": "type", "propertyName": "type",
}, },
"format": undefined,
"parentRefs": Array [ "parentRefs": Array [
"#/components/schemas/Pet", "#/components/schemas/Pet",
], ],
@ -2721,6 +2723,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"discriminator": Object { "discriminator": Object {
"propertyName": "type", "propertyName": "type",
}, },
"format": undefined,
"parentRefs": Array [ "parentRefs": Array [
"#/components/schemas/Pet", "#/components/schemas/Pet",
], ],

View File

@ -1,6 +1,6 @@
import { OpenAPIRef, OpenAPISchema, OpenAPISpec, Referenced } from '../types'; import { OpenAPIRef, OpenAPISchema, OpenAPISpec, Referenced } from '../types';
import { isArray, isBoolean, IS_BROWSER } from '../utils/'; import { isArray, isBoolean, IS_BROWSER } from '../utils';
import { JsonPointer } from '../utils/JsonPointer'; import { JsonPointer } from '../utils/JsonPointer';
import { getDefinitionName, isNamedDefinition } from '../utils/openapi'; import { getDefinitionName, isNamedDefinition } from '../utils/openapi';
import { RedocNormalizedOptions } from './RedocNormalizedOptions'; import { RedocNormalizedOptions } from './RedocNormalizedOptions';
@ -173,7 +173,7 @@ export class OpenAPIParser {
keys.some(k => k !== 'description' && k !== 'title' && k !== 'externalDocs') keys.some(k => k !== 'description' && k !== 'title' && k !== 'externalDocs')
) { ) {
return { return {
allOf: [rest, resolved], allOf: [resolved, rest],
}; };
} else { } else {
// small optimization // small optimization
@ -244,6 +244,7 @@ export class OpenAPIParser {
for (const { $ref: subSchemaRef, schema: subSchema } of allOfSchemas) { for (const { $ref: subSchemaRef, schema: subSchema } of allOfSchemas) {
const { const {
type, type,
format,
enum: enumProperty, enum: enumProperty,
properties, properties,
items, items,
@ -263,6 +264,7 @@ export class OpenAPIParser {
receiver.type = [...type, ...receiver.type]; receiver.type = [...type, ...receiver.type];
} else { } else {
receiver.type = type; receiver.type = type;
receiver.format = format;
} }
} }

View File

@ -4,6 +4,7 @@ exports[`Models Schema schemaDefinition should resolve field with conditional op
Object { Object {
"allOf": undefined, "allOf": undefined,
"default": undefined, "default": undefined,
"format": undefined,
"items": Object { "items": Object {
"allOf": undefined, "allOf": undefined,
"format": "url", "format": "url",
@ -24,6 +25,7 @@ exports[`Models Schema schemaDefinition should resolve field with conditional op
Object { Object {
"allOf": undefined, "allOf": undefined,
"default": undefined, "default": undefined,
"format": undefined,
"items": Object { "items": Object {
"allOf": undefined, "allOf": undefined,
"format": "url", "format": "url",
@ -48,6 +50,7 @@ Object {
exports[`Models Schema schemaDefinition should resolve schema with conditional operators 1`] = ` exports[`Models Schema schemaDefinition should resolve schema with conditional operators 1`] = `
Object { Object {
"allOf": undefined, "allOf": undefined,
"format": undefined,
"maxItems": 2, "maxItems": 2,
"parentRefs": Array [], "parentRefs": Array [],
"properties": Object { "properties": Object {
@ -57,6 +60,7 @@ Object {
"enum": Array [ "enum": Array [
10, 10,
], ],
"format": undefined,
"items": Object { "items": Object {
"allOf": undefined, "allOf": undefined,
"format": "url", "format": "url",
@ -83,6 +87,7 @@ Object {
exports[`Models Schema schemaDefinition should resolve schema with conditional operators 2`] = ` exports[`Models Schema schemaDefinition should resolve schema with conditional operators 2`] = `
Object { Object {
"allOf": undefined, "allOf": undefined,
"format": undefined,
"maxItems": 20, "maxItems": 20,
"parentRefs": Array [], "parentRefs": Array [],
"properties": Object { "properties": Object {

View File

@ -2261,6 +2261,7 @@ Object {
"id": Object { "id": Object {
"$ref": "#/components/schemas/Id", "$ref": "#/components/schemas/Id",
"description": "Tag ID", "description": "Tag ID",
"type": "number",
}, },
"name": Object { "name": Object {
"description": "Tag name", "description": "Tag name",