apib2swagger 1.15.0 → 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.
@@ -9,7 +9,7 @@ jobs:
9
9
 
10
10
  strategy:
11
11
  matrix:
12
- node-version: [12.x, 14.x, 16.x]
12
+ node-version: [14.x, 16.x, 18.x]
13
13
 
14
14
  steps:
15
15
  - uses: actions/checkout@v1
package/.travis.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  language: node_js
2
2
  node_js:
3
+ - "18"
3
4
  - "16"
4
5
  - "14"
5
- - "12"
6
6
  after_success: npm run coverage
package/README.md CHANGED
@@ -14,7 +14,7 @@ Supported versions:
14
14
  - [Include directive](https://github.com/danielgtaylor/aglio#including-files)
15
15
  - Swagger 2.0
16
16
  - OpenAPI 3.0.3
17
- - Node.js 12.x, 14.x, 16.x or higher
17
+ - Node.js 14.x, 16.x, 18.x or higher
18
18
 
19
19
  ## Install
20
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apib2swagger",
3
- "version": "1.15.0",
3
+ "version": "1.16.1",
4
4
  "description": "Convert API Blueprint to Swagger.",
5
5
  "bin": "./bin/apib2swagger.js",
6
6
  "scripts": {
@@ -99,6 +99,7 @@ function convert(mson, options) {
99
99
  }
100
100
 
101
101
  function convertEnum(contents) {
102
+ if (!contents) return null
102
103
  var schema = { type: '', enum: [] };
103
104
  for (var i = 0; i < contents.length; i++) {
104
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) => {
@@ -6,3 +6,9 @@ FORMAT: 1A
6
6
  ## Config
7
7
  + alice (string, required) - information about alice
8
8
  + bob (string, required) - information about bob
9
+
10
+ ## Filter
11
+ + status (array[enum])
12
+ + Members
13
+ + option1
14
+ + option2
@@ -20,6 +20,17 @@
20
20
  "application/json": {
21
21
  "message": "Hello World!"
22
22
  }
23
+ },
24
+ "schema": {
25
+ "type": "object",
26
+ "properties": {
27
+ "message": {
28
+ "type": "string"
29
+ }
30
+ },
31
+ "example": {
32
+ "message": "Hello World!"
33
+ }
23
34
  }
24
35
  }
25
36
  },
@@ -20,6 +20,17 @@
20
20
  "application/json": {
21
21
  "message": "Hello World!"
22
22
  }
23
+ },
24
+ "schema": {
25
+ "type": "object",
26
+ "properties": {
27
+ "message": {
28
+ "type": "string"
29
+ }
30
+ },
31
+ "example": {
32
+ "message": "Hello World!"
33
+ }
23
34
  }
24
35
  }
25
36
  },
@@ -20,6 +20,17 @@
20
20
  "application/json": {
21
21
  "message": "Hello World!"
22
22
  }
23
+ },
24
+ "schema": {
25
+ "type": "object",
26
+ "properties": {
27
+ "message": {
28
+ "type": "string"
29
+ }
30
+ },
31
+ "example": {
32
+ "message": "Hello World!"
33
+ }
23
34
  }
24
35
  }
25
36
  },
@@ -20,6 +20,17 @@
20
20
  "application/json": {
21
21
  "message": "Hello World!"
22
22
  }
23
+ },
24
+ "schema": {
25
+ "type": "object",
26
+ "properties": {
27
+ "message": {
28
+ "type": "string"
29
+ }
30
+ },
31
+ "example": {
32
+ "message": "Hello World!"
33
+ }
23
34
  }
24
35
  }
25
36
  },
@@ -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
  },
@@ -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
  },
@@ -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
  },
@@ -27,6 +27,15 @@
27
27
  "description": "information about bob"
28
28
  }
29
29
  }
30
+ },
31
+ "Filter": {
32
+ "type": "object",
33
+ "properties": {
34
+ "status": {
35
+ "type": "array",
36
+ "items": {}
37
+ }
38
+ }
30
39
  }
31
40
  },
32
41
  "securityDefinitions": {},
@@ -27,6 +27,15 @@
27
27
  "description": "information about bob"
28
28
  }
29
29
  }
30
+ },
31
+ "Filter": {
32
+ "type": "object",
33
+ "properties": {
34
+ "status": {
35
+ "type": "array",
36
+ "items": {}
37
+ }
38
+ }
30
39
  }
31
40
  },
32
41
  "securityDefinitions": {},