apib2swagger 1.12.0 → 1.14.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.
Files changed (124) hide show
  1. package/.github/workflows/codeql-analysis.yml +71 -0
  2. package/.github/workflows/docker-publish.yml +1 -1
  3. package/.github/workflows/nodejs.yml +1 -1
  4. package/.travis.yml +2 -1
  5. package/Dockerfile +1 -1
  6. package/LICENSE +0 -0
  7. package/README.md +30 -9
  8. package/bin/apib2swagger.js +44 -18
  9. package/index.js +82 -366
  10. package/package.json +7 -4
  11. package/src/escape_json_pointer.js +0 -0
  12. package/src/mson_to_json_schema.js +12 -10
  13. package/src/parameters.js +111 -0
  14. package/src/requests.js +357 -0
  15. package/src/responses.js +186 -0
  16. package/src/util.js +125 -0
  17. package/test/input/Attributes.md +0 -0
  18. package/test/input/Issue-#15.md +0 -0
  19. package/test/input/Issue-#22.md +0 -0
  20. package/test/input/Issue-#23.md +0 -0
  21. package/test/input/Issue-#26.md +0 -0
  22. package/test/input/Issue-#29.md +0 -0
  23. package/test/input/Issue-#33.md +0 -0
  24. package/test/input/Issue-#35.md +0 -0
  25. package/test/input/Issue-#36.md +0 -0
  26. package/test/input/Issue-#38.md +0 -0
  27. package/test/input/Issue-#49.md +0 -0
  28. package/test/input/Issue-#57.md +14 -0
  29. package/test/input/OpenAPI3_Issue-#58.md +31 -0
  30. package/test/input/OpenAPI3_attributes.md +36 -0
  31. package/test/input/OpenAPI3_headers.md +74 -0
  32. package/test/input/OpenAPI3_includes.md +22 -0
  33. package/test/input/OpenAPI3_requests.md +162 -0
  34. package/test/input/OpenAPI3_responses.md +177 -0
  35. package/test/input/Schema.md +0 -0
  36. package/test/input/apiblueprint_uber.md +0 -0
  37. package/test/input/apiblueprint_valid_simple.md +0 -0
  38. package/test/input/includes/resource-request-body-2.json +3 -0
  39. package/test/input/includes/resource-request-body.json +3 -0
  40. package/test/input/includes/resource-request-schema.json +9 -0
  41. package/test/input/includes/resource-response-body-2.json +3 -0
  42. package/test/input/includes/resource-response-body.json +3 -0
  43. package/test/input/includes/resource-response-schema.json +9 -0
  44. package/test/input/schema_without_body.md +17 -0
  45. package/test/meta_schema.json +0 -0
  46. package/test/openAPI_30_schema.json +1662 -0
  47. package/test/output/01. Simplest API.json +0 -0
  48. package/test/output/01. Simplest API.ref.json +0 -0
  49. package/test/output/02. Resource and Actions.json +0 -0
  50. package/test/output/02. Resource and Actions.ref.json +0 -0
  51. package/test/output/03. Named Resource and Actions.json +0 -0
  52. package/test/output/03. Named Resource and Actions.ref.json +0 -0
  53. package/test/output/04. Grouping Resources.json +0 -0
  54. package/test/output/04. Grouping Resources.ref.json +0 -0
  55. package/test/output/05. Responses.json +0 -0
  56. package/test/output/05. Responses.ref.json +0 -0
  57. package/test/output/06. Requests.json +0 -0
  58. package/test/output/06. Requests.ref.json +0 -0
  59. package/test/output/07. Parameters.json +0 -0
  60. package/test/output/07. Parameters.ref.json +0 -0
  61. package/test/output/08. Attributes.json +0 -0
  62. package/test/output/08. Attributes.ref.json +0 -0
  63. package/test/output/09. Advanced Attributes.json +0 -0
  64. package/test/output/09. Advanced Attributes.ref.json +0 -0
  65. package/test/output/10. Data Structures.json +0 -0
  66. package/test/output/10. Data Structures.ref.json +0 -0
  67. package/test/output/11. Resource Model.json +0 -0
  68. package/test/output/11. Resource Model.ref.json +0 -0
  69. package/test/output/12. Advanced Action.json +0 -0
  70. package/test/output/12. Advanced Action.ref.json +0 -0
  71. package/test/output/13. Named Endpoints.json +0 -0
  72. package/test/output/13. Named Endpoints.ref.json +0 -0
  73. package/test/output/Attributes.json +0 -0
  74. package/test/output/Attributes.ref.json +0 -0
  75. package/test/output/Gist Fox API + Auth.json +0 -0
  76. package/test/output/Gist Fox API + Auth.ref.json +0 -0
  77. package/test/output/Issue-#15.json +0 -0
  78. package/test/output/Issue-#15.ref.json +0 -0
  79. package/test/output/Issue-#22.json +0 -0
  80. package/test/output/Issue-#22.ref.json +0 -0
  81. package/test/output/Issue-#23.json +0 -0
  82. package/test/output/Issue-#23.ref.json +0 -0
  83. package/test/output/Issue-#26.json +0 -0
  84. package/test/output/Issue-#26.ref.json +0 -0
  85. package/test/output/Issue-#29.json +0 -0
  86. package/test/output/Issue-#29.ref.json +0 -0
  87. package/test/output/Issue-#33.json +0 -0
  88. package/test/output/Issue-#33.ref.json +0 -0
  89. package/test/output/Issue-#35.json +0 -0
  90. package/test/output/Issue-#35.ref.json +0 -0
  91. package/test/output/Issue-#36.json +0 -0
  92. package/test/output/Issue-#36.ref.json +0 -0
  93. package/test/output/Issue-#38.bearer.json +0 -0
  94. package/test/output/Issue-#38.json +0 -0
  95. package/test/output/Issue-#38.ref.json +0 -0
  96. package/test/output/Issue-#49.json +0 -0
  97. package/test/output/Issue-#49.ref.json +0 -0
  98. package/test/output/Issue-#57.json +44 -0
  99. package/test/output/Issue-#57.ref.json +44 -0
  100. package/test/output/OpenAPI3_Issue-#58.json +202 -0
  101. package/test/output/OpenAPI3_Issue-#58.ref.json +163 -0
  102. package/test/output/OpenAPI3_attributes.json +199 -0
  103. package/test/output/OpenAPI3_attributes.ref.json +173 -0
  104. package/test/output/OpenAPI3_headers.json +169 -0
  105. package/test/output/OpenAPI3_headers.ref.json +169 -0
  106. package/test/output/OpenAPI3_includes.json +66 -0
  107. package/test/output/OpenAPI3_includes.ref.json +66 -0
  108. package/test/output/OpenAPI3_requests.json +326 -0
  109. package/test/output/OpenAPI3_requests.ref.json +321 -0
  110. package/test/output/OpenAPI3_responses.json +255 -0
  111. package/test/output/OpenAPI3_responses.ref.json +245 -0
  112. package/test/output/Schema.json +0 -0
  113. package/test/output/Schema.ref.json +0 -0
  114. package/test/output/apiblueprint_uber.json +0 -0
  115. package/test/output/apiblueprint_uber.ref.json +0 -0
  116. package/test/output/apiblueprint_valid_simple.json +0 -0
  117. package/test/output/apiblueprint_valid_simple.ref.json +0 -0
  118. package/test/output/schema_without_body.json +52 -0
  119. package/test/output/schema_without_body.ref.json +52 -0
  120. package/test/swagger_20_schema.json +0 -0
  121. package/test/test.js +26 -9
  122. package/test/util.test.js +151 -0
  123. package/.npmignore +0 -35
  124. package/package-lock.json +0 -2021
