openapi-validator
Advanced tools
Comparing version 0.12.0 to 0.13.0
const OpenAPIResponseValidator = require('openapi-response-validator').default; | ||
const { extractPathname } = require('../utils'); | ||
const { getPathname } = require('../utils/common.utils'); | ||
const ValidationError = require('./errors/ValidationError'); | ||
@@ -60,3 +60,3 @@ | ||
findOpenApiPathMatchingRequest(actualRequest) { | ||
const actualPathname = extractPathname(actualRequest); | ||
const actualPathname = getPathname(actualRequest); | ||
const openApiPath = this.findOpenApiPathMatchingPathname(actualPathname); | ||
@@ -72,3 +72,3 @@ return openApiPath; | ||
findExpectedPathItem(actualRequest) { | ||
const actualPathname = extractPathname(actualRequest); | ||
const actualPathname = getPathname(actualRequest); | ||
const openApiPath = this.findOpenApiPathMatchingPathname(actualPathname); | ||
@@ -75,0 +75,0 @@ const pathItemObject = this.getPathItem(openApiPath); |
@@ -1,2 +0,2 @@ | ||
const { stringify } = require('../utils'); | ||
const { stringify } = require('../utils/common.utils'); | ||
@@ -3,0 +3,0 @@ class AbstractResponse { |
@@ -1,2 +0,2 @@ | ||
const utils = require('../utils'); | ||
const utils = require('../utils/common.utils'); | ||
const AbstractOpenApiSpec = require('./AbstractOpenApiSpec'); | ||
@@ -3,0 +3,0 @@ const ValidationError = require('./errors/ValidationError'); |
@@ -1,13 +0,13 @@ | ||
const url = require('url'); | ||
const utils = require('../utils'); | ||
const { | ||
defaultBasePath, | ||
findOpenApiPathMatchingPossiblePathnames, | ||
getPathnameWithoutBasePath, | ||
} = require('../utils/common.utils'); | ||
const { | ||
serversPropertyNotProvidedOrIsEmptyArray, | ||
getMatchingServerUrlsAndServerBasePaths, | ||
} = require('../utils/OpenApi3Spec.utils'); | ||
const AbstractOpenApiSpec = require('./AbstractOpenApiSpec'); | ||
const ValidationError = require('./errors/ValidationError'); | ||
const serversPropertyNotProvidedOrIsEmptyArray = (spec) => | ||
!Object.prototype.hasOwnProperty.call(spec, 'servers') || | ||
!spec.servers.length; | ||
const extractBasePath = (inputUrl) => url.parse(inputUrl).path; | ||
class OpenApi3Spec extends AbstractOpenApiSpec { | ||
@@ -26,3 +26,3 @@ constructor(spec) { | ||
if (serversPropertyNotProvidedOrIsEmptyArray(this.spec)) { | ||
this.spec.servers = [{ url: '/' }]; | ||
this.spec.servers = [{ url: defaultBasePath }]; | ||
} | ||
@@ -42,21 +42,14 @@ } | ||
getServerBasePaths() { | ||
const basePaths = this.servers().map((server) => | ||
extractBasePath(server.url), | ||
); | ||
return basePaths; | ||
} | ||
getMatchingServerUrls(pathname) { | ||
const matchingServerUrls = this.getServerUrls().filter((URL) => | ||
pathname.startsWith(extractBasePath(URL)), | ||
); | ||
return matchingServerUrls; | ||
return getMatchingServerUrlsAndServerBasePaths( | ||
this.servers(), | ||
pathname, | ||
).map(({ concreteUrl }) => concreteUrl); | ||
} | ||
getMatchingServerBasePaths(pathname) { | ||
const matchingServerBasePaths = this.getServerBasePaths().filter( | ||
(basePath) => pathname.startsWith(basePath), | ||
); | ||
return matchingServerBasePaths; | ||
return getMatchingServerUrlsAndServerBasePaths( | ||
this.servers(), | ||
pathname, | ||
).map(({ matchingBasePath }) => matchingBasePath); | ||
} | ||
@@ -70,5 +63,5 @@ | ||
const possiblePathnames = matchingServerBasePaths.map((basePath) => | ||
utils.getPathnameWithoutBasePath(basePath, pathname), | ||
getPathnameWithoutBasePath(basePath, pathname), | ||
); | ||
const openApiPath = utils.findOpenApiPathMatchingPossiblePathnames( | ||
const openApiPath = findOpenApiPathMatchingPossiblePathnames( | ||
possiblePathnames, | ||
@@ -75,0 +68,0 @@ this.paths(), |
@@ -1,4 +0,6 @@ | ||
const { isEmptyObj } = require('../utils'); | ||
const AbstractResponse = require('./AbstractResponse'); | ||
const isEmptyObj = (obj) => | ||
!!obj && Object.entries(obj).length === 0 && obj.constructor === Object; | ||
class SuperAgentResponse extends AbstractResponse { | ||
@@ -5,0 +7,0 @@ constructor(res) { |
@@ -7,3 +7,3 @@ const fs = require('fs-extra'); | ||
const utils = require('./utils'); | ||
const utils = require('./utils/common.utils'); | ||
const OpenApi2Spec = require('./classes/OpenApi2Spec'); | ||
@@ -10,0 +10,0 @@ const OpenApi3Spec = require('./classes/OpenApi3Spec'); |
{ | ||
"name": "openapi-validator", | ||
"version": "0.12.0", | ||
"version": "0.13.0", | ||
"description": "Common code for jest-openapi and Chai OpenAPI Response Validator", | ||
@@ -11,3 +11,4 @@ "scripts": { | ||
"test:precommit": "echo", | ||
"test:ci": "echo" | ||
"test:ci": "echo", | ||
"publish": "npm publish" | ||
}, | ||
@@ -33,4 +34,4 @@ "repository": "https://github.com/openapi-library/OpenAPIValidators/tree/master/packages/openapi-validator", | ||
"homepage": "https://github.com/openapi-library/OpenAPIValidators#openapi-validators", | ||
"devDependencies": {}, | ||
"dependencies": { | ||
"combos": "^0.2.0", | ||
"fs-extra": "^9.0.0", | ||
@@ -37,0 +38,0 @@ "js-yaml": "^3.13.1", |
21531
16
592
7
+ Addedcombos@^0.2.0
+ Addedcombos@0.2.0(transitive)