Skip to content

Commit 1b0a6d4

Browse files
n0rahhJLekawatatomyr
authored
feat: add support for 'x-query' operation in PathItem type (#2501)
* feat: add support for 'x-query' operation in PathItem type * tests: add tests for bundling external refs in x-query operations * feat: changeset * Update .changeset/fair-moons-knock.md Co-authored-by: Andrew Tatomyr <andrew.tatomyr@redocly.com> --------- Co-authored-by: Jacek Łękawa <164185257+JLekawa@users.noreply.github.com> Co-authored-by: Andrew Tatomyr <andrew.tatomyr@redocly.com>
1 parent 7f37e14 commit 1b0a6d4

4 files changed

Lines changed: 52 additions & 0 deletions

File tree

.changeset/fair-moons-knock.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@redocly/openapi-core": patch
3+
---
4+
5+
Allowed `x-query` operations names in OpenAPI 3.0 and 3.1 similar to `query` in OpenAPI 3.2.

packages/core/src/__tests__/bundle.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ describe('bundle', () => {
6767
expect(res.parsed).toMatchSnapshot();
6868
});
6969

70+
it('should bundle external refs under x-query operation (no dereference)', async () => {
71+
const { bundle: res, problems } = await bundle({
72+
config: await createConfig({}),
73+
ref: path.join(__dirname, 'fixtures/refs/openapi-with-external-refs-x-query.yaml'),
74+
});
75+
76+
expect(problems).toHaveLength(0);
77+
const parsed = res.parsed as any;
78+
expect(
79+
parsed.paths['/pet']['x-query'].responses['200'].content['application/json'].schema
80+
).toMatchObject({
81+
$ref: '#/components/schemas/schema-a',
82+
});
83+
expect(parsed.components.schemas['schema-a']).toEqual({ type: 'string' });
84+
});
85+
7086
it('should bundle external refs and warn for conflicting names', async () => {
7187
const { bundle: res, problems } = await bundle({
7288
config: await createConfig({}),
@@ -92,6 +108,22 @@ describe('bundle', () => {
92108
expect(res.parsed).toMatchSnapshot();
93109
});
94110

111+
it('should dereference external refs under x-query operation when dereference is enabled', async () => {
112+
const { bundle: res, problems } = await bundle({
113+
config: await createConfig({}),
114+
ref: path.join(__dirname, 'fixtures/refs/openapi-with-external-refs-x-query.yaml'),
115+
dereference: true,
116+
});
117+
118+
expect(problems).toHaveLength(0);
119+
const parsed = res.parsed as any;
120+
expect(
121+
parsed.paths['/pet']['x-query'].responses['200'].content['application/json'].schema
122+
).toEqual({
123+
type: 'string',
124+
});
125+
});
126+
95127
it('should place referenced schema inline when referenced schema name resolves to original schema name', async () => {
96128
const { bundle: res, problems } = await bundle({
97129
config: await createConfig({}),
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
openapi: 3.0.0
2+
info:
3+
title: x-query external refs
4+
version: '1.0'
5+
paths:
6+
/pet:
7+
x-query:
8+
responses:
9+
'200':
10+
description: ok
11+
content:
12+
application/json:
13+
schema:
14+
$ref: ./schema-a.yaml

packages/core/src/types/oas3.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ const PathItem: NodeType = {
146146
head: 'Operation',
147147
patch: 'Operation',
148148
trace: 'Operation',
149+
'x-query': 'Operation',
149150
},
150151
extensionsPrefix: 'x-',
151152
};

0 commit comments

Comments
 (0)