@openapi-generator-plus/generator-common
Advanced tools
Comparing version 0.6.1 to 0.7.0
@@ -6,2 +6,2 @@ import { CodegenGenerator, CodegenServer, CodegenGeneratorContext, CodegenConfig } from '@openapi-generator-plus/types'; | ||
export declare function commonGenerator(config: CodegenConfig, context: CodegenGeneratorContext): Pick<CodegenGenerator, 'toOperationName' | 'toSchemaName' | 'templateRootContext'>; | ||
export declare function apiBasePath(servers: CodegenServer[] | undefined): string; | ||
export declare function apiBasePath(servers: CodegenServer[] | null): string; |
@@ -9,1 +9,2 @@ import { CodegenModel, CodegenProperties, CodegenProperty } from '@openapi-generator-plus/types'; | ||
export declare function uniquePropertiesIncludingInherited(model: CodegenModel, result?: CodegenProperties): CodegenProperty[]; | ||
export declare function stringify(value: any): string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.uniquePropertiesIncludingInherited = void 0; | ||
exports.stringify = exports.uniquePropertiesIncludingInherited = void 0; | ||
const core_1 = require("@openapi-generator-plus/core"); | ||
@@ -21,1 +21,37 @@ /** | ||
exports.uniquePropertiesIncludingInherited = uniquePropertiesIncludingInherited; | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any | ||
function stringify(value) { | ||
if (value === undefined) { | ||
return 'undefined'; | ||
} | ||
else { | ||
return JSON.stringify(value, refReplacer()); | ||
} | ||
} | ||
exports.stringify = stringify; | ||
/** | ||
* A replacer function for `JSON.stringify` that manages cycles. | ||
* Based on https://stackoverflow.com/a/61749783/1951952 | ||
*/ | ||
function refReplacer() { | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
const paths = new Map(); | ||
let initial; | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
return function (field, value) { | ||
if (!value || typeof value !== 'object' || value === null) { | ||
return value; | ||
} | ||
const knownPath = paths.get(value); | ||
if (knownPath) { | ||
return `#REF:${knownPath}`; | ||
} | ||
if (initial == undefined) { | ||
initial = value; | ||
paths.set(this, '$'); | ||
} | ||
const path = `${paths.get(this)}${field ? (Array.isArray(this) ? `[${field}]` : `.${field}`) : ''}`; | ||
paths.set(value, path); | ||
return value; | ||
}; | ||
} |
{ | ||
"name": "@openapi-generator-plus/generator-common", | ||
"version": "0.6.1", | ||
"version": "0.7.0", | ||
"description": "Common utilities for openapi-generator-plus generators", | ||
@@ -28,3 +28,3 @@ "main": "dist/index.js", | ||
"peerDependencies": { | ||
"@openapi-generator-plus/core": "^0.17.0" | ||
"@openapi-generator-plus/core": "^0.18.0" | ||
}, | ||
@@ -34,3 +34,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "bb6db1d106fa33e87512fd049b952868a48af604" | ||
"gitHead": "9f041c2ef5d37f40ef2dc9055258d73306bb2161" | ||
} |
@@ -41,3 +41,3 @@ import { CodegenGenerator, CodegenServer, CodegenSchemaPurpose, CodegenGeneratorContext, CodegenConfig } from '@openapi-generator-plus/types' | ||
export function apiBasePath(servers: CodegenServer[] | undefined): string { | ||
export function apiBasePath(servers: CodegenServer[] | null): string { | ||
if (!servers || !servers.length) { | ||
@@ -44,0 +44,0 @@ return '/' |
@@ -20,1 +20,42 @@ import { CodegenModel, CodegenProperties, CodegenProperty } from '@openapi-generator-plus/types' | ||
} | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any | ||
export function stringify(value: any): string { | ||
if (value === undefined) { | ||
return 'undefined' | ||
} else { | ||
return JSON.stringify(value, refReplacer()) | ||
} | ||
} | ||
/** | ||
* A replacer function for `JSON.stringify` that manages cycles. | ||
* Based on https://stackoverflow.com/a/61749783/1951952 | ||
*/ | ||
function refReplacer() { | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
const paths = new Map<object, string>() | ||
let initial: unknown | undefined | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
return function(this: object, field: string, value: unknown) { | ||
if (!value || typeof value !== 'object' || value === null) { | ||
return value | ||
} | ||
const knownPath = paths.get(value) | ||
if (knownPath) { | ||
return `#REF:${knownPath}` | ||
} | ||
if (initial == undefined) { | ||
initial = value | ||
paths.set(this, '$') | ||
} | ||
const path = `${paths.get(this)}${field ? (Array.isArray(this) ? `[${field}]` : `.${field}`) : ''}` | ||
paths.set(value, path) | ||
return value | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34939
550