Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

openapi-typescript

Package Overview
Dependencies
Maintainers
1
Versions
139
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 7.4.1 to 7.4.2

6

CHANGELOG.md
# openapi-typescript
## 7.4.2
### Patch Changes
- [#1873](https://github.com/openapi-ts/openapi-typescript/pull/1873) [`c2c396d`](https://github.com/openapi-ts/openapi-typescript/commit/c2c396d8282692f3ac2df50656ebcd9e8615a685) Thanks [@DanDeMicco](https://github.com/DanDeMicco)! - Support for generating enums when enums definition has null value
## 7.4.1

@@ -4,0 +10,0 @@

16

dist/transform/schema-object.js

@@ -35,3 +35,4 @@ import { parseRef } from "@redocly/openapi-core/lib/ref-utils.js";

!("additionalProperties" in schemaObject)) {
if (options.ctx.enum && schemaObject.enum.every((v) => typeof v === "string" || typeof v === "number")) {
if (options.ctx.enum &&
schemaObject.enum.every((v) => typeof v === "string" || typeof v === "number" || v === null)) {
let enumName = parseRef(options.path ?? "").pointer.join("/");

@@ -43,3 +44,11 @@ enumName = enumName.replace("components/schemas", "");

}));
const enumType = tsEnum(enumName, schemaObject.enum, metadata, {
let hasNull = false;
const validSchemaEnums = schemaObject.enum.filter((enumValue) => {
if (enumValue === null) {
hasNull = true;
return false;
}
return true;
});
const enumType = tsEnum(enumName, validSchemaEnums, metadata, {
shouldCache: options.ctx.dedupeEnums,

@@ -51,3 +60,4 @@ export: true,

}
return ts.factory.createTypeReferenceNode(enumType.name);
const ref = ts.factory.createTypeReferenceNode(enumType.name);
return hasNull ? tsUnion([ref, NULL]) : ref;
}

@@ -54,0 +64,0 @@ const enumType = schemaObject.enum.map(tsLiteral);

2

package.json
{
"name": "openapi-typescript",
"description": "Convert OpenAPI 3.0 & 3.1 schemas to TypeScript",
"version": "7.4.1",
"version": "7.4.2",
"author": {

@@ -6,0 +6,0 @@ "name": "Drew Powers",

@@ -97,3 +97,6 @@ import { parseRef } from "@redocly/openapi-core/lib/ref-utils.js";

// hoist enum to top level if string/number enum and option is enabled
if (options.ctx.enum && schemaObject.enum.every((v) => typeof v === "string" || typeof v === "number")) {
if (
options.ctx.enum &&
schemaObject.enum.every((v) => typeof v === "string" || typeof v === "number" || v === null)
) {
let enumName = parseRef(options.path ?? "").pointer.join("/");

@@ -106,3 +109,14 @@ // allow #/components/schemas to have simpler names

}));
const enumType = tsEnum(enumName, schemaObject.enum as (string | number)[], metadata, {
// enums can contain null values, but dont want to output them
let hasNull = false;
const validSchemaEnums = schemaObject.enum.filter((enumValue) => {
if (enumValue === null) {
hasNull = true;
return false;
}
return true;
});
const enumType = tsEnum(enumName, validSchemaEnums as (string | number)[], metadata, {
shouldCache: options.ctx.dedupeEnums,

@@ -115,3 +129,4 @@ export: true,

}
return ts.factory.createTypeReferenceNode(enumType.name);
const ref = ts.factory.createTypeReferenceNode(enumType.name);
return hasNull ? tsUnion([ref, NULL]) : ref;
}

@@ -118,0 +133,0 @@ const enumType = schemaObject.enum.map(tsLiteral);

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