oas-normalize
Advanced tools
Comparing version 8.0.0 to 8.1.0
@@ -110,4 +110,15 @@ import type { OpenAPI } from 'openapi-types'; | ||
validate(opts?: { | ||
/** | ||
* Automatically convert the supplied API definition to the latest version of OpenAPI. | ||
*/ | ||
convertToLatest?: boolean; | ||
}): Promise<any>; | ||
/** | ||
* Retrieve OpenAPI, Swagger, or Postman version information about the supplied API definition. | ||
* | ||
*/ | ||
version(): Promise<{ | ||
specification: string; | ||
version: any; | ||
}>; | ||
} |
@@ -250,4 +250,32 @@ "use strict"; | ||
}; | ||
/** | ||
* Retrieve OpenAPI, Swagger, or Postman version information about the supplied API definition. | ||
* | ||
*/ | ||
OASNormalize.prototype.version = function () { | ||
return this.load().then(function (schema) { | ||
switch ((0, exports.getAPIDefinitionType)(schema)) { | ||
case 'openapi': | ||
return { | ||
specification: 'openapi', | ||
version: schema.openapi | ||
}; | ||
case 'postman': | ||
// We don't have any way right now to know if a Postman collection is for v2.0 or v2.1. | ||
return { | ||
specification: 'postman', | ||
version: 'unknown' | ||
}; | ||
case 'swagger': | ||
return { | ||
specification: 'swagger', | ||
version: schema.swagger | ||
}; | ||
default: | ||
throw new Error('Unknown file detected.'); | ||
} | ||
}); | ||
}; | ||
return OASNormalize; | ||
}()); | ||
exports["default"] = OASNormalize; |
{ | ||
"name": "oas-normalize", | ||
"version": "8.0.0", | ||
"version": "8.1.0", | ||
"description": "Tooling for converting, valiating, and parsing OpenAPI, Swagger, and Postman API definitions", | ||
@@ -16,3 +16,2 @@ "main": "dist/index.js", | ||
"microservice", | ||
"postman", | ||
"oai", | ||
@@ -25,2 +24,3 @@ "oas", | ||
"openapi specification", | ||
"postman", | ||
"swagger" | ||
@@ -27,0 +27,0 @@ ], |
@@ -115,2 +115,13 @@ <p align="center"> | ||
### `#version()` | ||
Load and retrieve version information about a supplied API definition. | ||
```js | ||
await oas.version().then(({ specification, version }) => { | ||
console.log(specification); // openapi | ||
console.log(version); // 3.1.0 | ||
}); | ||
``` | ||
### Options | ||
@@ -117,0 +128,0 @@ |
@@ -144,3 +144,10 @@ import type { OpenAPI } from 'openapi-types'; | ||
*/ | ||
async validate(opts: { convertToLatest?: boolean } = { convertToLatest: false }) { | ||
async validate( | ||
opts: { | ||
/** | ||
* Automatically convert the supplied API definition to the latest version of OpenAPI. | ||
*/ | ||
convertToLatest?: boolean; | ||
} = { convertToLatest: false } | ||
) { | ||
const convertToLatest = opts.convertToLatest; | ||
@@ -194,2 +201,34 @@ const colorizeErrors = this.opts.colorizeErrors; | ||
} | ||
/** | ||
* Retrieve OpenAPI, Swagger, or Postman version information about the supplied API definition. | ||
* | ||
*/ | ||
version() { | ||
return this.load().then(schema => { | ||
switch (getAPIDefinitionType(schema)) { | ||
case 'openapi': | ||
return { | ||
specification: 'openapi', | ||
version: schema.openapi, | ||
}; | ||
case 'postman': | ||
// We don't have any way right now to know if a Postman collection is for v2.0 or v2.1. | ||
return { | ||
specification: 'postman', | ||
version: 'unknown', | ||
}; | ||
case 'swagger': | ||
return { | ||
specification: 'swagger', | ||
version: schema.swagger, | ||
}; | ||
default: | ||
throw new Error('Unknown file detected.'); | ||
} | ||
}); | ||
} | ||
} |
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
2663231
874
149