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

@openapi-generator-plus/generator-common

Package Overview
Dependencies
Maintainers
1
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@openapi-generator-plus/generator-common - npm Package Compare versions

Comparing version 0.24.0 to 0.25.0

18

dist/testing.d.ts

@@ -6,9 +6,19 @@ import { CodegenResult } from '@openapi-generator-plus/testing';

*/
export declare type TestGenerateFunc = (basePath: string) => Promise<void>;
export declare type TestGeneratePostProcess = (basePath: string) => Promise<void>;
export interface TestGenerateOptions {
/**
* The name of the test
*/
testName: string;
/**
* A function to handle the generation result.
*/
postProcess?: TestGeneratePostProcess;
clean?: boolean;
}
/**
* Generate the templates for the `CodegenResult` and call `func` to test them.
* @param result a `CodegenResult` from `createCodegenResult`
* @param func a function to handle the generation result
* @param testName the name of the test
* @param options options for the test
*/
export declare function testGenerate(result: CodegenResult, func: TestGenerateFunc, testName: string): Promise<void>;
export declare function testGenerate(result: CodegenResult, options: TestGenerateOptions): Promise<void>;

@@ -27,13 +27,17 @@ "use strict";

* @param result a `CodegenResult` from `createCodegenResult`
* @param func a function to handle the generation result
* @param testName the name of the test
* @param options options for the test
*/
async function testGenerate(result, func, testName) {
async function testGenerate(result, options) {
const { testName, postProcess, clean } = options;
const outputPath = path_1.default.join((0, os_1.tmpdir)(), 'openapi-generator-plus-generators', path_1.default.basename((0, process_1.cwd)()), testName);
/* Clean the output first */
await rimrafPromise(outputPath, { disableGlob: true });
if (clean !== false) {
await rimrafPromise(outputPath, { disableGlob: true });
}
await fs_1.promises.mkdir(outputPath, { recursive: true });
await result.state.generator.exportTemplates(outputPath, result.doc);
await func(outputPath);
if (postProcess) {
await postProcess(outputPath);
}
}
exports.testGenerate = testGenerate;
import { CodegenObjectSchema, CodegenProperties, CodegenProperty } from '@openapi-generator-plus/types';
export { stringify, debugStringify } from '@openapi-generator-plus/core';
/**

@@ -9,2 +10,1 @@ * Return an object containing all of the unique properties, including inherited properties, for a schema, where properties

export declare function uniquePropertiesIncludingInherited(schemas: CodegenObjectSchema[], result?: CodegenProperties): CodegenProperty[];
export declare function stringify(value: any): string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.stringify = exports.uniquePropertiesIncludingInherited = void 0;
exports.uniquePropertiesIncludingInherited = exports.debugStringify = exports.stringify = void 0;
const core_1 = require("@openapi-generator-plus/core");
var core_2 = require("@openapi-generator-plus/core");
Object.defineProperty(exports, "stringify", { enumerable: true, get: function () { return core_2.stringify; } });
Object.defineProperty(exports, "debugStringify", { enumerable: true, get: function () { return core_2.debugStringify; } });
/**

@@ -28,37 +31,1 @@ * Return an object containing all of the unique properties, including inherited properties, for a schema, where properties

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.24.0",
"version": "0.25.0",
"description": "Common utilities for openapi-generator-plus generators",

@@ -22,3 +22,3 @@ "main": "dist/index.js",

"peerDependencies": {
"@openapi-generator-plus/core": "^0.40.0"
"@openapi-generator-plus/core": "^0.41.0"
},

@@ -25,0 +25,0 @@ "publishConfig": {

@@ -24,19 +24,37 @@ import { CodegenResult } from '@openapi-generator-plus/testing'

*/
export type TestGenerateFunc = (basePath: string) => Promise<void>
export type TestGeneratePostProcess = (basePath: string) => Promise<void>
export interface TestGenerateOptions {
/**
* The name of the test
*/
testName: string
/**
* A function to handle the generation result.
*/
postProcess?: TestGeneratePostProcess
clean?: boolean
}
/**
* Generate the templates for the `CodegenResult` and call `func` to test them.
* @param result a `CodegenResult` from `createCodegenResult`
* @param func a function to handle the generation result
* @param testName the name of the test
* @param options options for the test
*/
export async function testGenerate(result: CodegenResult, func: TestGenerateFunc, testName: string): Promise<void> {
export async function testGenerate(result: CodegenResult, options: TestGenerateOptions): Promise<void> {
const { testName, postProcess, clean } = options
const outputPath = path.join(tmpdir(), 'openapi-generator-plus-generators', path.basename(cwd()), testName)
/* Clean the output first */
await rimrafPromise(outputPath, { disableGlob: true })
if (clean !== false) {
await rimrafPromise(outputPath, { disableGlob: true })
}
await fs.mkdir(outputPath, { recursive: true })
await result.state.generator.exportTemplates(outputPath, result.doc)
await func(outputPath)
if (postProcess) {
await postProcess(outputPath)
}
}
import { CodegenObjectSchema, CodegenProperties, CodegenProperty } from '@openapi-generator-plus/types'
import { idx } from '@openapi-generator-plus/core'
export { stringify, debugStringify } from '@openapi-generator-plus/core'

@@ -27,42 +28,1 @@ /**

}
// 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
}
}
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