@@ -0,0 +1,245 @@
1
+ {
2
+ "openapi": "3.0.3",
3
+ "info": {
4
+ "title": "",
5
+ "version": "1.0.0",
6
+ "description": ""
7
+ },
8
+ "servers": [
9
+ {
10
+ "url": "https://www.testhost.com"
11
+ }
12
+ ],
13
+ "paths": {
14
+ "/some/resource": {
15
+ "get": {
16
+ "responses": {
17
+ "200": {
18
+ "description": "Array schema",
19
+ "headers": {
20
+ "X-My-Message-Header": {
21
+ "schema": {
22
+ "type": "string"
23
+ }
24
+ }
25
+ },
26
+ "content": {
27
+ "application/json": {
28
+ "schema": {
29
+ "oneOf": [
30
+ {
31
+ "type": "object",
32
+ "properties": {
33
+ "message": {
34
+ "type": "string",
35
+ "description": "This is the message description "
36
+ }
37
+ }
38
+ },
39
+ {
40
+ "type": "object",
41
+ "properties": {
42
+ "other": {
43
+ "type": "string",
44
+ "description": "This is the message description "
45
+ }
46
+ }
47
+ },
48
+ {
49
+ "type": "array",
50
+ "items": {
51
+ "type": "object",
52
+ "properties": {
53
+ "message": {
54
+ "type": "string",
55
+ "description": "This is the message description "
56
+ }
57
+ }
58
+ }
59
+ }
60
+ ]
61
+ },
62
+ "examples": {
63
+ "example1": {
64
+ "value": {
65
+ "message": "Hello World!"
66
+ }
67
+ },
68
+ "example2": {
69
+ "value": {
70
+ "other": "Hello World!"
71
+ }
72
+ },
73
+ "example3": {
74
+ "value": {
75
+ "other": "Hello World!"
76
+ }
77
+ },
78
+ "example4": {
79
+ "value": [
80
+ {
81
+ "message": "Hello World!"
82
+ }
83
+ ]
84
+ }
85
+ }
86
+ }
87
+ }
88
+ },
89
+ "400": {
90
+ "description": "Bad Request",
91
+ "headers": {},
92
+ "content": {
93
+ "application/json": {
94
+ "example": {
95
+ "message": "Invalid data"
96
+ }
97
+ }
98
+ }
99
+ }
100
+ },
101
+ "summary": "Some resource",
102
+ "operationId": "Some resource",
103
+ "description": "",
104
+ "tags": [],
105
+ "parameters": []
106
+ },
107
+ "post": {
108
+ "responses": {
109
+ "200": {
110
+ "description": "OK",
111
+ "headers": {
112
+ "X-My-Message-Header": {
113
+ "schema": {
114
+ "type": "string"
115
+ }
116
+ }
117
+ },
118
+ "content": {
119
+ "application/json": {
120
+ "schema": {
121
+ "type": "object",
122
+ "properties": {
123
+ "message": {
124
+ "type": "string",
125
+ "description": "This is the message description "
126
+ }
127
+ }
128
+ },
129
+ "examples": {
130
+ "example1": {
131
+ "value": {
132
+ "message": "Hello World!"
133
+ }
134
+ },
135
+ "example2": {
136
+ "value": {
137
+ "message": "Hello World!"
138
+ }
139
+ }
140
+ }
141
+ }
142
+ }
143
+ }
144
+ },
145
+ "summary": "Some resource",
146
+ "operationId": "Some resource",
147
+ "description": "",
148
+ "tags": [],
149
+ "parameters": []
150
+ }
151
+ },
152
+ "/test/attributes": {
153
+ "get": {
154
+ "responses": {
155
+ "200": {
156
+ "description": "OK",
157
+ "headers": {},
158
+ "content": {
159
+ "application/json": {
160
+ "schema": {
161
+ "oneOf": [
162
+ {
163
+ "$ref": "#/components/schemas/Message"
164
+ },
165
+ {
166
+ "$ref": "#/components/schemas/OtherMessage"
167
+ }
168
+ ]
169
+ },
170
+ "examples": {
171
+ "example1": {
172
+ "value": {
173
+ "message": "Hello World!"
174
+ }
175
+ },
176
+ "example2": {
177
+ "value": {
178
+ "message": "Hello World2"
179
+ }
180
+ },
181
+ "example3": {
182
+ "value": {
183
+ "otherMessage": "Hello World!"
184
+ }
185
+ }
186
+ }
187
+ }
188
+ }
189
+ }
190
+ },
191
+ "summary": "Some resource",
192
+ "operationId": "Some resource",
193
+ "description": "",
194
+ "tags": [],
195
+ "parameters": []
196
+ }
197
+ },
198
+ "/message": {
199
+ "get": {
200
+ "responses": {
201
+ "200": {
202
+ "description": "Unparsable schema should fall back to Attributes",
203
+ "headers": {},
204
+ "content": {
205
+ "application/json": {
206
+ "schema": {
207
+ "$ref": "#/components/schemas/Message"
208
+ },
209
+ "example": {
210
+ "message": ""
211
+ }
212
+ }
213
+ }
214
+ }
215
+ },
216
+ "summary": "Message",
217
+ "operationId": "Message",
218
+ "description": "",
219
+ "tags": [],
220
+ "parameters": []
221
+ }
222
+ }
223
+ },
224
+ "components": {
225
+ "schemas":{
226
+ "Message": {
227
+ "type": "object",
228
+ "properties": {
229
+ "message": {
230
+ "type": "string"
231
+ }
232
+ }
233
+ },
234
+ "OtherMessage": {
235
+ "type": "object",
236
+ "properties": {
237
+ "otherMessage": {
238
+ "type": "string"
239
+ }
240
+ }
241
+ }
242
+ }
243
+ },
244
+ "tags": []
245
+ }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,52 @@
1
+ {
2
+ "swagger": "2.0",
3
+ "info": {
4
+ "title": "",
5
+ "version": "",
6
+ "description": ""
7
+ },
8
+ "paths": {
9
+ "/some/resource": {
10
+ "post": {
11
+ "responses": {
12
+ "200": {
13
+ "description": "OK",
14
+ "headers": {},
15
+ "examples": {
16
+ "text/plain": ""
17
+ }
18
+ }
19
+ },
20
+ "summary": "Some resource",
21
+ "operationId": "Some resource",
22
+ "description": "",
23
+ "tags": [],
24
+ "parameters": [
25
+ {
26
+ "name": "body",
27
+ "in": "body",
28
+ "schema": {
29
+ "type": "object",
30
+ "properties": {
31
+ "prop1": {
32
+ "type": "string"
33
+ }
34
+ },
35
+ "required": [
36
+ "prop1"
37
+ ]
38
+ }
39
+ }
40
+ ],
41
+ "produces": [
42
+ "text/plain"
43
+ ]
44
+ }
45
+ }
46
+ },
47
+ "definitions": {
48
+ "Some resource": {}
49
+ },
50
+ "securityDefinitions": {},
51
+ "tags": []
52
+ }
@@ -0,0 +1,52 @@
1
+ {
2
+ "swagger": "2.0",
3
+ "info": {
4
+ "title": "",
5
+ "version": "",
6
+ "description": ""
7
+ },
8
+ "paths": {
9
+ "/some/resource": {
10
+ "post": {
11
+ "responses": {
12
+ "200": {
13
+ "description": "OK",
14
+ "headers": {},
15
+ "examples": {
16
+ "text/plain": ""
17
+ }
18
+ }
19
+ },
20
+ "summary": "Some resource",
21
+ "operationId": "Some resource",
22
+ "description": "",
23
+ "tags": [],
24
+ "parameters": [
25
+ {
26
+ "name": "body",
27
+ "in": "body",
28
+ "schema": {
29
+ "type": "object",
30
+ "properties": {
31
+ "prop1": {
32
+ "type": "string"
33
+ }
34
+ },
35
+ "required": [
36
+ "prop1"
37
+ ]
38
+ }
39
+ }
40
+ ],
41
+ "produces": [
42
+ "text/plain"
43
+ ]
44
+ }
45
+ }
46
+ },
47
+ "definitions": {
48
+ "Some resource": {}
49
+ },
50
+ "securityDefinitions": {},
51
+ "tags": []
52
+ }
File without changes
package/test/test.js CHANGED
@@ -4,6 +4,14 @@ var assert = require("assert"),
4
4
  apib2swagger = require("../index.js"),
