在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:LucyBot-Inc/api-spec-converter开源软件地址:https://github.com/LucyBot-Inc/api-spec-converter开源编程语言:JavaScript 55.7%开源软件介绍:api-spec-converterConvert between API description formats such as Swagger and RAML Currently only supports conversion to OpenAPI(fka Swagger) 2.0 format, and from OpenAPI 2.0 to OpenAPI 3.0.x You can also use the online version at https://lucybot-inc.github.io/api-spec-converter/. InstallationCommand Line
npm install -g api-spec-converter NodeJS/Browsernpm install --save api-spec-converter UsageCommand Line$ api-spec-converter -h
Usage: api-spec-converter [options] <URL|filename>
Convert API descriptions between popular formats.
Supported formats:
* swagger_1
* swagger_2
* openapi_3
* api_blueprint
* io_docs
* google
* raml
* wadl
Options:
-h, --help output usage information
-V, --version output the version number
-f, --from <format> Specifies format to convert
-t, --to <format> Specifies output format
-s, --syntax [syntax] Specifies output data syntax: json or yaml. Defaults to json
-o, --order [sortOrder] Specifies top fields ordering: openapi or alpha. Defaults to openapi
-c, --check Check if result is valid spec
-d, --dummy Fill missing required fields with dummy data Example: $ api-spec-converter --from=swagger_1 --to=swagger_2 --syntax=yaml --order=alpha https://raw.githubusercontent.com/LucyBot-Inc/api-spec-converter/master/test/input/swagger_1/petstore/pet.json > swagger.json NodeJSOptions
Simple example:var Converter = require('api-spec-converter');
Converter.convert({
from: 'swagger_1',
to: 'swagger_2',
source: 'https://api.gettyimages.com/swagger/api-docs',
}, function(err, converted) {
console.log(converted.stringify());
// For yaml and/or OpenApi field order output replace above line
// with an options object like below
// var options = {syntax: 'yaml', order: 'openapi'}
// console.log(converted.stringify(options));
}) Callback vs PromisesThis library has full support for both callback and promises. All async functions return promises but also will execute callback if provided. var Converter = require('api-spec-converter');
Converter.convert({
from: 'swagger_1',
to: 'swagger_2',
source: 'https://api.gettyimages.com/swagger/api-docs',
})
.then(function(converted) {
console.log(converted.stringify());
}); Advanced features:var Converter = require('api-spec-converter');
Converter.convert({
from: 'swagger_1',
to: 'swagger_2',
source: 'https://api.gettyimages.com/swagger/api-docs',
})
.then(function(converted) {
// [Optional] Fill missing fields with dummy values
converted.fillMissing();
// [Optional] Validate converted spec
return converted.validate()
.then(function (result) {
if (result.errors)
return console.error(JSON.stringify(errors, null, 2));
if (result.warnings)
return console.error(JSON.stringify(warnings, null, 2));
fs.writeFileSync('swagger2.json', converted.stringify());
});
}); Browser<script src="node_modules/api-spec-converter/dist/api-spec-converter.js"></script>
APISpecConverter.convert(...) Supported Formats
Conversion Table
Key
ContributingContributions are welcome and encouraged. TestingPlease add a test case if you're adding features or fixing bugs. To run the tests: npm test In case you need to override the expected outputs, due to a justified and verified change, run this: WRITE_GOLDEN=true npm test Releases
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论