Skip to content

Commit 84cdccb

Browse files
committed
fix: oas example types and tests
1 parent ecbacdb commit 84cdccb

File tree

12 files changed

+97
-193
lines changed

12 files changed

+97
-193
lines changed

__tests__/bundle/bundle-example-value-with-ref/openapi.yaml

Lines changed: 0 additions & 92 deletions
This file was deleted.

__tests__/bundle/bundle-example-value-with-ref/redocly.yaml

Lines changed: 0 additions & 3 deletions
This file was deleted.

__tests__/bundle/bundle-example-value-with-ref/snapshot.txt

Lines changed: 0 additions & 92 deletions
This file was deleted.

packages/core/src/types/oas2.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ const Parameter: NodeType = {
163163
uniqueItems: { type: 'boolean' },
164164
enum: { type: 'array' },
165165
multipleOf: { type: 'number' },
166-
'x-example': {}, // any
166+
'x-example': 'XExample',
167167
'x-examples': 'ExamplesMap',
168168
},
169169
required(value) {
@@ -427,7 +427,9 @@ const SecurityRequirement: NodeType = {
427427
additionalProperties: { type: 'array', items: { type: 'string' } },
428428
};
429429

430-
const Example: NodeType = {
430+
const Example = { isExample: true, properties: {} };
431+
432+
const XExample: NodeType = {
431433
properties: {
432434
value: { isExample: true, resolvable: false },
433435
summary: { type: 'string' },
@@ -475,4 +477,5 @@ export const Oas2Types = {
475477
XCodeSampleList: listOf('XCodeSample'),
476478
XServerList: listOf('XServer'),
477479
XServer,
480+
XExample,
478481
} as const;

packages/core/src/types/oas3_1.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,16 @@ const DependentRequired: NodeType = {
271271
additionalProperties: { type: 'array', items: { type: 'string' } },
272272
};
273273

274+
const Example: NodeType = {
275+
properties: {
276+
value: { isExample: true, resolvable: false },
277+
summary: { type: 'string' },
278+
description: { type: 'string' },
279+
externalValue: { type: 'string' },
280+
},
281+
extensionsPrefix: 'x-',
282+
};
283+
274284
export const Oas3_1Types = {
275285
...Oas3Types,
276286
Info,
@@ -284,4 +294,5 @@ export const Oas3_1Types = {
284294
SecurityScheme,
285295
Operation,
286296
DependentRequired,
297+
Example,
287298
} as const;

packages/core/src/types/oas3_2.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,15 @@ const Discriminator: NodeType = {
191191
};
192192

193193
const Example: NodeType = {
194-
...Oas3_1Types.Example,
195194
properties: {
196-
...Oas3_1Types.Example.properties,
195+
value: { isExample: true, resolvable: false },
196+
summary: { type: 'string' },
197+
description: { type: 'string' },
198+
externalValue: { type: 'string' },
197199
dataValue: { isExample: true, resolvable: false },
198200
serializedValue: { type: 'string' },
199201
},
202+
extensionsPrefix: 'x-',
200203
};
201204

202205
export const Oas3_2Types = {
@@ -213,4 +216,5 @@ export const Oas3_2Types = {
213216
MediaType,
214217
Discriminator,
215218
Example,
219+
ExamplesMap: mapOf('Example'),
216220
} as const;

__tests__/bundle/bundle-example-value-with-ref/example.json renamed to tests/e2e/bundle/bundle-example-value-with-ref/example.json

File renamed without changes.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
openapi: 3.2.0
2+
info:
3+
title: Test API
4+
version: 1.0.0
5+
paths:
6+
/test:
7+
get:
8+
responses:
9+
'200':
10+
content:
11+
application/json:
12+
schema:
13+
type: object
14+
properties:
15+
id:
16+
type: integer
17+
name:
18+
type: string
19+
active:
20+
type: boolean
21+
example:
22+
$ref: example.json
23+
examples:
24+
Test:
25+
summary: Example with $ref in value (should NOT resolve)
26+
value:
27+
$ref: example.json
28+
29+
TestDataValue:
30+
summary: Example with $ref in dataValue (should NOT resolve)
31+
dataValue:
32+
$ref: example.json
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apis:
2+
main:
3+
root: openapi.yaml
4+
5+
resolve:
6+
doNotResolveExamples: true
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
openapi: 3.2.0
2+
info:
3+
title: Test API
4+
version: 1.0.0
5+
paths:
6+
/test:
7+
get:
8+
responses:
9+
'200':
10+
content:
11+
application/json:
12+
schema:
13+
type: object
14+
properties:
15+
id:
16+
type: integer
17+
name:
18+
type: string
19+
active:
20+
type: boolean
21+
example:
22+
$ref: example.json
23+
examples:
24+
Test:
25+
summary: Example with $ref in value (should NOT resolve)
26+
value:
27+
$ref: example.json
28+
TestDataValue:
29+
summary: Example with $ref in dataValue (should NOT resolve)
30+
dataValue:
31+
$ref: example.json
32+
components: {}
33+
34+
bundling openapi.yaml using configuration for api 'main'...
35+
📦 Created a bundle for openapi.yaml at stdout <test>ms.

0 commit comments

Comments
 (0)