apib2swagger 1.14.3 → 1.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/nodejs.yml +1 -1
- package/.travis.yml +1 -1
- package/README.md +1 -1
- package/package.json +3 -3
- package/src/mson_to_json_schema.js +4 -0
- package/src/responses.js +7 -1
- package/test/input/Issue-#35.md +6 -0
- package/test/output/05. Responses.json +11 -0
- package/test/output/05. Responses.ref.json +11 -0
- package/test/output/06. Requests.json +11 -0
- package/test/output/06. Requests.ref.json +11 -0
- package/test/output/07. Parameters.json +47 -0
- package/test/output/07. Parameters.ref.json +47 -0
- package/test/output/08. Attributes.ref.json +4 -1
- package/test/output/09. Advanced Attributes.json +6 -2
- package/test/output/09. Advanced Attributes.ref.json +6 -2
- package/test/output/10. Data Structures.json +4 -1
- package/test/output/10. Data Structures.ref.json +4 -1
- package/test/output/12. Advanced Action.json +63 -0
- package/test/output/12. Advanced Action.ref.json +63 -0
- package/test/output/Gist Fox API + Auth.json +51 -0
- package/test/output/Gist Fox API + Auth.ref.json +51 -0
- package/test/output/Issue-#15.json +12 -1
- package/test/output/Issue-#15.ref.json +16 -3
- package/test/output/Issue-#29.json +12 -6
- package/test/output/Issue-#29.ref.json +12 -6
- package/test/output/Issue-#33.ref.json +2 -0
- package/test/output/Issue-#35.json +9 -0
- package/test/output/Issue-#35.ref.json +9 -0
- package/test/output/OpenAPI3_attributes.ref.json +157 -156
- package/test/output/OpenAPI3_responses.json +240 -232
- package/test/output/OpenAPI3_responses.ref.json +231 -223
- package/test/output/Schema.json +11 -0
- package/test/output/Schema.ref.json +11 -0
- package/test/output/apiblueprint_valid_simple.json +51 -0
- package/test/output/apiblueprint_valid_simple.ref.json +51 -0
package/.travis.yml
CHANGED
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apib2swagger",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.1",
|
|
4
4
|
"description": "Convert API Blueprint to Swagger.",
|
|
5
5
|
"bin": "./bin/apib2swagger.js",
|
|
6
6
|
"scripts": {
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"coveralls": "^3.1.1",
|
|
31
31
|
"cross-env": "^5.2.0",
|
|
32
|
-
"mocha": "^
|
|
33
|
-
"nyc": "^
|
|
32
|
+
"mocha": "^10.0.0",
|
|
33
|
+
"nyc": "^15.1.0",
|
|
34
34
|
"sinon": "^12.0.1",
|
|
35
35
|
"tv4": "^1.2.7"
|
|
36
36
|
}
|
|
@@ -38,6 +38,9 @@ function convert(mson, options) {
|
|
|
38
38
|
case 'boolean':
|
|
39
39
|
case 'string':
|
|
40
40
|
case 'number':
|
|
41
|
+
if (mson.content) {
|
|
42
|
+
return { type: mson.element, example: mson.content };
|
|
43
|
+
}
|
|
41
44
|
return { type: mson.element };
|
|
42
45
|
default:
|
|
43
46
|
if (!mson.content) {
|
|
@@ -96,6 +99,7 @@ function convert(mson, options) {
|
|
|
96
99
|
}
|
|
97
100
|
|
|
98
101
|
function convertEnum(contents) {
|
|
102
|
+
if (!contents) return null
|
|
99
103
|
var schema = { type: '', enum: [] };
|
|
100
104
|
for (var i = 0; i < contents.length; i++) {
|
|
101
105
|
var content = contents[i];
|
package/src/responses.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { fixArraySchema, hasFileRef, getRefFromInclude, searchDataStructure } = require('./util')
|
|
1
|
+
const { fixArraySchema, hasFileRef, getRefFromInclude, searchDataStructure, generateSchemaFromExample } = require('./util')
|
|
2
2
|
const escapeJSONPointer = require('./escape_json_pointer')
|
|
3
3
|
const isEqual = require('lodash.isequal')
|
|
4
4
|
const http = require('http')
|
|
@@ -58,6 +58,12 @@ const getResponseSchema = (response, options) => {
|
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
+
for (let content of response.content) {
|
|
62
|
+
const schema = generateSchemaFromExample(response.headers, content.content, options)
|
|
63
|
+
if (schema) {
|
|
64
|
+
return schema
|
|
65
|
+
}
|
|
66
|
+
}
|
|
61
67
|
}
|
|
62
68
|
|
|
63
69
|
const setResponseSchema = (responses, response, schema, options) => {
|
package/test/input/Issue-#35.md
CHANGED
|
@@ -21,6 +21,21 @@
|
|
|
21
21
|
"id": 1,
|
|
22
22
|
"message": "Hello World!"
|
|
23
23
|
}
|
|
24
|
+
},
|
|
25
|
+
"schema": {
|
|
26
|
+
"type": "object",
|
|
27
|
+
"properties": {
|
|
28
|
+
"id": {
|
|
29
|
+
"type": "number"
|
|
30
|
+
},
|
|
31
|
+
"message": {
|
|
32
|
+
"type": "string"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"example": {
|
|
36
|
+
"id": 1,
|
|
37
|
+
"message": "Hello World!"
|
|
38
|
+
}
|
|
24
39
|
}
|
|
25
40
|
}
|
|
26
41
|
},
|
|
@@ -114,6 +129,38 @@
|
|
|
114
129
|
"message": "So long, and thanks for all the fish."
|
|
115
130
|
}
|
|
116
131
|
]
|
|
132
|
+
},
|
|
133
|
+
"schema": {
|
|
134
|
+
"type": "array",
|
|
135
|
+
"items": {
|
|
136
|
+
"type": "object",
|
|
137
|
+
"properties": {
|
|
138
|
+
"id": {
|
|
139
|
+
"type": "number"
|
|
140
|
+
},
|
|
141
|
+
"message": {
|
|
142
|
+
"type": "string"
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
"required": [
|
|
146
|
+
"id",
|
|
147
|
+
"message"
|
|
148
|
+
]
|
|
149
|
+
},
|
|
150
|
+
"example": [
|
|
151
|
+
{
|
|
152
|
+
"id": 1,
|
|
153
|
+
"message": "Hello World!"
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
"id": 2,
|
|
157
|
+
"message": "Time is an illusion. Lunchtime doubly so."
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
"id": 3,
|
|
161
|
+
"message": "So long, and thanks for all the fish."
|
|
162
|
+
}
|
|
163
|
+
]
|
|
117
164
|
}
|
|
118
165
|
}
|
|
119
166
|
},
|
|
@@ -21,6 +21,21 @@
|
|
|
21
21
|
"id": 1,
|
|
22
22
|
"message": "Hello World!"
|
|
23
23
|
}
|
|
24
|
+
},
|
|
25
|
+
"schema": {
|
|
26
|
+
"type": "object",
|
|
27
|
+
"properties": {
|
|
28
|
+
"id": {
|
|
29
|
+
"type": "number"
|
|
30
|
+
},
|
|
31
|
+
"message": {
|
|
32
|
+
"type": "string"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"example": {
|
|
36
|
+
"id": 1,
|
|
37
|
+
"message": "Hello World!"
|
|
38
|
+
}
|
|
24
39
|
}
|
|
25
40
|
}
|
|
26
41
|
},
|
|
@@ -114,6 +129,38 @@
|
|
|
114
129
|
"message": "So long, and thanks for all the fish."
|
|
115
130
|
}
|
|
116
131
|
]
|
|
132
|
+
},
|
|
133
|
+
"schema": {
|
|
134
|
+
"type": "array",
|
|
135
|
+
"items": {
|
|
136
|
+
"type": "object",
|
|
137
|
+
"properties": {
|
|
138
|
+
"id": {
|
|
139
|
+
"type": "number"
|
|
140
|
+
},
|
|
141
|
+
"message": {
|
|
142
|
+
"type": "string"
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
"required": [
|
|
146
|
+
"id",
|
|
147
|
+
"message"
|
|
148
|
+
]
|
|
149
|
+
},
|
|
150
|
+
"example": [
|
|
151
|
+
{
|
|
152
|
+
"id": 1,
|
|
153
|
+
"message": "Hello World!"
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
"id": 2,
|
|
157
|
+
"message": "Time is an illusion. Lunchtime doubly so."
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
"id": 3,
|
|
161
|
+
"message": "So long, and thanks for all the fish."
|
|
162
|
+
}
|
|
163
|
+
]
|
|
117
164
|
}
|
|
118
165
|
}
|
|
119
166
|
},
|
|
@@ -17,14 +17,17 @@
|
|
|
17
17
|
"type": "object",
|
|
18
18
|
"properties": {
|
|
19
19
|
"id": {
|
|
20
|
-
"type": "string"
|
|
20
|
+
"type": "string",
|
|
21
|
+
"example": "250FF"
|
|
21
22
|
},
|
|
22
23
|
"created": {
|
|
23
24
|
"type": "number",
|
|
25
|
+
"example": 1415203908,
|
|
24
26
|
"description": "Time stamp"
|
|
25
27
|
},
|
|
26
28
|
"percent_off": {
|
|
27
29
|
"type": "number",
|
|
30
|
+
"example": 25,
|
|
28
31
|
"description": "A positive integer between 1 and 100 that represents the discount the coupon will apply."
|
|
29
32
|
},
|
|
30
33
|
"redeem_by": {
|
|
@@ -153,7 +153,8 @@
|
|
|
153
153
|
"type": "object",
|
|
154
154
|
"properties": {
|
|
155
155
|
"percent_off": {
|
|
156
|
-
"type": "number"
|
|
156
|
+
"type": "number",
|
|
157
|
+
"example": 25
|
|
157
158
|
},
|
|
158
159
|
"redeem_by": {
|
|
159
160
|
"type": "number"
|
|
@@ -173,14 +174,17 @@
|
|
|
173
174
|
"type": "object",
|
|
174
175
|
"properties": {
|
|
175
176
|
"id": {
|
|
176
|
-
"type": "string"
|
|
177
|
+
"type": "string",
|
|
178
|
+
"example": "250FF"
|
|
177
179
|
},
|
|
178
180
|
"created": {
|
|
179
181
|
"type": "number",
|
|
182
|
+
"example": 1415203908,
|
|
180
183
|
"description": "Time stamp"
|
|
181
184
|
},
|
|
182
185
|
"percent_off": {
|
|
183
186
|
"type": "number",
|
|
187
|
+
"example": 25,
|
|
184
188
|
"description": "A positive integer between 1 and 100 that represents the discount the coupon will apply."
|
|
185
189
|
},
|
|
186
190
|
"redeem_by": {
|
|
@@ -118,7 +118,8 @@
|
|
|
118
118
|
"type": "object",
|
|
119
119
|
"properties": {
|
|
120
120
|
"percent_off": {
|
|
121
|
-
"type": "number"
|
|
121
|
+
"type": "number",
|
|
122
|
+
"example": 25
|
|
122
123
|
},
|
|
123
124
|
"redeem_by": {
|
|
124
125
|
"type": "number"
|
|
@@ -138,14 +139,17 @@
|
|
|
138
139
|
"type": "object",
|
|
139
140
|
"properties": {
|
|
140
141
|
"id": {
|
|
141
|
-
"type": "string"
|
|
142
|
+
"type": "string",
|
|
143
|
+
"example": "250FF"
|
|
142
144
|
},
|
|
143
145
|
"created": {
|
|
144
146
|
"type": "number",
|
|
147
|
+
"example": 1415203908,
|
|
145
148
|
"description": "Time stamp"
|
|
146
149
|
},
|
|
147
150
|
"percent_off": {
|
|
148
151
|
"type": "number",
|
|
152
|
+
"example": 25,
|
|
149
153
|
"description": "A positive integer between 1 and 100 that represents the discount the coupon will apply."
|
|
150
154
|
},
|
|
151
155
|
"redeem_by": {
|
|
@@ -170,10 +170,12 @@
|
|
|
170
170
|
"type": "object",
|
|
171
171
|
"properties": {
|
|
172
172
|
"id": {
|
|
173
|
-
"type": "string"
|
|
173
|
+
"type": "string",
|
|
174
|
+
"example": "250FF"
|
|
174
175
|
},
|
|
175
176
|
"created": {
|
|
176
177
|
"type": "number",
|
|
178
|
+
"example": 1415203908,
|
|
177
179
|
"description": "Time stamp"
|
|
178
180
|
}
|
|
179
181
|
}
|
|
@@ -189,6 +191,7 @@
|
|
|
189
191
|
"properties": {
|
|
190
192
|
"percent_off": {
|
|
191
193
|
"type": "number",
|
|
194
|
+
"example": 25,
|
|
192
195
|
"description": "A positive integer between 1 and 100 that represents the discount the coupon will apply."
|
|
193
196
|
},
|
|
194
197
|
"redeem_by": {
|
|
@@ -135,10 +135,12 @@
|
|
|
135
135
|
"type": "object",
|
|
136
136
|
"properties": {
|
|
137
137
|
"id": {
|
|
138
|
-
"type": "string"
|
|
138
|
+
"type": "string",
|
|
139
|
+
"example": "250FF"
|
|
139
140
|
},
|
|
140
141
|
"created": {
|
|
141
142
|
"type": "number",
|
|
143
|
+
"example": 1415203908,
|
|
142
144
|
"description": "Time stamp"
|
|
143
145
|
}
|
|
144
146
|
}
|
|
@@ -154,6 +156,7 @@
|
|
|
154
156
|
"properties": {
|
|
155
157
|
"percent_off": {
|
|
156
158
|
"type": "number",
|
|
159
|
+
"example": 25,
|
|
157
160
|
"description": "A positive integer between 1 and 100 that represents the discount the coupon will apply."
|
|
158
161
|
},
|
|
159
162
|
"redeem_by": {
|
|
@@ -27,6 +27,46 @@
|
|
|
27
27
|
"type": "task"
|
|
28
28
|
}
|
|
29
29
|
]
|
|
30
|
+
},
|
|
31
|
+
"schema": {
|
|
32
|
+
"type": "array",
|
|
33
|
+
"items": {
|
|
34
|
+
"type": "object",
|
|
35
|
+
"properties": {
|
|
36
|
+
"id": {
|
|
37
|
+
"type": "number"
|
|
38
|
+
},
|
|
39
|
+
"name": {
|
|
40
|
+
"type": "string"
|
|
41
|
+
},
|
|
42
|
+
"done": {
|
|
43
|
+
"type": "boolean"
|
|
44
|
+
},
|
|
45
|
+
"type": {
|
|
46
|
+
"type": "string"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"required": [
|
|
50
|
+
"id",
|
|
51
|
+
"name",
|
|
52
|
+
"done",
|
|
53
|
+
"type"
|
|
54
|
+
]
|
|
55
|
+
},
|
|
56
|
+
"example": [
|
|
57
|
+
{
|
|
58
|
+
"id": 123,
|
|
59
|
+
"name": "Exercise in gym",
|
|
60
|
+
"done": false,
|
|
61
|
+
"type": "task"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"id": 124,
|
|
65
|
+
"name": "Shop for groceries",
|
|
66
|
+
"done": true,
|
|
67
|
+
"type": "task"
|
|
68
|
+
}
|
|
69
|
+
]
|
|
30
70
|
}
|
|
31
71
|
}
|
|
32
72
|
},
|
|
@@ -68,6 +108,29 @@
|
|
|
68
108
|
"done": false,
|
|
69
109
|
"type": "task"
|
|
70
110
|
}
|
|
111
|
+
},
|
|
112
|
+
"schema": {
|
|
113
|
+
"type": "object",
|
|
114
|
+
"properties": {
|
|
115
|
+
"id": {
|
|
116
|
+
"type": "number"
|
|
117
|
+
},
|
|
118
|
+
"name": {
|
|
119
|
+
"type": "string"
|
|
120
|
+
},
|
|
121
|
+
"done": {
|
|
122
|
+
"type": "boolean"
|
|
123
|
+
},
|
|
124
|
+
"type": {
|
|
125
|
+
"type": "string"
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
"example": {
|
|
129
|
+
"id": 123,
|
|
130
|
+
"name": "Go to gym",
|
|
131
|
+
"done": false,
|
|
132
|
+
"type": "task"
|
|
133
|
+
}
|
|
71
134
|
}
|
|
72
135
|
}
|
|
73
136
|
},
|
|
@@ -27,6 +27,46 @@
|
|
|
27
27
|
"type": "task"
|
|
28
28
|
}
|
|
29
29
|
]
|
|
30
|
+
},
|
|
31
|
+
"schema": {
|
|
32
|
+
"type": "array",
|
|
33
|
+
"items": {
|
|
34
|
+
"type": "object",
|
|
35
|
+
"properties": {
|
|
36
|
+
"id": {
|
|
37
|
+
"type": "number"
|
|
38
|
+
},
|
|
39
|
+
"name": {
|
|
40
|
+
"type": "string"
|
|
41
|
+
},
|
|
42
|
+
"done": {
|
|
43
|
+
"type": "boolean"
|
|
44
|
+
},
|
|
45
|
+
"type": {
|
|
46
|
+
"type": "string"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"required": [
|
|
50
|
+
"id",
|
|
51
|
+
"name",
|
|
52
|
+
"done",
|
|
53
|
+
"type"
|
|
54
|
+
]
|
|
55
|
+
},
|
|
56
|
+
"example": [
|
|
57
|
+
{
|
|
58
|
+
"id": 123,
|
|
59
|
+
"name": "Exercise in gym",
|
|
60
|
+
"done": false,
|
|
61
|
+
"type": "task"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"id": 124,
|
|
65
|
+
"name": "Shop for groceries",
|
|
66
|
+
"done": true,
|
|
67
|
+
"type": "task"
|
|
68
|
+
}
|
|
69
|
+
]
|
|
30
70
|
}
|
|
31
71
|
}
|
|
32
72
|
},
|
|
@@ -68,6 +108,29 @@
|
|
|
68
108
|
"done": false,
|
|
69
109
|
"type": "task"
|
|
70
110
|
}
|
|
111
|
+
},
|
|
112
|
+
"schema": {
|
|
113
|
+
"type": "object",
|
|
114
|
+
"properties": {
|
|
115
|
+
"id": {
|
|
116
|
+
"type": "number"
|
|
117
|
+
},
|
|
118
|
+
"name": {
|
|
119
|
+
"type": "string"
|
|
120
|
+
},
|
|
121
|
+
"done": {
|
|
122
|
+
"type": "boolean"
|
|
123
|
+
},
|
|
124
|
+
"type": {
|
|
125
|
+
"type": "string"
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
"example": {
|
|
129
|
+
"id": 123,
|
|
130
|
+
"name": "Go to gym",
|
|
131
|
+
"done": false,
|
|
132
|
+
"type": "task"
|
|
133
|
+
}
|
|
71
134
|
}
|
|
72
135
|
}
|
|
73
136
|
},
|
|
@@ -31,6 +31,57 @@
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
+
},
|
|
35
|
+
"schema": {
|
|
36
|
+
"type": "object",
|
|
37
|
+
"properties": {
|
|
38
|
+
"_links": {
|
|
39
|
+
"type": "object",
|
|
40
|
+
"properties": {
|
|
41
|
+
"self": {
|
|
42
|
+
"type": "object",
|
|
43
|
+
"properties": {
|
|
44
|
+
"href": {
|
|
45
|
+
"type": "string"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"gists": {
|
|
50
|
+
"type": "object",
|
|
51
|
+
"properties": {
|
|
52
|
+
"href": {
|
|
53
|
+
"type": "string"
|
|
54
|
+
},
|
|
55
|
+
"templated": {
|
|
56
|
+
"type": "boolean"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"authorization": {
|
|
61
|
+
"type": "object",
|
|
62
|
+
"properties": {
|
|
63
|
+
"href": {
|
|
64
|
+
"type": "string"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"example": {
|
|
72
|
+
"_links": {
|
|
73
|
+
"self": {
|
|
74
|
+
"href": "/"
|
|
75
|
+
},
|
|
76
|
+
"gists": {
|
|
77
|
+
"href": "/gists?{since}",
|
|
78
|
+
"templated": true
|
|
79
|
+
},
|
|
80
|
+
"authorization": {
|
|
81
|
+
"href": "/authorization"
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
34
85
|
}
|
|
35
86
|
}
|
|
36
87
|
},
|