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 5.3.0 to 5.4.0

13

bin/cli.js

@@ -24,2 +24,3 @@ #!/usr/bin/env node

--immutable-types, -it (optional) Generates immutable types (readonly properties and readonly array)
--content-never (optional) If supplied, an omitted reponse \`content\` property will be generated as \`never\` instead of \`unknown\`
--additional-properties, -ap (optional) Allow arbitrary properties for all schema objects without "additionalProperties: false"

@@ -49,3 +50,12 @@ --default-non-nullable (optional) If a schema object has a default value set, don’t mark it as nullable

array: ["header"],
boolean: ["defaultNonNullable", "immutableTypes", "rawSchema", "exportType", "supportArrayLength", "makePathsEnum", "pathParamsAsTypes"],
boolean: [
"defaultNonNullable",
"immutableTypes",
"contentNever",
"rawSchema",
"exportType",
"supportArrayLength",
"makePathsEnum",
"pathParamsAsTypes",
],
number: ["version"],

@@ -97,2 +107,3 @@ string: ["auth", "header", "headersObject", "httpMethod", "prettierConfig"],

makePathsEnum: flags.makePathsEnum,
contentNever: flags.contentNever,
silent: output === OUTPUT_STDOUT,

@@ -99,0 +110,0 @@ version: flags.version,

/// <reference types="node" />
/// <reference types="node" />
import type { OpenAPI2, OpenAPI3, SchemaObject, SwaggerToTSOptions } from "./types.js";

@@ -3,0 +4,0 @@ import { Readable } from "stream";

import path from "path";
import fs from "fs";
import prettier from "prettier";

@@ -25,2 +26,3 @@ import parserTypescript from "prettier/parser-typescript.js";

immutableTypes: options.immutableTypes || false,
contentNever: options.contentNever || false,
makePathsEnum: options.makePathsEnum || false,

@@ -85,3 +87,5 @@ pathParamsAsTypes: options.pathParamsAsTypes,

try {
const userOptions = await prettier.resolveConfig(path.resolve(process.cwd(), options.prettierConfig));
const prettierConfigFile = path.resolve(process.cwd(), options.prettierConfig);
await fs.promises.access(prettierConfigFile, fs.constants.F_OK);
const userOptions = await prettier.resolveConfig(prettierConfigFile);
prettierOptions = {

@@ -95,2 +99,3 @@ ...(userOptions || {}),

console.error(`❌ ${err}`);
process.exit(1);
}

@@ -97,0 +102,0 @@ }

/// <reference types="node" />
/// <reference types="node" />
import type { GlobalContext, Headers } from "./types.js";

@@ -3,0 +4,0 @@ import { Readable } from "stream";

2

dist/transform/paths.js

@@ -77,3 +77,3 @@ import { comment, tsReadonly, nodeType } from "../utils.js";

export function makeApiPathsEnum(paths) {
let output = "enum ApiPaths {\n";
let output = "export enum ApiPaths {\n";
for (const [url, pathItem] of Object.entries(paths)) {

@@ -80,0 +80,0 @@ for (const [method, operation] of Object.entries(pathItem)) {

import { comment, tsReadonly } from "../utils.js";
import { transformHeaderObjMap } from "./headers.js";
import { transformSchemaObj } from "./schema.js";
const resType = (res) => (res === 204 || (res >= 300 && res < 400) ? "never" : "unknown");
export function transformResponsesObj(responsesObj, ctx) {
const readonly = tsReadonly(ctx.immutableTypes);
const resType = (res) => {
if (tsReadonly(ctx.contentNever)) {
return "never";
}
else {
return res === 204 || (res >= 300 && res < 400) ? "never" : "unknown";
}
};
let output = "";

@@ -8,0 +15,0 @@ for (const httpStatusCode of Object.keys(responsesObj)) {

@@ -115,2 +115,3 @@ /// <reference types="node" />

immutableTypes?: boolean;
contentNever?: boolean;
defaultNonNullable?: boolean;

@@ -136,2 +137,3 @@ prettierConfig?: string;

immutableTypes: boolean;
contentNever: boolean;
makePathsEnum: boolean;

@@ -138,0 +140,0 @@ namespace?: string;

@@ -20,4 +20,11 @@ const COMMENT_RE = /\*\//g;

const field = supportedJsDocTags[index];
if (v[field])
commentsArray.push(`@${field} ${v[field]} `);
const allowEmptyString = field === "default" || field === "example";
if (v[field] === undefined) {
continue;
}
if (v[field] === "" && !allowEmptyString) {
continue;
}
const serialized = typeof v[field] === "object" ? JSON.stringify(v[field], null, 2) : v[field];
commentsArray.push(`@${field} ${serialized} `);
}

@@ -24,0 +31,0 @@ if (v.const)

{
"name": "openapi-typescript",
"description": "Generate TypeScript types from Swagger OpenAPI specs",
"version": "5.3.0",
"version": "5.4.0",
"engines": {

@@ -42,3 +42,3 @@ "node": ">= 14.0.0",

"scripts": {
"build": "rm -rf dist && tsc",
"build": "del dist && tsc",
"format": "npm run prettier -w .",

@@ -49,3 +49,3 @@ "lint": "eslint .",

"test": "mocha --recursive --timeout 30000",
"test:coverage": "nyc --reporter=lcov mocha --recursive --timeout 30000 && codecov",
"test:coverage": "nyc --reporter=lcov mocha --recursive --timeout 30000",
"version": "npm run build"

@@ -58,3 +58,3 @@ },

"tiny-glob": "^0.2.9",
"undici": "^5.0.0",
"undici": "^5.4.0",
"yargs-parser": "^21.0.1"

@@ -65,10 +65,10 @@ },

"@types/mime": "^2.0.3",
"@types/node": "^17.0.25",
"@types/prettier": "^2.6.0",
"@typescript-eslint/eslint-plugin": "^5.20.0",
"@typescript-eslint/parser": "^5.20.0",
"@types/node": "^17.0.38",
"@types/prettier": "^2.6.3",
"@typescript-eslint/eslint-plugin": "^5.27.0",
"@typescript-eslint/parser": "^5.27.0",
"chai": "^4.3.6",
"codecov": "^3.8.3",
"del-cli": "^4.0.1",
"eol": "^0.9.1",
"eslint": "^8.14.0",
"eslint": "^8.16.0",
"eslint-config-prettier": "^8.5.0",

@@ -78,4 +78,4 @@ "eslint-plugin-prettier": "^4.0.0",

"nyc": "^15.1.0",
"typescript": "^4.6.3"
"typescript": "^4.7.2"
}
}

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

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-51-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-52-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

@@ -321,2 +321,3 @@

<td align="center"><a href="https://powell-v2.github.io/"><img src="https://avatars.githubusercontent.com/u/25308326?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Pavel Yermolin</b></sub></a><br /><a href="https://github.com/drwpow/openapi-typescript/commits?author=Powell-v2" title="Code">💻</a> <a href="https://github.com/drwpow/openapi-typescript/commits?author=Powell-v2" title="Documentation">📖</a> <a href="https://github.com/drwpow/openapi-typescript/commits?author=Powell-v2" title="Tests">⚠️</a></td>
<td align="center"><a href="http://www.duncanbeevers.com"><img src="https://avatars.githubusercontent.com/u/7367?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Duncan Beevers</b></sub></a><br /><a href="https://github.com/drwpow/openapi-typescript/commits?author=duncanbeevers" title="Code">💻</a> <a href="https://github.com/drwpow/openapi-typescript/issues?q=author%3Aduncanbeevers" title="Bug reports">🐛</a> <a href="https://github.com/drwpow/openapi-typescript/commits?author=duncanbeevers" title="Tests">⚠️</a></td>
</tr>

@@ -323,0 +324,0 @@ </table>

import type { GlobalContext, OpenAPI2, OpenAPI3, SchemaObject, SwaggerToTSOptions } from "./types.js";
import path from "path";
import fs from "fs";
import prettier from "prettier";

@@ -45,2 +46,3 @@ import parserTypescript from "prettier/parser-typescript.js";

immutableTypes: options.immutableTypes || false,
contentNever: options.contentNever || false,
makePathsEnum: options.makePathsEnum || false,

@@ -119,3 +121,5 @@ pathParamsAsTypes: options.pathParamsAsTypes,

try {
const userOptions = await prettier.resolveConfig(path.resolve(process.cwd(), options.prettierConfig));
const prettierConfigFile = path.resolve(process.cwd(), options.prettierConfig);
await fs.promises.access(prettierConfigFile, fs.constants.F_OK);
const userOptions = await prettier.resolveConfig(prettierConfigFile);
prettierOptions = {

@@ -128,2 +132,3 @@ ...(userOptions || {}),

console.error(`❌ ${err}`);
process.exit(1);
}

@@ -130,0 +135,0 @@ }

@@ -104,3 +104,3 @@ import type { GlobalContext, OperationObject, ParameterObject, PathItemObject } from "../types.js";

export function makeApiPathsEnum(paths: Record<string, PathItemObject>): string {
let output = "enum ApiPaths {\n";
let output = "export enum ApiPaths {\n";

@@ -107,0 +107,0 @@ for (const [url, pathItem] of Object.entries(paths)) {

@@ -6,6 +6,11 @@ import type { GlobalContext } from "../types.js";

const resType = (res: string | number) => (res === 204 || (res >= 300 && res < 400) ? "never" : "unknown");
export function transformResponsesObj(responsesObj: Record<string, any>, ctx: GlobalContext): string {
const readonly = tsReadonly(ctx.immutableTypes);
const resType = (res: string | number) => {
if (tsReadonly(ctx.contentNever)) {
return "never";
} else {
return res === 204 || (res >= 300 && res < 400) ? "never" : "unknown";
}
};

@@ -12,0 +17,0 @@ let output = "";

@@ -129,2 +129,4 @@ import type { URL } from "url";

immutableTypes?: boolean;
/** (optional) If supplied, an omitted reponse \`content\` property will be generated as \`never\` instead of \`unknown\` */
contentNever?: boolean;
/** (optional) Treat schema objects with default values as non-nullable */

@@ -184,2 +186,3 @@ defaultNonNullable?: boolean;

immutableTypes: boolean;
contentNever: boolean;
makePathsEnum: boolean;

@@ -186,0 +189,0 @@ namespace?: string;

@@ -45,3 +45,11 @@ import type { OpenAPI2, OpenAPI3, ReferenceObject } from "./types.js";

const field = supportedJsDocTags[index];
if (v[field]) commentsArray.push(`@${field} ${v[field]} `);
const allowEmptyString = field === "default" || field === "example";
if (v[field] === undefined) {
continue;
}
if (v[field] === "" && !allowEmptyString) {
continue;
}
const serialized = typeof v[field] === "object" ? JSON.stringify(v[field], null, 2) : v[field];
commentsArray.push(`@${field} ${serialized} `);
}

@@ -48,0 +56,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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