Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 5 additions & 0 deletions .changeset/fair-moons-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@redocly/openapi-core": patch
---

Added bundling and dereference handling for `x-query` operations in OpenAPI 3.0 and 3.1.
32 changes: 32 additions & 0 deletions packages/core/src/__tests__/bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ describe('bundle', () => {
expect(res.parsed).toMatchSnapshot();
});

it('should bundle external refs under x-query operation (no dereference)', async () => {
const { bundle: res, problems } = await bundle({
config: await createConfig({}),
ref: path.join(__dirname, 'fixtures/refs/openapi-with-external-refs-x-query.yaml'),
});

expect(problems).toHaveLength(0);
const parsed = res.parsed as any;
expect(
parsed.paths['/pet']['x-query'].responses['200'].content['application/json'].schema
).toMatchObject({
$ref: '#/components/schemas/schema-a',
});
expect(parsed.components.schemas['schema-a']).toEqual({ type: 'string' });
});

it('should bundle external refs and warn for conflicting names', async () => {
const { bundle: res, problems } = await bundle({
config: await createConfig({}),
Expand All @@ -92,6 +108,22 @@ describe('bundle', () => {
expect(res.parsed).toMatchSnapshot();
});

it('should dereference external refs under x-query operation when dereference is enabled', async () => {
const { bundle: res, problems } = await bundle({
config: await createConfig({}),
ref: path.join(__dirname, 'fixtures/refs/openapi-with-external-refs-x-query.yaml'),
dereference: true,
});

expect(problems).toHaveLength(0);
const parsed = res.parsed as any;
expect(
parsed.paths['/pet']['x-query'].responses['200'].content['application/json'].schema
).toEqual({
type: 'string',
});
});

it('should place referenced schema inline when referenced schema name resolves to original schema name', async () => {
const { bundle: res, problems } = await bundle({
config: await createConfig({}),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
openapi: 3.0.0
info:
title: x-query external refs
version: '1.0'
paths:
/pet:
x-query:
responses:
'200':
description: ok
content:
application/json:
schema:
$ref: ./schema-a.yaml
1 change: 1 addition & 0 deletions packages/core/src/types/oas3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ const PathItem: NodeType = {
head: 'Operation',
patch: 'Operation',
trace: 'Operation',
'x-query': 'Operation',
},
extensionsPrefix: 'x-',
};
Expand Down
Loading