New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

openapi-typescript

Package Overview
Dependencies
Maintainers
1
Versions
145
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openapi-typescript - npm Package Compare versions

Comparing version 4.0.0-pre.0 to 4.0.0

2

package.json
{
"name": "openapi-typescript",
"description": "Generate TypeScript types from Swagger OpenAPI specs",
"version": "4.0.0-pre.0",
"version": "4.0.0",
"engines": {

@@ -6,0 +6,0 @@ "node": ">= 10.0.0"

@@ -15,7 +15,9 @@ [![version(scoped)](https://img.shields.io/npm/v/openapi-typescript.svg)](https://www.npmjs.com/package/openapi-typescript)

- Convert [Open API 3.x][openapi3] and [Swagger 2.x][openapi2] to TypeScript types
- Load schemas either from local `.yaml` or `.json` files, or from a remote URL (simple authentication supported with the `--auth` flag)
- Supports remote `$ref`s using [json-schema-ref-parser][json-schema-ref-parser]
- Formats output using [Prettier][prettier]
- Uses the latest TypeScript 4.0 syntax
- ✅ [OpenAPI 3.0][openapi3]
- ✅ [Swagger 2.0][openapi2]
- ✅ Supports YAML and JSON schema formats
- ✅ Supports loading via remote URL (simple authentication supported with the `--auth` flag)
- ✅ Supports remote references: `$ref: "external.yaml#components/schemas/User"`
- ✅ Formats using [Prettier][prettier]
- ✅ TypeScript 4.0 features

@@ -40,2 +42,3 @@ **Examples**

npx openapi-typescript "specs/**/*.yaml" --output schemas/
# 🔭 Loading spec from specs/one.yaml…

@@ -76,3 +79,3 @@ # 🔭 Loading spec from specs/two.yaml…

The reason for all the `["…"]` everywhere is because OpenAPI lets you use more characters than are valid TypeScript identifiers. The goal of this project is to generate _all_ of your schema, not merely the parts that are “TypeScript-safe.”
Because OpenAPI schemas may have invalid TypeScript characters as names, the square brackets are a safe way to access every property.

@@ -87,8 +90,10 @@ Also note that there’s a special `operations` interface that you can import `OperationObjects` by their [operationId][openapi-operationid]:

This is the only place where our generation differs from your schema as-written, but it’s done so as a convenience and shouldn’t cause any issues (you can still use deep references as-needed).
Even though `operations` isn’t present in your original schema, it’s a simple convenience and won’t disrupt any of your other types.
_Thanks to @gr2m for the operations feature!_
_Thanks to [@gr2m](https://github.com/gr2m) for the operations feature!_
#### Outputting to `stdout`
#### Outputting to stdout
Simply omit the `--output` flag to return to stdout:
```bash

@@ -120,11 +125,11 @@ npx openapi-typescript schema.yaml

// option 1: load [object] as schema (JSON only)
// example 1: load [object] as schema (JSON only)
const schema = await fs.promises.readFile("spec.json", "utf8") // must be OpenAPI JSON
const output = await openapiTS(JSON.parse(schema));
// option 2: load [string] as local file (YAML or JSON; released in v3.3)
// example 2: load [string] as local file (YAML or JSON; released in v4.0)
const localPath = path.join(__dirname, 'spec.yaml'); // may be YAML or JSON format
const output = await openapiTS(localPath);
// option 3: load [string] as remote URL (YAML or JSON; released in v3.3)
// example 3: load [string] as remote URL (YAML or JSON; released in v4.0)
const output = await openapiTS('https://myurl.com/v1/openapi.yaml');

@@ -135,3 +140,3 @@ ```

⚠️ As of `v3.3`, this is an async function.
⚠️ As of `v4.0`, `openapiTS()` is an async function.

@@ -182,3 +187,2 @@ #### Custom Formatter

[js-yaml]: https://www.npmjs.com/package/js-yaml
[json-schema-ref-parser]: https://github.com/APIDevTools/json-schema-ref-parser
[namespace]: https://www.typescriptlang.org/docs/handbook/namespaces.html

@@ -185,0 +189,0 @@ [npm-run-all]: https://www.npmjs.com/package/npm-run-all

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc