open-api-mocker
Advanced tools
Comparing version 1.3.1 to 1.4.0
@@ -9,5 +9,12 @@ # Changelog | ||
## [1.4.0] - 2020-07-03 | ||
### Added | ||
- Added support for path level parameters (#8) | ||
### Fixed | ||
- Path objects are now correctly as they can have extra standard and extended properties (#8) | ||
## [1.3.1] - 2020-04-25 | ||
### Fixed | ||
- Support for every 3.x.x specification version | ||
- Support for every 3.x.x specification version (#6) | ||
@@ -14,0 +21,0 @@ ## [1.3.0] - 2020-04-05 |
@@ -7,2 +7,4 @@ 'use strict'; | ||
const { knownHttpMethods } = require('../utils/http-methods'); | ||
class Parser { | ||
@@ -38,13 +40,22 @@ | ||
parsePath(uri, operations) { | ||
const pathLevelParameters = operations.parameters || []; | ||
return Object.entries(operations) | ||
.map(([httpMethod, operationData]) => this.parseOperation(uri, httpMethod, operationData)) | ||
.map(([httpMethod, operationData]) => this.parseOperation(uri, httpMethod, operationData, pathLevelParameters)) | ||
.filter(Boolean); | ||
} | ||
parseOperation(uri, httpMethod, { parameters, requestBody, responses }) { | ||
parseOperation(uri, httpMethod, { parameters, requestBody, responses }, pathLevelParameters) { | ||
if(!knownHttpMethods.includes(httpMethod.toLowerCase())) | ||
return; | ||
return new Path({ | ||
uri, | ||
httpMethod, | ||
parameters, | ||
parameters: [ | ||
...(parameters || []), | ||
...pathLevelParameters | ||
], | ||
requestBody, | ||
@@ -51,0 +62,0 @@ responses |
@@ -10,2 +10,4 @@ 'use strict'; | ||
const { knownHttpMethods } = require('../utils/http-methods'); | ||
const MediaTypeStruct = struct.interface({ | ||
@@ -34,8 +36,14 @@ schema: struct.optional(struct.union([ | ||
const HttpMethodsStruct = struct.enum(['get', 'post', 'put', 'patch', 'delete', 'options', 'head', 'trace']); | ||
const PathStruct = struct.intersection([ | ||
'object', | ||
struct.interface(knownHttpMethods.reduce((acum, httpMethod) => { | ||
acum[httpMethod] = struct.union(['undefined', OperationStruct]); | ||
return acum; | ||
}, { | ||
parameters: struct.optional([ParameterStruct]) | ||
})) | ||
]); | ||
const PathStruct = struct.dict([HttpMethodsStruct, OperationStruct]); | ||
const Paths = struct.dict(['string', PathStruct]); | ||
module.exports = Paths; |
{ | ||
"name": "open-api-mocker", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"description": "A mock server based in Open API Specification", | ||
@@ -5,0 +5,0 @@ "main": "lib/open-api-mocker.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46347
48
1398