3.10.0 • Published 3 months ago

@icholy/openapi-ts v3.10.0

Weekly downloads
-
License
ISC
Repository
-
Last release
3 months ago

openapi-ts

Library for generating TypeScript interfaces from OpenAPI v3 documents.

  • This library is library is incomplete, it implements the subset of the spec that I personally need.

CLI:

The package comes with a cli tool with a basic transformer implementation.

$ openapi-ts ./openapi.json

Basic Usage:

import { load, analyse, transform } from "@icholy/openapi-ts";

function main() {
  const doc = await load("openapi.json");
  const details = analyse(doc);
  console.log(transform(details));
}

Custom Transform

import {
  load,
  analyse,
  Schema,
  Printer,
  DocumentDetails
} from "@icholy/openapi-ts";

function main() {
  const doc = await load("openapi.json");
  const details = analyse(doc);
  console.log(transform(details));
}

function transform(doc: DocumentDetails): string {
  const print = new Printer();
  
  // output component schemas
  for (const [name, schema] of Object.entries(doc.schemas)) {
    print.schema(schema, name);
  }

  // output body types with random names
  for (const op of doc.operations) {
    // usually the name is inferred from the op's method/path
    print.schema(op.params.body, "InterfaceNameHere");
  }
  
  // output a custom type
  const schema = new Schema("object");
  schema.setProperty("a", new Schema("string", { required: true }));
  schema.setProperty("b", new Schema("SomeOtherType"));
  print.schema(schema, "MyType");

  // output types for each route
  return print.code();
}
3.10.0

3 months ago

3.9.0

3 months ago

3.8.0

4 months ago

3.7.0

5 months ago

3.6.0

5 months ago

2.11.0

8 months ago

3.4.0

6 months ago

3.3.0

6 months ago

3.2.0

6 months ago

3.1.0

6 months ago

3.5.0

6 months ago

3.0.0

6 months ago

2.10.4

1 year ago

2.10.2

1 year ago

2.10.3

1 year ago

2.10.1

2 years ago

2.10.0

2 years ago

2.9.0

2 years ago

2.8.0

2 years ago

2.7.0

2 years ago

2.5.2

2 years ago

2.6.0

2 years ago

2.5.0

3 years ago

2.4.0

3 years ago

2.5.1

3 years ago

2.3.2

3 years ago

2.3.1

3 years ago

2.3.0

3 years ago

2.2.0

3 years ago

2.1.0

3 years ago

2.0.0

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago