Skip to content

Commit

Permalink
fix: merge reference for openapi 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVarchuk committed Jun 24, 2022
1 parent 7ca10da commit b469f77
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions demo/openapi-3-1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,7 @@ components:
type: object
properties:
id:
type: number
description: Tag ID
$ref: '#/components/schemas/Id'
name:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"discriminator": Object {
"propertyName": "type",
},
"format": undefined,
"parentRefs": Array [
"#/components/schemas/Pet",
],
Expand Down Expand Up @@ -1643,6 +1644,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"discriminator": Object {
"propertyName": "type",
},
"format": undefined,
"parentRefs": Array [
"#/components/schemas/Pet",
],
Expand Down Expand Up @@ -2721,6 +2723,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"discriminator": Object {
"propertyName": "type",
},
"format": undefined,
"parentRefs": Array [
"#/components/schemas/Pet",
],
Expand Down
6 changes: 4 additions & 2 deletions src/services/OpenAPIParser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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 { getDefinitionName, isNamedDefinition } from '../utils/openapi';
import { RedocNormalizedOptions } from './RedocNormalizedOptions';
Expand Down Expand Up @@ -173,7 +173,7 @@ export class OpenAPIParser {
keys.some(k => k !== 'description' && k !== 'title' && k !== 'externalDocs')
) {
return {
allOf: [rest, resolved],
allOf: [resolved, rest],
};
} else {
// small optimization
Expand Down Expand Up @@ -244,6 +244,7 @@ export class OpenAPIParser {
for (const { $ref: subSchemaRef, schema: subSchema } of allOfSchemas) {
const {
type,
format,
enum: enumProperty,
properties,
items,
Expand All @@ -263,6 +264,7 @@ export class OpenAPIParser {
receiver.type = [...type, ...receiver.type];
} else {
receiver.type = type;
receiver.format = format;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[`Models Schema schemaDefinition should resolve field with conditional op
Object {
"allOf": undefined,
"default": undefined,
"format": undefined,
"items": Object {
"allOf": undefined,
"format": "url",
Expand All @@ -24,6 +25,7 @@ exports[`Models Schema schemaDefinition should resolve field with conditional op
Object {
"allOf": undefined,
"default": undefined,
"format": undefined,
"items": Object {
"allOf": undefined,
"format": "url",
Expand All @@ -48,6 +50,7 @@ Object {
exports[`Models Schema schemaDefinition should resolve schema with conditional operators 1`] = `
Object {
"allOf": undefined,
"format": undefined,
"maxItems": 2,
"parentRefs": Array [],
"properties": Object {
Expand All @@ -57,6 +60,7 @@ Object {
"enum": Array [
10,
],
"format": undefined,
"items": Object {
"allOf": undefined,
"format": "url",
Expand All @@ -83,6 +87,7 @@ Object {
exports[`Models Schema schemaDefinition should resolve schema with conditional operators 2`] = `
Object {
"allOf": undefined,
"format": undefined,
"maxItems": 20,
"parentRefs": Array [],
"properties": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2261,6 +2261,7 @@ Object {
"id": Object {
"$ref": "#/components/schemas/Id",
"description": "Tag ID",
"type": "number",
},
"name": Object {
"description": "Tag name",
Expand Down

0 comments on commit b469f77

Please sign in to comment.