Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit 2fb8fdc

Browse files
Natalie Mikešovákylef
andauthored
fix(oas3): generate message body in oas3 adapter (#480)
Co-authored-by: Kyle Fuller <kyle@fuller.li>
1 parent cb079d7 commit 2fb8fdc

File tree

5 files changed

+184
-2
lines changed

5 files changed

+184
-2
lines changed

packages/openapi3-parser/lib/adapter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function parse(options) {
1818
options.namespace,
1919
{
2020
generateSourceMap: options.generateSourceMap,
21+
generateMessageBody: options.generateMessageBody,
2122
}
2223
);
2324

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
{
2+
"element": "parseResult",
3+
"content": [
4+
{
5+
"element": "category",
6+
"meta": {
7+
"classes": {
8+
"element": "array",
9+
"content": [
10+
{
11+
"element": "string",
12+
"content": "api"
13+
}
14+
]
15+
},
16+
"title": {
17+
"element": "string",
18+
"content": "My API"
19+
}
20+
},
21+
"attributes": {
22+
"version": {
23+
"element": "string",
24+
"content": "2.0"
25+
}
26+
},
27+
"content": [
28+
{
29+
"element": "resource",
30+
"attributes": {
31+
"href": {
32+
"element": "string",
33+
"content": "/questions"
34+
}
35+
},
36+
"content": [
37+
{
38+
"element": "transition",
39+
"meta": {
40+
"title": {
41+
"element": "string",
42+
"content": "Description of the resource"
43+
}
44+
},
45+
"content": [
46+
{
47+
"element": "httpTransaction",
48+
"content": [
49+
{
50+
"element": "httpRequest",
51+
"attributes": {
52+
"headers": {
53+
"element": "httpHeaders",
54+
"content": [
55+
{
56+
"element": "member",
57+
"content": {
58+
"key": {
59+
"element": "string",
60+
"content": "Content-Type"
61+
},
62+
"value": {
63+
"element": "string",
64+
"content": "application/json"
65+
}
66+
}
67+
}
68+
]
69+
},
70+
"method": {
71+
"element": "string",
72+
"content": "POST"
73+
}
74+
},
75+
"content": [
76+
{
77+
"element": "dataStructure",
78+
"content": {
79+
"element": "string",
80+
"attributes": {
81+
"samples": {
82+
"element": "array",
83+
"content": [
84+
{
85+
"element": "string",
86+
"content": "hello world"
87+
}
88+
]
89+
}
90+
}
91+
}
92+
}
93+
]
94+
},
95+
{
96+
"element": "httpResponse",
97+
"attributes": {
98+
"headers": {
99+
"element": "httpHeaders",
100+
"content": [
101+
{
102+
"element": "member",
103+
"content": {
104+
"key": {
105+
"element": "string",
106+
"content": "Content-Type"
107+
},
108+
"value": {
109+
"element": "string",
110+
"content": "application/json"
111+
}
112+
}
113+
}
114+
]
115+
},
116+
"statusCode": {
117+
"element": "string",
118+
"content": "200"
119+
}
120+
},
121+
"content": [
122+
{
123+
"element": "dataStructure",
124+
"content": {
125+
"element": "string",
126+
"attributes": {
127+
"samples": {
128+
"element": "array",
129+
"content": [
130+
{
131+
"element": "string",
132+
"content": "hello world"
133+
}
134+
]
135+
}
136+
}
137+
}
138+
},
139+
{
140+
"element": "copy",
141+
"content": "Created"
142+
}
143+
]
144+
}
145+
]
146+
}
147+
]
148+
}
149+
]
150+
}
151+
]
152+
}
153+
]
154+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
openapi: 3.0.1
2+
info:
3+
title: My API
4+
version: '2.0'
5+
paths:
6+
/questions:
7+
post:
8+
summary: Description of the resource
9+
requestBody:
10+
content:
11+
application/json:
12+
schema:
13+
type: string
14+
example: hello world
15+
responses:
16+
'200':
17+
description: Created
18+
content:
19+
application/json:
20+
schema:
21+
type: string
22+
example: hello world

packages/openapi3-parser/test/integration/parse-test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ describe('#parse', () => {
1212
return testParseFixture(file, true);
1313
});
1414

15+
it('can parse messageBody example generating message body', () => {
16+
const file = path.join(__dirname, 'fixtures', 'messageBody');
17+
return testParseFixture(file, false, false);
18+
});
19+
1520
it('can parse auth schemes', () => {
1621
const file = path.join(__dirname, 'fixtures', 'auth-scheme');
1722
return testParseFixture(file);

packages/openapi3-parser/test/integration/testParseFixture.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ fury.use(adapter);
2222
const { minim: namespace } = fury;
2323
const parse = promisify(fury.parse.bind(fury));
2424

25-
function testParseFixture(file, generateSourceMap = false) {
25+
function testParseFixture(file, generateSourceMap = false, generateMessageBody = true) {
2626
const source = fs.readFileSync(`${file}.yaml`, 'utf-8');
2727

28-
return parse({ source, generateSourceMap }).then((parseResult) => {
28+
return parse({ source, generateSourceMap, adapterOptions: { generateMessageBody } }).then((parseResult) => {
2929
expect(parseResult).to.be.instanceof(namespace.elements.ParseResult);
3030

3131
// freeze elements to ensure there is no duplicate elements in tree,

0 commit comments

Comments
 (0)