diff --git a/scripts/testCodeGen.ts b/scripts/testCodeGen.ts index f2d67fe4..98a4a0b2 100644 --- a/scripts/testCodeGen.ts +++ b/scripts/testCodeGen.ts @@ -1,7 +1,7 @@ import * as fs from "fs"; import { posix as path } from "path"; -import { CodeGenerator } from "../lib"; +import { CodeGenerator, GeneratorTemplate } from "../lib"; import * as Templates from "../lib/templates"; const writeText = (filename: string, text: string): void => { @@ -13,7 +13,7 @@ const writeText = (filename: string, text: string): void => { const generateTypedefCodeOnly = (inputFilename: string, outputFilename: string, isValidate: boolean) => { const codeGenerator = new CodeGenerator(inputFilename); if (isValidate) { - codeGenerator.validate({ + codeGenerator.validateOpenApiSchema({ logger: { displayLogLines: 1 }, }); } @@ -29,14 +29,17 @@ const generateTemplateCodeOnly = ( ): void => { const codeGenerator = new CodeGenerator(inputFilename); if (isValidate) { - codeGenerator.validate({ + codeGenerator.validateOpenApiSchema({ logger: { displayLogLines: 1 }, }); } - const code = codeGenerator.generateCode({ + + const apiClientGeneratorTemplate: GeneratorTemplate = { generator: Templates.ApiClient.generator, option: option, - }); + }; + + const code = codeGenerator.generateCode([apiClientGeneratorTemplate]); writeText(outputFilename, code); }; @@ -49,18 +52,53 @@ const generateTypedefWithTemplateCode = ( ): void => { const codeGenerator = new CodeGenerator(inputFilename); if (isValidate) { - codeGenerator.validate({ + codeGenerator.validateOpenApiSchema({ logger: { displayLogLines: 1 }, }); } - const code = codeGenerator.generateTypeDefinition({ - generator: Templates.ApiClient.generator, - option: option, - }); + + const code = codeGenerator.generateTypeDefinition([ + { + generator: () => { + return codeGenerator.getAdditionalTypeStatements(); + }, + }, + { + generator: Templates.ApiClient.generator, + option: option, + }, + ]); writeText(outputFilename, code); }; +const generateSplitCode = (inputFilename: string, outputDir: string) => { + const codeGenerator = new CodeGenerator(inputFilename); + + const apiClientGeneratorTemplate: GeneratorTemplate = { + generator: Templates.ApiClient.generator, + option: { sync: false }, + }; + + const typeDefCode = codeGenerator.generateTypeDefinition(); + const apiClientCode = codeGenerator.generateCode([ + { + generator: () => { + return [`import { Schemas } from "./types";`]; + }, + }, + { + generator: () => { + return codeGenerator.getAdditionalTypeStatements(); + }, + }, + apiClientGeneratorTemplate, + ]); + + writeText(path.join(outputDir, "types.ts"), typeDefCode); + writeText(path.join(outputDir, "apiClient.ts"), apiClientCode); +}; + const main = () => { generateTypedefCodeOnly("test/api.test.domain/index.yml", "test/code/typedef-only/api.test.domain.ts", true); generateTypedefCodeOnly("test/infer.domain/index.yml", "test/code/typedef-only/infer.domain.ts", false); @@ -69,9 +107,15 @@ const main = () => { generateTemplateCodeOnly("test/api.test.domain/index.yml", "test/code/template-only/sync-api.test.domain.ts", true, { sync: true }); generateTemplateCodeOnly("test/infer.domain/index.yml", "test/code/template-only/infer.domain.ts", false, { sync: true }); - generateTypedefWithTemplateCode("test/api.test.domain/index.yml", "test/code/typedef-with-template/api.test.domain.ts", true, { sync: false }); - generateTypedefWithTemplateCode("test/api.test.domain/index.yml", "test/code/typedef-with-template/sync-api.test.domain.ts", true, { sync: true }); + generateTypedefWithTemplateCode("test/api.test.domain/index.yml", "test/code/typedef-with-template/api.test.domain.ts", true, { + sync: false, + }); + generateTypedefWithTemplateCode("test/api.test.domain/index.yml", "test/code/typedef-with-template/sync-api.test.domain.ts", true, { + sync: true, + }); generateTypedefWithTemplateCode("test/infer.domain/index.yml", "test/code/typedef-with-template/infer.domain.ts", false, { sync: false }); + + generateSplitCode("test/api.test.domain/index.yml", "test/code/split"); }; main(); diff --git a/src/index.ts b/src/index.ts index f5ab025d..c093413b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,8 @@ import { EOL } from "os"; -import { OpenApiTools, ResolveReference, TsGenerator, Validator, FileSystem } from "./api"; +import ts from "typescript"; + +import * as Api from "./api"; import type * as Types from "./types"; export interface GeneratorTemplate { @@ -11,43 +13,75 @@ export interface GeneratorTemplate { export class CodeGenerator { private rootSchema: Types.OpenApi.Document; private resolvedReferenceDocument: Types.OpenApi.Document; - private parser: OpenApiTools.Parser; + private parser: Api.OpenApiTools.Parser; constructor(private readonly entryPoint: string) { - this.rootSchema = FileSystem.loadJsonOrYaml(entryPoint); - this.resolvedReferenceDocument = ResolveReference.resolve(entryPoint, entryPoint, JSON.parse(JSON.stringify(this.rootSchema))); + this.rootSchema = Api.FileSystem.loadJsonOrYaml(entryPoint); + this.resolvedReferenceDocument = Api.ResolveReference.resolve(entryPoint, entryPoint, JSON.parse(JSON.stringify(this.rootSchema))); this.parser = this.createParser(); } - private createParser(allowOperationIds?: string[]): OpenApiTools.Parser { - return new OpenApiTools.Parser(this.entryPoint, this.rootSchema, this.resolvedReferenceDocument, { + private createParser(allowOperationIds?: string[]): Api.OpenApiTools.Parser { + return new Api.OpenApiTools.Parser(this.entryPoint, this.rootSchema, this.resolvedReferenceDocument, { allowOperationIds: allowOperationIds, }); } - public validate(config?: Types.Validator.Configuration) { - if (!config) { - Validator.validate(this.resolvedReferenceDocument); + /** + * Validate the OpenAPI Schema + */ + public validateOpenApiSchema(option?: Types.Validator.Option) { + if (!option) { + Api.Validator.validate(this.resolvedReferenceDocument); } else { - Validator.validate(this.resolvedReferenceDocument, config.logger); + Api.Validator.validate(this.resolvedReferenceDocument, option.logger); } } - public generateTypeDefinition(generatorTemplate?: GeneratorTemplate): string { + /** + * Provides TypeScript typedefs generated from OpenAPI Schema. + * + * @param generatorTemplate Template for when you want to change the code following a type definition + * @returns String of generated code + */ + public generateTypeDefinition(generatorTemplates?: GeneratorTemplate[]): string { const create = () => { - const statements = this.parser.getTypeDefinitionStatements(); - if (generatorTemplate) { + const statements = this.parser.getOpenApiTypeDefinitionStatements(); + generatorTemplates?.forEach(generatorTemplate => { const payload = this.parser.getCodeGeneratorParamsArray(); - const extraStatements = TsGenerator.Utils.convertIntermediateCodes(generatorTemplate.generator(payload, generatorTemplate.option)); - return statements.concat(extraStatements); - } + const extraStatements = Api.TsGenerator.Utils.convertIntermediateCodes(generatorTemplate.generator(payload, generatorTemplate.option)); + statements.push(...extraStatements); + }); return statements; }; - return [OpenApiTools.Comment.generateLeading(this.resolvedReferenceDocument), TsGenerator.generate(create)].join(EOL + EOL + EOL); + return [Api.OpenApiTools.Comment.generateLeading(this.resolvedReferenceDocument), Api.TsGenerator.generate(create)].join(EOL + EOL + EOL); } - public generateCode(generatorTemplate: GeneratorTemplate): string { + /** + * Generate code using a template + * + * @param generatorTemplate + * @returns String of generated code + */ + public generateCode(generatorTemplates: GeneratorTemplate[]): string { const payload = this.parser.getCodeGeneratorParamsArray(); - const create = () => TsGenerator.Utils.convertIntermediateCodes(generatorTemplate?.generator(payload, generatorTemplate.option)); - return [OpenApiTools.Comment.generateLeading(this.resolvedReferenceDocument), TsGenerator.generate(create)].join(EOL + EOL + EOL); + const create = () => { + return generatorTemplates + .map(generatorTemplate => { + return Api.TsGenerator.Utils.convertIntermediateCodes(generatorTemplate?.generator(payload, generatorTemplate.option)); + }) + .flat(); + }; + return [Api.OpenApiTools.Comment.generateLeading(this.resolvedReferenceDocument), Api.TsGenerator.generate(create)].join(EOL + EOL + EOL); + } + + /** + * Provides parameters extracted from OpenApi Schema + */ + public getCodeGeneratorParamsArray(): Types.CodeGenerator.Params[] { + return this.parser.getCodeGeneratorParamsArray(); + } + + public getAdditionalTypeStatements(): ts.Statement[] { + return this.parser.getAdditionalTypeStatements(); } } diff --git a/src/internal/OpenApiTools/Parser.ts b/src/internal/OpenApiTools/Parser.ts index 41e58fec..c20276e5 100644 --- a/src/internal/OpenApiTools/Parser.ts +++ b/src/internal/OpenApiTools/Parser.ts @@ -130,7 +130,11 @@ export class Parser { return Extractor.generateCodeGeneratorParamsArray(this.store, this.convertContext, this.option.allowOperationIds); } - public getTypeDefinitionStatements(): ts.Statement[] { + public getOpenApiTypeDefinitionStatements(): ts.Statement[] { return this.store.getRootStatements(); } + + public getAdditionalTypeStatements(): ts.Statement[] { + return this.store.getAdditionalStatements(); + } } diff --git a/src/internal/OpenApiTools/store/Store.ts b/src/internal/OpenApiTools/store/Store.ts index de810f30..ece94703 100644 --- a/src/internal/OpenApiTools/store/Store.ts +++ b/src/internal/OpenApiTools/store/Store.ts @@ -5,8 +5,8 @@ import Dot from "dot-prop"; import ts from "typescript"; import type { OpenApi } from "../../../types"; -import { Factory } from "../../TsGenerator"; import { UnSupportError } from "../../Exception"; +import { Factory } from "../../TsGenerator"; import * as Def from "./Definition"; import * as Operation from "./Operation"; import * as State from "./State"; @@ -25,6 +25,7 @@ export interface Type { hasStatement: (path: string, types: Structure.DataStructure.Kind[]) => boolean; addAdditionalStatement: (statements: ts.Statement[]) => void; getRootStatements: () => ts.Statement[]; + getAdditionalStatements: () => ts.Statement[]; updateOperationState: (httpMethod: string, requestUri: string, operationId: string, state: Partial) => void; getNoReferenceOperationState: () => Operation.State; getPathItem: (localPath: string) => OpenApi.PathItem; @@ -75,7 +76,11 @@ export const create = (factory: Factory.Type, rootDocument: OpenApi.Document): T } return statements; }, []); - return statements.concat(state.additionalStatements); + return statements; + }; + + const getAdditionalStatements = (): ts.Statement[] => { + return state.additionalStatements; }; return { @@ -95,6 +100,7 @@ export const create = (factory: Factory.Type, rootDocument: OpenApi.Document): T return getChildByPaths(targetPath, kind); }, getRootStatements, + getAdditionalStatements, addComponent: (componentName: Def.ComponentName, statement: Structure.ComponentParams): void => { operator.set(`${componentName}`, Structure.createInstance(statement)); }, diff --git a/src/typedef/Validator.ts b/src/typedef/Validator.ts index bc056fa6..43fe7621 100644 --- a/src/typedef/Validator.ts +++ b/src/typedef/Validator.ts @@ -5,6 +5,6 @@ export interface Logger { */ displayLogLines?: number; } -export interface Configuration { +export interface Option { logger?: Logger; } diff --git a/test/__tests__/__snapshots__/spit-code-test.ts.snap b/test/__tests__/__snapshots__/spit-code-test.ts.snap new file mode 100644 index 00000000..7c419b62 --- /dev/null +++ b/test/__tests__/__snapshots__/spit-code-test.ts.snap @@ -0,0 +1,412 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Split Code apiClient 1`] = ` +"// +// Generated by @himenon/openapi-typescript-code-generator +// +// OpenApi : 3.1.0 +// +// License : MIT +// + + +import { Schemas } from \\"./types\\"; +export interface Parameter$getIncludeLocalReference { + /** parameters.StringQueryParams */ + StringQuery: string; +} +export interface Response$getIncludeLocalReference$Status$200 { + \\"application/json\\": { + meta: string; + }; +} +export interface Parameter$getIncludeRemoteReference { + /** remote reference parameter */ + IncludeRemoteReference: number; +} +export interface RequestBody$getIncludeRemoteReference { + \\"application/json\\": string; +} +export interface Parameter$getFullRemoteReference { + /** Full Remote Reference */ + FullRemoteReferenceQuery: Schemas.FullRemoteReference.ForParameters; +} +export interface Response$getFullRemoteReference$Status$200 { + \\"application/json\\": { + /** responseA description */ + name?: \\"responseA\\"; + }; +} +export interface Response$getReferenceItems$Status$200 { + \\"application/json\\": { + books?: Schemas.Item[]; + }; +} +export type ResponseContentType$getIncludeLocalReference = keyof Response$getIncludeLocalReference$Status$200; +export interface Params$getIncludeLocalReference { + parameter: Parameter$getIncludeLocalReference; +} +export type RequestContentType$getIncludeRemoteReference = keyof RequestBody$getIncludeRemoteReference; +export interface Params$getIncludeRemoteReference { + parameter: Parameter$getIncludeRemoteReference; + requestBody: RequestBody$getIncludeRemoteReference[\\"application/json\\"]; +} +export type ResponseContentType$getFullRemoteReference = keyof Response$getFullRemoteReference$Status$200; +export interface Params$getFullRemoteReference { + parameter: Parameter$getFullRemoteReference; +} +export type ResponseContentType$getReferenceItems = keyof Response$getReferenceItems$Status$200; +export type HttpMethod = \\"GET\\" | \\"PUT\\" | \\"POST\\" | \\"DELETE\\" | \\"OPTIONS\\" | \\"HEAD\\" | \\"PATCH\\" | \\"TRACE\\"; +export interface ObjectLike { + [key: string]: any; +} +export interface QueryParameter { + value: any; + style?: \\"form\\" | \\"spaceDelimited\\" | \\"pipeDelimited\\" | \\"deepObject\\"; + explode: boolean; +} +export interface QueryParameters { + [key: string]: QueryParameter; +} +export type SuccessResponses = Response$getIncludeLocalReference$Status$200 | Response$getFullRemoteReference$Status$200 | Response$getReferenceItems$Status$200; +export namespace ErrorResponse { + export type getIncludeLocalReference = void; + export type getIncludeRemoteReference = void; + export type getFullRemoteReference = void; + export type getReferenceItems = void; +} +export interface ApiClient { + request: (httpMethod: HttpMethod, url: string, headers: ObjectLike | any, requestBody: ObjectLike | any, queryParameters: QueryParameters | undefined, options?: RequestOption) => Promise; +} +export class Client { + constructor(private apiClient: ApiClient, private baseUrl: string) { } + public async getIncludeLocalReference(params: Params$getIncludeLocalReference, option?: RequestOption): Promise { + const url = this.baseUrl + \`/get/IncludeLocalReference\`; + const headers = { + Accept: \\"application/json\\" + }; + const queryParameters: QueryParameters = { + StringQuery: { value: params.parameter.StringQuery, explode: false } + }; + return this.apiClient.request(\\"GET\\", url, headers, undefined, queryParameters, option); + } + public async getIncludeRemoteReference(params: Params$getIncludeRemoteReference, option?: RequestOption): Promise { + const url = this.baseUrl + \`/get/IncludeRemoteReference\`; + const headers = { + \\"Content-Type\\": \\"application/json\\" + }; + const queryParameters: QueryParameters = { + IncludeRemoteReference: { value: params.parameter.IncludeRemoteReference, explode: false } + }; + return this.apiClient.request(\\"GET\\", url, headers, params.requestBody, queryParameters, option); + } + public async getFullRemoteReference(params: Params$getFullRemoteReference, option?: RequestOption): Promise { + const url = this.baseUrl + \`/FullRemoteReference\`; + const headers = { + Accept: \\"application/json\\" + }; + const queryParameters: QueryParameters = { + FullRemoteReferenceQuery: { value: params.parameter.FullRemoteReferenceQuery, explode: false } + }; + return this.apiClient.request(\\"GET\\", url, headers, undefined, queryParameters, option); + } + public async getReferenceItems(option?: RequestOption): Promise { + const url = this.baseUrl + \`/get/reference/items\`; + const headers = { + Accept: \\"application/json\\" + }; + return this.apiClient.request(\\"GET\\", url, headers, undefined, undefined, option); + } +} +" +`; + +exports[`Split Code types 1`] = ` +"// +// Generated by @himenon/openapi-typescript-code-generator +// +// OpenApi : 3.1.0 +// +// License : MIT +// + + +export namespace Schemas { + /** String Literal */ + export type StringType = string; + export type StringHasEnumType = \\"a\\" | \\"A\\" | \\"b\\" | \\"B\\" | \\"c\\" | \\"C\\"; + export type StringDateType = string; + export type StringDateTimeType = string; + export type StringPasswordType = string; + export type StringByteType = string; + export type StringBinaryType = string; + export type StringWithPatternType = string; + /** Number Literal */ + export type NumberType = number; + export type NumberHasEnumType = 1 | 2 | 3 | 100 | 123 | 0.1 | -0.1 | 0; + export type NumberInt32Type = number; + export type NumberInt64Type = number; + export type NumberFloat = number; + export type NumberDouble = number; + /** Boolean Literal */ + export type BooleanType = boolean; + export type ArrayStringType = string[]; + export type ArrayNumberType = number[]; + export type ArrayBooleanType = boolean[]; + export interface ObjectEmptyPropertiesType { + } + export interface ObjectHasPropertiesType { + stringType?: string; + numberType?: number; + booleanType?: boolean; + arrayType?: string; + objectType?: { + requiredStringType: string; + }; + } + export type OneOfType = string | number | {}; + export type AllOfType = { + A?: string; + } & { + B?: string; + }; + export type LocalRefStringType = Schemas.StringType; + export type LocalRefNumberType = Schemas.NumberType; + export type LocalRefBooleanType = Schemas.BooleanType; + export type LocalRefArrayStringType = Schemas.BooleanType; + export type LocalRefObjectHasPropertiesType = Schemas.ObjectHasPropertiesType; + export interface LocalRefObjectProperties { + stringType: Schemas.StringType; + numberType: Schemas.NumberType; + booleanType: Schemas.BooleanType; + arrayType: Schemas.BooleanType; + objectType: Schemas.ObjectHasPropertiesType; + } + export type LocalRefOneOfType = Schemas.StringType | Schemas.NumberType | Schemas.ObjectHasPropertiesType | Schemas.LocalRefObjectProperties; + export type LocalRefAllOfType = Schemas.StringType & Schemas.NumberType & Schemas.ObjectHasPropertiesType & Schemas.LocalRefObjectProperties; + export type LocalReferenceBeforeResolvedSchema1 = Schemas.UnresolvedTarget1; + export type UnresolvedTarget1 = boolean; + export type LocalReferenceBeforeResolvedSchema2 = Schemas.UnresolvedTarget2; + export type UnresolvedTarget2 = Schemas.UnresolvedTarget3; + export type UnresolvedTarget3 = number; + export interface LocalReferenceBeforeResolvedSchema3 { + unresolvedTarget4?: Schemas.UnresolvedTarget4; + } + export interface UnresolvedTarget4 { + unresolvedTarget5?: Schemas.UnresolvedTarget5; + } + export type UnresolvedTarget5 = string; + export type RemoteString = string; + export type RemoteRefString = Schemas.RemoteString; + export namespace Level1 { + /** Level 1 */ + export type RemoteBoolean = boolean; + export namespace Level2 { + /** Level 2 */ + export type RemoteNumber = number; + export namespace Level3 { + /** Level 3 */ + export type RemoteArray = string[]; + export namespace Level4 { + /** Level 4 */ + export interface RemoteObject { + A?: string; + B?: number; + } + } + } + } + } + /** Level 1 */ + export type RemoteRefBoolean = Schemas.Level1.RemoteBoolean; + /** Level 2 */ + export type RemoteRefNumber = Schemas.Level1.Level2.RemoteNumber; + /** Level 3 */ + export type RemoteRefArray = Schemas.Level1.Level2.Level3.RemoteArray; + /** Level 4 */ + export type RemoteRefObject = Schemas.Level1.Level2.Level3.Level4.RemoteObject; + export namespace DirectRef { + export type ForHeader = string; + export interface ForResponse { + forResponse?: string; + } + export type ForParameters = string; + export interface ForRequestBody { + a?: string; + } + } + export namespace FullRemoteReference { + export type ForParameters = string; + } + export interface Child { + id: string; + /** child name */ + name: string; + } + export interface Item { + name: string; + children: Child[]; + } +} +export namespace Headers { + export type StringHeader = string; + export type A = number; + export namespace Level1 { + export type B = string; + } + export type ReferenceOfHeaderToSchema = Schemas.DirectRef.ForHeader; +} +export namespace Responses { + /** + * Status Code 100 + * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/100 + */ + export namespace Continue { } + /** + * Status Code 101 + * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/101 + */ + export namespace SwitchingProtocol { } + /** Type Reference - string */ + export namespace LocalReferenceStringDateTimeType { + export interface Content { + \\"application/json\\": Schemas.StringDateTimeType; + } + } + /** Local Reference - object */ + export namespace LocalReferenceObjectType { + export interface Content { + \\"application/json\\": Schemas.ObjectHasPropertiesType; + } + } + /** Response -> Schema */ + export namespace ReferenceOfResponseToSchema { + export interface Content { + \\"application/json\\": Schemas.DirectRef.ForResponse; + } + } + /** response A definition */ + export namespace ResponseA { + export interface Header { + HeaderA: Headers.A; + HeaderB: string; + } + export interface Content { + \\"application/json\\": { + /** responseA description */ + name?: \\"responseA\\"; + }; + } + } + export namespace Level1 { + /** response B definition */ + export namespace ResponseB { + export interface Content { + \\"application/json\\": { + name?: \\"responseB\\"; + }; + } + } + export namespace Level2 { + /** response C definition */ + export namespace ResponseC { + export interface Content { + \\"application/json\\": { + name?: \\"responseC\\"; + }; + } + } + } + } + export namespace ForPathItems { + /** response A definition */ + export namespace FullRemoteReference { + export interface Header { + HeaderA: Headers.A; + HeaderB: string; + } + export interface Content { + \\"application/json\\": { + /** responseA description */ + name?: \\"responseA\\"; + }; + } + } + } +} +export namespace Parameters { + /** parameters.StringQueryParams */ + export type StringQueryParams = string; + /** parameters.NumberQueryParams */ + export type NumberQueryParams = number; + /** parameters.StringQueryParams */ + export type StringHeaderParams = string; + export type A = number; + export type RemoteReferenceA = Parameters.A; + export namespace level1 { + export type B = string; + } + export type RemoteReferenceB = Parameters.level1.B; + /** parameters -> schemas */ + export type ReferenceOfParameterToSchema = Schemas.DirectRef.ForParameters; + /** deepObject */ + export type DeepObjectParameter = { + [key: string]: { + gt?: string; + gte?: string; + lt?: string; + lte?: string; + any?: string | number | boolean; + }; + }; +} +export namespace RequestBodies { + /** Request body string type */ + export namespace StringType { + export interface Content { + \\"application/json\\": string; + } + } + /** Request body Local reference string type */ + export namespace LocalReferenceStringType { + export interface Content { + \\"application/json\\": Schemas.StringHasEnumType; + } + } + /** requestBodies -> schemas */ + export namespace ReferenceOfRequestBodyToSchema { + export interface Content { + \\"application/json\\": Schemas.DirectRef.ForRequestBody; + } + } + /** Remote Request body A */ + export namespace RequestBodyA { + export interface Content { + \\"application/json\\": { + body?: string; + }; + } + } + export namespace Level1 { + /** Remote Request body B */ + export namespace RequestBodyB { + export interface Content { + \\"application/json\\": { + body?: string; + }; + } + } + export namespace Level2 { + /** Remote Request body C */ + export namespace RequestBodyC { + export interface Content { + \\"application/json\\": { + body?: string; + }; + } + } + } + } +} +" +`; diff --git a/test/__tests__/__snapshots__/typedef-only-test.ts.snap b/test/__tests__/__snapshots__/typedef-only-test.ts.snap index 95640898..8d94402d 100644 --- a/test/__tests__/__snapshots__/typedef-only-test.ts.snap +++ b/test/__tests__/__snapshots__/typedef-only-test.ts.snap @@ -287,37 +287,6 @@ export namespace RequestBodies { } } } -export interface Parameter$getIncludeLocalReference { - /** parameters.StringQueryParams */ - StringQuery: string; -} -export interface Response$getIncludeLocalReference$Status$200 { - \\"application/json\\": { - meta: string; - }; -} -export interface Parameter$getIncludeRemoteReference { - /** remote reference parameter */ - IncludeRemoteReference: number; -} -export interface RequestBody$getIncludeRemoteReference { - \\"application/json\\": string; -} -export interface Parameter$getFullRemoteReference { - /** Full Remote Reference */ - FullRemoteReferenceQuery: Schemas.FullRemoteReference.ForParameters; -} -export interface Response$getFullRemoteReference$Status$200 { - \\"application/json\\": { - /** responseA description */ - name?: \\"responseA\\"; - }; -} -export interface Response$getReferenceItems$Status$200 { - \\"application/json\\": { - books?: Schemas.Item[]; - }; -} " `; diff --git a/test/__tests__/spit-code-test.ts b/test/__tests__/spit-code-test.ts new file mode 100644 index 00000000..d74f88f0 --- /dev/null +++ b/test/__tests__/spit-code-test.ts @@ -0,0 +1,18 @@ +import * as fs from "fs"; +import * as path from "path"; + +import * as Utils from "../utils"; + +describe("Split Code", () => { + test("types", () => { + const generateCode = fs.readFileSync(path.join(__dirname, "../code/split/types.ts"), { encoding: "utf-8" }); + const text = Utils.replaceVersionInfo(generateCode); + expect(text).toMatchSnapshot(); + }); + + test("apiClient", () => { + const generateCode = fs.readFileSync(path.join(__dirname, "../code/split/apiClient.ts"), { encoding: "utf-8" }); + const text = Utils.replaceVersionInfo(generateCode); + expect(text).toMatchSnapshot(); + }); +});