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 6.6.1 to 6.6.2-beta.0

53

dist/load.js

@@ -9,20 +9,5 @@ import fs from "node:fs";

export const VIRTUAL_JSON_URL = `file:///_json`;
function parseYAML(schema) {
try {
return yaml.load(schema);
}
catch (err) {
error(`YAML: ${String(err)}`);
process.exit(1);
}
function parseSchema(source) {
return source.trim().startsWith("{") ? JSON.parse(source) : yaml.load(source);
}
function parseJSON(schema) {
try {
return JSON.parse(schema);
}
catch (err) {
error(`JSON: ${String(err)}`);
process.exit(1);
}
}
export function resolveSchema(filename) {

@@ -71,3 +56,2 @@ if (isRemoteURL(filename))

options.urlCache.add(schemaID);
const ext = path.extname(schema.pathname).toLowerCase();
if (schema.protocol.startsWith("http")) {

@@ -87,30 +71,8 @@ const headers = { "User-Agent": "openapi-typescript" };

});
const contentType = res.headers.get("content-type");
if (ext === ".json" || contentType?.includes("json")) {
options.schemas[schemaID] = {
hint,
schema: parseJSON(await res.text()),
};
}
else if (ext === ".yaml" || ext === ".yml" || contentType?.includes("yaml")) {
options.schemas[schemaID] = {
hint,
schema: parseYAML(await res.text()),
};
}
const contents = await res.text();
options.schemas[schemaID] = { hint, schema: parseSchema(contents) };
}
else {
const contents = fs.readFileSync(schema, "utf8");
if (ext === ".yaml" || ext === ".yml") {
options.schemas[schemaID] = {
hint,
schema: parseYAML(contents),
};
}
else if (ext === ".json") {
options.schemas[schemaID] = {
hint,
schema: parseJSON(contents),
};
}
options.schemas[schemaID] = { hint, schema: parseSchema(contents) };
}

@@ -131,6 +93,3 @@ }

});
options.schemas[schemaID] = {
hint: "OpenAPI3",
schema: contents.startsWith("{") ? parseJSON(contents) : parseYAML(contents),
};
options.schemas[schemaID] = { hint: "OpenAPI3", schema: parseSchema(contents) };
}

@@ -137,0 +96,0 @@ else if (typeof schema === "object") {

40

package.json
{
"name": "openapi-typescript",
"description": "Convert OpenAPI 3.0 & 3.1 schemas to TypeScript",
"version": "6.6.1",
"version": "6.6.2-beta.0",
"author": {

@@ -42,2 +42,21 @@ "name": "Drew Powers",

},
"scripts": {
"build": "run-s -s build:*",
"build:clean": "del dist",
"build:esm": "tsc -p tsconfig.build.json",
"build:cjs": "esbuild --bundle --platform=node --target=es2019 --outfile=dist/index.cjs --external:js-yaml --external:undici src/index.ts --footer:js=\"module.exports = module.exports.default;\"",
"dev": "tsc -p tsconfig.build.json --watch",
"download:schemas": "vite-node ./scripts/download-schemas.ts",
"format": "prettier --write \"src/**/*\"",
"lint": "run-p -s lint:*",
"lint:js": "eslint \"{src,test}/**/*.{js,ts}\"",
"lint:prettier": "prettier --check \"src/**/*\"",
"prepare": "pnpm run build",
"test": "run-p -s test:*",
"test:js": "vitest run",
"test:ts": "tsc --noEmit",
"update:examples": "pnpm run download:schemas && vite-node ./scripts/update-examples.ts",
"prepublish": "pnpm run build",
"version": "pnpm run build"
},
"dependencies": {

@@ -62,20 +81,3 @@ "ansi-colors": "^4.1.3",

"vitest": "^0.34.3"
},
"scripts": {
"build": "run-s -s build:*",
"build:esm": "tsc -p tsconfig.build.json",
"build:cjs": "esbuild --bundle --platform=node --target=es2019 --outfile=dist/index.cjs --external:js-yaml --external:undici src/index.ts --footer:js=\"module.exports = module.exports.default;\"",
"dev": "tsc -p tsconfig.build.json --watch",
"download:schemas": "vite-node ./scripts/download-schemas.ts",
"format": "prettier --write \"src/**/*\"",
"lint": "run-p -s lint:*",
"lint:js": "eslint \"{src,test}/**/*.{js,ts}\"",
"lint:prettier": "prettier --check \"src/**/*\"",
"test": "run-p -s test:*",
"test:js": "vitest run",
"test:ts": "tsc --noEmit",
"update:examples": "pnpm run download:schemas && vite-node ./scripts/update-examples.ts",
"prepublish": "pnpm run build",
"version": "pnpm run build"
}
}
}

@@ -17,20 +17,7 @@ import type { ComponentsObject, DiscriminatorObject, Fetch, GlobalContext, OpenAPI3, OperationObject, ParameterObject, PathItemObject, ReferenceObject, RequestBodyObject, ResponseObject, SchemaObject, Subschema } from "./types.js";

function parseYAML(schema: string) {
try {
return yaml.load(schema);
} catch (err) {
error(`YAML: ${String(err)}`);
process.exit(1);
}
/** parse OpenAPI schema s YAML or JSON */
function parseSchema(source: string) {
return source.trim().startsWith("{") ? JSON.parse(source) : yaml.load(source);
}
function parseJSON(schema: string) {
try {
return JSON.parse(schema);
} catch (err) {
error(`JSON: ${String(err)}`);
process.exit(1);
}
}
export function resolveSchema(filename: string): URL {

@@ -112,4 +99,2 @@ // option 1: remote

const ext = path.extname(schema.pathname).toLowerCase();
// remote

@@ -131,14 +116,4 @@ if (schema.protocol.startsWith("http")) {

});
const contentType = res.headers.get("content-type");
if (ext === ".json" || contentType?.includes("json")) {
options.schemas[schemaID] = {
hint,
schema: parseJSON(await res.text()),
};
} else if (ext === ".yaml" || ext === ".yml" || contentType?.includes("yaml")) {
options.schemas[schemaID] = {
hint,
schema: parseYAML(await res.text()) as any, // eslint-disable-line @typescript-eslint/no-explicit-any
};
}
const contents = await res.text();
options.schemas[schemaID] = { hint, schema: parseSchema(contents) };
}

@@ -148,13 +123,3 @@ // local file

const contents = fs.readFileSync(schema, "utf8");
if (ext === ".yaml" || ext === ".yml") {
options.schemas[schemaID] = {
hint,
schema: parseYAML(contents) as any, // eslint-disable-line @typescript-eslint/no-explicit-any
};
} else if (ext === ".json") {
options.schemas[schemaID] = {
hint,
schema: parseJSON(contents),
};
}
options.schemas[schemaID] = { hint, schema: parseSchema(contents) };
}

@@ -176,7 +141,3 @@ }

});
// if file starts with '{' assume JSON
options.schemas[schemaID] = {
hint: "OpenAPI3",
schema: contents.startsWith("{") ? parseJSON(contents) : parseYAML(contents),
};
options.schemas[schemaID] = { hint: "OpenAPI3", schema: parseSchema(contents) };
}

@@ -183,0 +144,0 @@ // 1c. inline

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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