5
5
  tv4 = require('tv4');
6
6
 
7
+ const swaggerSchema = JSON.parse(fs.readFileSync('test/swagger_20_schema.json'));
8
+ const openAPI3Schema = JSON.parse(fs.readFileSync('test/openAPI_30_schema.json'))
9
+ const meta_schema = JSON.parse(fs.readFileSync('test/meta_schema.json'));
10
+
11
+ tv4.addSchema('http://json-schema.org/draft-04/schema', meta_schema);
12
+ tv4.addSchema('https://spec.openapis.org/oas/3.0/schema/2021-09-28', openAPI3Schema);
13
+ tv4.addSchema('http://swagger.io/v2/schema.json', swaggerSchema);
14
+
7
15
  var remote = 'https://raw.githubusercontent.com/apiaryio/api-blueprint/format-1A9/examples/',
8
16
  localInput = 'test/input/',
9
17
  localOutput = 'test/output/',
@@ -38,8 +46,16 @@ var remote = 'https://raw.githubusercontent.com/apiaryio/api-blueprint/format-1A
38
46
  'Issue-#36.md',
39
47
  'Issue-#38.md',
40
48
  'Issue-#49.md',
49
+ 'Issue-#57.md',
41
50
  'apiblueprint_uber.md',
42
- 'apiblueprint_valid_simple.md'
51
+ 'apiblueprint_valid_simple.md',
52
+ 'schema_without_body.md',
53
+ 'OpenAPI3_responses.md',
54
+ 'OpenAPI3_requests.md',
55
+ 'OpenAPI3_headers.md',
56
+ 'OpenAPI3_includes.md',
57
+ 'OpenAPI3_attributes.md',
58
+ 'OpenAPI3_Issue-#58.md'
43
59
  ];
