Skip to content

danzelbel/oas-to-k6-clients

Repository files navigation

MIT License Build Release NPM Version NPM Weekly Downloads

oas-to-k6-clients

Convert OpenApi doc to k6 client.

Uses swagger-parser to validate/parse a OpenAPI 3.0 file.

Installation

$ npm i oas-to-k6-clients

Usage

CLI

$ npx oas-to-k6-clients petstore.yaml -o .

Library

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);
}

Validate

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
}

Example

Using wateringhole.yaml

Types source output - wateringhole.d.ts

Clients source output - wateringhole.js

About

Generate k6 api clients from oas files

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published