From 0bf55ed3c55587754accd6e0897e4644c378c44c Mon Sep 17 00:00:00 2001 From: Sam Chung Date: Wed, 19 Jun 2024 12:57:50 +1000 Subject: [PATCH] Optimise Types (#288) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- scripts/copyTypes.ts | 23 +++++++++++++++++++++-- src/openapi3-ts/dist/index.ts | 2 +- src/openapi3-ts/dist/model/oas-common.ts | 2 -- src/openapi3-ts/dist/model/openapi30.ts | 5 +---- src/openapi3-ts/dist/model/openapi31.ts | 5 +---- src/openapi3-ts/dist/oas30.ts | 4 ++-- src/openapi3-ts/dist/oas31.ts | 4 ++-- 7 files changed, 28 insertions(+), 17 deletions(-) diff --git a/scripts/copyTypes.ts b/scripts/copyTypes.ts index f25ff3e..adf0782 100644 --- a/scripts/copyTypes.ts +++ b/scripts/copyTypes.ts @@ -24,11 +24,30 @@ async function copyDTs(src: string, dest: string): Promise { const contents = (await fs.readFile(destination)).toString('utf-8'); if (contents.includes('export { Server, ServerVariable }')) { + const patched = contents + .replaceAll(/export \{ Server, ServerVariable \}.*/g, '') + .replaceAll(/.*\.\/dsl\/openapi-builder.*/g, ''); + await fs.writeFile(destination, Buffer.from(patched)); + continue; + } + if ( + contents.includes( + ", SpecificationExtension } from './specification-extension';", + ) + ) { + const patched = contents + .replace(', SpecificationExtension }', ' }') + .replaceAll(/.*export declare function.*\n/g, ''); + await fs.writeFile(destination, Buffer.from(patched)); + continue; + } + if (contents.includes('export declare function getExtension')) { const patched = contents.replaceAll( - 'export { Server, ServerVariable }', - 'export type { Server, ServerVariable }', + /.*export declare function.*\n/g, + '', ); await fs.writeFile(destination, Buffer.from(patched)); + continue; } } } diff --git a/src/openapi3-ts/dist/index.ts b/src/openapi3-ts/dist/index.ts index a7d3106..e31ae11 100644 --- a/src/openapi3-ts/dist/index.ts +++ b/src/openapi3-ts/dist/index.ts @@ -1,3 +1,3 @@ export * as oas30 from "./oas30"; export * as oas31 from "./oas31"; -export type { Server, ServerVariable } from "./model/server"; + diff --git a/src/openapi3-ts/dist/model/oas-common.ts b/src/openapi3-ts/dist/model/oas-common.ts index cf477a3..d4b3a18 100644 --- a/src/openapi3-ts/dist/model/oas-common.ts +++ b/src/openapi3-ts/dist/model/oas-common.ts @@ -11,5 +11,3 @@ export interface ServerVariableObject extends ISpecificationExtension { default: string | boolean | number; description?: string; } -export declare function getExtension(obj: ISpecificationExtension | undefined, extensionName: string): any; -export declare function addExtension(obj: ISpecificationExtension | undefined, extensionName: string, extension: any): void; diff --git a/src/openapi3-ts/dist/model/openapi30.ts b/src/openapi3-ts/dist/model/openapi30.ts index 30ade75..267052d 100644 --- a/src/openapi3-ts/dist/model/openapi30.ts +++ b/src/openapi3-ts/dist/model/openapi30.ts @@ -1,7 +1,7 @@ import { ServerObject } from './oas-common'; import { ISpecificationExtension } from './specification-extension'; export * from './oas-common'; -export type { ISpecificationExtension, SpecificationExtension } from './specification-extension'; +export type { ISpecificationExtension } from './specification-extension'; export interface OpenAPIObject extends ISpecificationExtension { openapi: string; info: InfoObject; @@ -62,7 +62,6 @@ export interface PathsObject extends ISpecificationExtension { [path: string]: PathItemObject; } export type PathObject = PathsObject; -export declare function getPath(pathsObject: PathsObject, path: string): PathItemObject | undefined; export interface PathItemObject extends ISpecificationExtension { $ref?: string; summary?: string; @@ -200,7 +199,6 @@ export interface ExamplesObject { export interface ReferenceObject { $ref: string; } -export declare function isReferenceObject(obj: any): obj is ReferenceObject; export type SchemaObjectType = 'integer' | 'number' | 'string' | 'boolean' | 'object' | 'null' | 'array'; export type SchemaObjectFormat = 'int32' | 'int64' | 'float' | 'double' | 'byte' | 'binary' | 'date' | 'date-time' | 'password' | string; export interface SchemaObject extends ISpecificationExtension { @@ -243,7 +241,6 @@ export interface SchemaObject extends ISpecificationExtension { required?: string[]; enum?: any[]; } -export declare function isSchemaObject(schema: SchemaObject | ReferenceObject): schema is SchemaObject; export interface SchemasObject { [schema: string]: SchemaObject; } diff --git a/src/openapi3-ts/dist/model/openapi31.ts b/src/openapi3-ts/dist/model/openapi31.ts index 0d3d7a6..3989074 100644 --- a/src/openapi3-ts/dist/model/openapi31.ts +++ b/src/openapi3-ts/dist/model/openapi31.ts @@ -1,7 +1,7 @@ import { ServerObject } from './oas-common'; import { ISpecificationExtension } from './specification-extension'; export * from './oas-common'; -export type { ISpecificationExtension, SpecificationExtension } from './specification-extension'; +export type { ISpecificationExtension } from './specification-extension'; export interface OpenAPIObject extends ISpecificationExtension { openapi: string; info: InfoObject; @@ -64,7 +64,6 @@ export interface PathsObject extends ISpecificationExtension { [path: string]: PathItemObject; } export type PathObject = PathsObject; -export declare function getPath(pathsObject: PathsObject | undefined, path: string): PathItemObject | undefined; export interface PathItemObject extends ISpecificationExtension { $ref?: string; summary?: string; @@ -204,7 +203,6 @@ export interface ReferenceObject { summary?: string; description?: string; } -export declare function isReferenceObject(obj: any): obj is ReferenceObject; export type SchemaObjectType = 'integer' | 'number' | 'string' | 'boolean' | 'object' | 'null' | 'array'; export interface SchemaObject extends ISpecificationExtension { discriminator?: DiscriminatorObject; @@ -250,7 +248,6 @@ export interface SchemaObject extends ISpecificationExtension { contentMediaType?: string; contentEncoding?: string; } -export declare function isSchemaObject(schema: SchemaObject | ReferenceObject): schema is SchemaObject; export interface SchemasObject { [schema: string]: SchemaObject; } diff --git a/src/openapi3-ts/dist/oas30.ts b/src/openapi3-ts/dist/oas30.ts index 2ba57db..8b9159d 100644 --- a/src/openapi3-ts/dist/oas30.ts +++ b/src/openapi3-ts/dist/oas30.ts @@ -1,4 +1,4 @@ -export * from './dsl/openapi-builder30'; + export * from './model/openapi30'; -export type { Server, ServerVariable } from './model/server'; + export type { IExtensionName, IExtensionType, ISpecificationExtension } from './model/specification-extension'; diff --git a/src/openapi3-ts/dist/oas31.ts b/src/openapi3-ts/dist/oas31.ts index ba438bc..e47f544 100644 --- a/src/openapi3-ts/dist/oas31.ts +++ b/src/openapi3-ts/dist/oas31.ts @@ -1,4 +1,4 @@ -export * from './dsl/openapi-builder31'; + export * from './model/openapi31'; -export type { Server, ServerVariable } from './model/server'; + export type { IExtensionName, IExtensionType, ISpecificationExtension } from './model/specification-extension';