44
60
 
45
61
  var fetch = function (file) {
@@ -79,6 +95,7 @@ const checkResultByFile = (result, file, originalExtension, newExtension) => {
79
95
  var f = fs.readFileSync(localOutput + file.replace(originalExtension, newExtension));
80
96
  var expected_answer = JSON.parse(f);
81
97
  assert.deepEqual(result.swagger, expected_answer);
98
+ const schema = file.includes('OpenAPI3') ? openAPI3Schema : swaggerSchema
82
99
  var validation_result = tv4.validateResult(result.swagger, schema);
83
100
  if (validation_result.error) {
84
101
  console.log(validation_result);
@@ -95,16 +112,16 @@ describe("apib2swagger", function () {
95
112
  return Promise.all(files.map(fetch));
96
113
  });
97
114
 
98
- schema = JSON.parse(fs.readFileSync('test/swagger_20_schema.json'));
99
- tv4.addSchema('http://swagger.io/v2/schema.json', schema);
100
- meta_schema = JSON.parse(fs.readFileSync('test/meta_schema.json'));
101
- tv4.addSchema('http://json-schema.org/draft-04/schema', meta_schema);
102
-
103
115
  files.concat(includedFiles).forEach(function (file) {
116
+ const options = {}
117
+ if (file.includes('OpenAPI3')){
118
+ options.openApi3 = true
119
+ }
120
+
104
121
  it(file, function (done) {
105
122
  this.timeout(10000); // 10s
106
123
  var apib = fs.readFileSync(localInput + file, "utf-8").replace(/\r/g, '');
107
- apib2swagger.convert(apib, function (error, result) {
124
+ apib2swagger.convert(apib, options, function (error, result) {
108
125
  if (error) {
109
126
  return done(error);
110
127
  }
@@ -117,7 +134,7 @@ describe("apib2swagger", function () {
117
134
  it(file + ' (--prefer-reference)', function (done) {
118
135
  this.timeout(10000); // 10s
119
136
  var apib = fs.readFileSync(localInput + file, "utf-8").replace(/\r/g, '');
120
- apib2swagger.convert(apib, { preferReference: true }, function (error, result) {
137
+ apib2swagger.convert(apib, { ...options, preferReference: true }, function (error, result) {
121
138
  if (error) {
122
139
  return done(error);
123
140
  }
@@ -140,7 +157,7 @@ describe("apib2swagger", function () {
140
157
  return done(error);
141
158
  }
142
159
  assert.equal(result.swagger.info.version, test.output);
143
- var validation_result = tv4.validateResult(result.swagger, schema);
160
+ var validation_result = tv4.validateResult(result.swagger, swaggerSchema);
144
161
  if (validation_result.error) {
145
162
  console.log(validation_result);
146
163
  }
@@ -0,0 +1,151 @@
1
+ const { hasFileRef, normalizeIncludes, getRefFromInclude, getAbsolutePath } = require('../src/util')
2
+ const assert = require('assert')
3
+ const sinon = require('sinon')
4
+ const fs = require('fs')
5
+
6
+ describe('util', () => {
7
+ describe('hasFileRef', () => {
8
+ it('should return true when include is present - has spaces', () => {
9
+ const result = hasFileRef('<!-- include(test.json) -->')
10
+ assert.equal(result, true)
11
+ })
12
+
13
+ it('should return true when include is present - lack of spaces', () => {
14
+ const result = hasFileRef('<!--include(test.json)-->')
15
+ assert.equal(result, true)
16
+ })
17
+
18
+ it('should return false when include is not present', () => {
19
+ const result = hasFileRef('test.json')
20
+ assert.equal(result, false)
21
+ })
22
+ });
23
+
24
+ describe('normalizeIncludes', () => {
25
+ it('should not affect contents before or after the include', () => {
26
+ const result = normalizeIncludes('12345<!-- include: path/to/file.json -->6789')
27
+ assert.equal(result, '12345<!-- include(path/to/file.json) -->6789')
28
+ })
29
+
30
+ it('should work with different input syntaxes', () => {
31
+ const inputSyntaxes = [
32
+ '<!-- include: path/to/file.json -->',
33
+ '<!-- include:path/to/file.json-->',
34
+ '<!-- include(path/to/file.json)-->',
35
+ '<!-- include (path/to/file.json) -->',
36
+ '<!-- include ( path/to/file.json ) -->',
37
+ '<!-- include ( path/to/file.json ) -->',
38
+ '<!-- include (path/to/file.json -->',
39
+ ]
40
+ inputSyntaxes.forEach(str => {
41
+ const result = normalizeIncludes(str)
42
+ assert.equal(result, '<!-- include(path/to/file.json) -->')
43
+ })
44
+ })
45
+
46
+ it('should work with multiple includes', () => {
47
+ const result = normalizeIncludes(`
48
+ 1234<!-- include: path/to/file.json -->5678
49
+ 1111<!-- include(path/to/file.json)-->2222
50
+ `)
51
+ assert.equal(result, `
52
+ 1234<!-- include(path/to/file.json) -->5678
53
+ 1111<!-- include(path/to/file.json) -->2222
54
+ `)
55
+ })
56
+
57
+ it('should allow parens in file name', () => {
58
+ const result = normalizeIncludes('<!-- include: path/to/file(test).json -->')
59
+ assert.equal(result, '<!-- include(path/to/file(test).json) -->')
60
+ })
61
+ });
62
+
63
+ describe('getRefFromInclude', () => {
64
+ it('should work with different input stynaxes', () => {
65
+ const inputSyntaxes = [
66
+ '<!-- include: path/to/file.json -->',
67
+ '<!-- include:path/to/file.json-->',
68
+ '<!-- include(path/to/file.json)-->',
69
+ '<!-- include (path/to/file.json) -->',
70
+ '<!-- include ( path/to/file.json ) -->',
71
+ '<!-- include (path/to/file.json -->',
72
+ ]
73
+ inputSyntaxes.forEach(str => {
74
+ const result = getRefFromInclude(str)
75
+ assert.deepEqual(result, { $ref: 'path/to/file.json' })
76
+ })
77
+ })
78
+
79
+ it('should allow parens in file name', () => {
80
+ const result = getRefFromInclude('<!-- include: path/to/file(test).json -->')
81
+ assert.deepEqual(result, { $ref: 'path/to/file(test).json' })
82
+ })
83
+
84
+ it('should throw an error if the syntax does not match a supported syntax', () => {
85
+ assert.throws(() => {
86
+ getRefFromInclude('<!-- include[path/to/file(test).json] -->')
87
+ })
88
+ })
89
+ });
90
+
91
+ describe('getAbsolutePath', () => {
92
+ const existsSync = sinon.stub(fs, 'existsSync')
93
+ const cwdStub = sinon.stub(process, 'cwd')
94
+ afterEach(() => {
95
+ existsSync.reset()
96
+ cwdStub.reset()
97
+ })
98
+
99
+ it('should return the path to the give source directory if the file exists', () => {
100
+ existsSync.returns(true)
101
+ const result = getAbsolutePath({ ['source-dir']: '~/source/dir/' }, '/file.json')
102
+ assert.equal(result, '~/source/dir/file.json')
103
+ })
104
+
105
+ it('should return the correct path when source is not given and execution path file exists', () => {
106
+ cwdStub.returns('~/cwd/dir/')
107
+ existsSync.returns(true)
108
+
109
+ const result = getAbsolutePath({}, '/file.json')
110
+ assert.equal(result, '~/cwd/dir/file.json')
111
+ })
112
+
113
+ it('should return the correct path when source path does not exist and execution path file exists', () => {
114
+ cwdStub.returns('~/cwd/dir/2/')
115
+ existsSync.onCall(0).returns(false)
116
+ existsSync.onCall(1).returns(true)
117
+
118
+ const result = getAbsolutePath({ ['source-dir']: '~/source/dir/' }, '/file.json')
119
+ assert.equal(result, '~/cwd/dir/2/file.json')
120
+ })
121
+
122
+ it('should return input path when other options do not exist and input path file exists', () => {
123
+ cwdStub.returns('~/cwd/dir/')
124
+ existsSync.onCall(0).returns(false)
125
+ existsSync.onCall(1).returns(false)
126
+ existsSync.onCall(2).returns(true)
127
+
128
+ const options = {
129
+ ['source-dir']: '~/source/dir/',
130
+ input: '~/input/api.md'
131
+ }
132
+ const result = getAbsolutePath(options, '/file.json')
133
+ assert.equal(result, '~/input/file.json')
134
+ })
135
+
136
+ it('should return null if the file does not exist at any of the paths', () => {
137
+ cwdStub.returns('~/cwd/dir/')
138
+ existsSync.onCall(0).returns(false)
139
+ existsSync.onCall(1).returns(false)
140
+ existsSync.onCall(2).returns(false)
141
+ existsSync.onCall(3).returns(true)
142
+
143
+ const options = {
144
+ ['source-dir']: '~/source/dir/',
145
+ input: '~/input/api.md'
146
+ }
147
+ const result = getAbsolutePath(options, '/file.json')
148
+ assert.equal(result, null)
149
+ })
150
+ })
151
+ })
package/.npmignore DELETED
@@ -1,35 +0,0 @@
1
- # Logs
2
- logs
3
- *.log
4
-
5
- # Runtime data
6
- pids
7
- *.pid
8
- *.seed
9
-
10
- # Directory for instrumented libs generated by jscoverage/JSCover
11
- lib-cov
12
-
13
- # Coverage directory used by tools like istanbul
14
- coverage
15
-
16
- # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17
- .grunt
18
-
19
- # Compiled binary addons (http://nodejs.org/api/addons.html)
20
- build/Release
21
-
22
- # Dependency directory
23
- # Commenting this out is preferred by some people, see
24
- # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
25
- node_modules
26
-
27
- # Users Environment Variables
28
- .lock-wscript
29
-
30
- # Swagger server
31
- swagger-ui-master/*
32
- swagger-ui-master.tar.gz
33
-
34
- # IDE
35
- .vscode