Convert OpenApi doc to k6 client.
Uses swagger-parser to validate/parse a OpenAPI 3.0 file.
$ npm i oas-to-k6-clients
$ npx oas-to-k6-clients petstore.yaml -o .
Convert
const fs = require("fs");
const { oasToK6Client } = require("oas-to-k6-clients");
async function run() {
const { typesSource, clientsSource } = await oasToK6Client("oas.yaml");
fs.writeFileSync("./index.d.ts", typesSource);
fs.writeFileSync("./index.js", clientsSource);
}
Validates the OpenApi doc against the OpenAPI 3.0 Schema.
const { validate } = require("oas-to-k6-clients");
try {
validate("oas.yaml");
} catch (error) {
// Handle invalid oas doc
}
Using wateringhole.yaml
Types source output - wateringhole.d.ts
Clients source output - wateringhole.js