Skip to content

Commit bb342ad

Browse files
committed
test: add basic snapshot test for remote ref access
1 parent aeb1fe6 commit bb342ad

File tree

3 files changed

+153
-0
lines changed

3 files changed

+153
-0
lines changed

scripts/testCodeGen.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ const main = () => {
2424
Writer.generateTypedefWithTemplateCode("test/ref.access/index.yml", "test/code/typedef-with-template/ref-access.ts", false, {
2525
sync: false,
2626
});
27+
Writer.generateTypedefWithTemplateCode("test/remote.ref.access/v1.yml", "test/code/typedef-with-template/remote-ref-access.ts", false, {
28+
sync: false,
29+
});
2730
Writer.generateTypedefWithTemplateCode("test/kubernetes/openapi-v1.18.5.json", "test/code/kubernetes/client-v1.18.5.ts", false, {
2831
sync: false,
2932
});

test/__tests__/__snapshots__/typedef-with-template-test.ts.snap

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,3 +1216,148 @@ export class Client<RequestOption> {
12161216
}
12171217
"
12181218
`;
1219+
1220+
exports[`Typedef with template remote-ref-access 1`] = `
1221+
"//
1222+
// Generated by @himenon/openapi-typescript-code-generator
1223+
//
1224+
// OpenApi : 3.1.0
1225+
//
1226+
// License : MIT
1227+
//
1228+
1229+
1230+
export namespace Schemas {
1231+
export interface Book {
1232+
author?: {
1233+
name?: string;
1234+
age?: string;
1235+
};
1236+
publisher?: {
1237+
name?: any;
1238+
address?: string;
1239+
};
1240+
metadata: {
1241+
description: string;
1242+
};
1243+
}
1244+
export namespace Book {
1245+
export namespace properties {
1246+
export interface author {
1247+
name?: string;
1248+
age?: string;
1249+
}
1250+
export interface publisher {
1251+
name?: any;
1252+
address?: string;
1253+
}
1254+
export namespace metadata {
1255+
export namespace properties {
1256+
export type description = string;
1257+
}
1258+
}
1259+
}
1260+
}
1261+
export type Author = Schemas.Book.properties.author;
1262+
export type Publisher = Schemas.Book.properties.publisher;
1263+
}
1264+
export interface Parameter$getBook {
1265+
/** Book ID */
1266+
id: string;
1267+
}
1268+
export interface Response$getBook$Status$200 {
1269+
\\"application/json\\": Schemas.Book;
1270+
}
1271+
export interface Parameter$getDescription {
1272+
/** Book ID */
1273+
id: string;
1274+
}
1275+
export interface Response$getDescription$Status$200 {
1276+
\\"application/json\\": Schemas.Book.properties.metadata.properties.description;
1277+
}
1278+
export interface Parameter$getAuthor {
1279+
/** Author Id */
1280+
id: string;
1281+
}
1282+
export interface Response$getAuthor$Status$200 {
1283+
\\"application/json\\": Schemas.Author;
1284+
}
1285+
export interface Parameter$getPublisher {
1286+
/** Publisher ID */
1287+
id: string;
1288+
}
1289+
export interface Response$getPublisher$Status$200 {
1290+
\\"application/json\\": Schemas.Publisher;
1291+
}
1292+
export type ResponseContentType$getBook = keyof Response$getBook$Status$200;
1293+
export interface Params$getBook {
1294+
parameter: Parameter$getBook;
1295+
}
1296+
export type ResponseContentType$getDescription = keyof Response$getDescription$Status$200;
1297+
export interface Params$getDescription {
1298+
parameter: Parameter$getDescription;
1299+
}
1300+
export type ResponseContentType$getAuthor = keyof Response$getAuthor$Status$200;
1301+
export interface Params$getAuthor {
1302+
parameter: Parameter$getAuthor;
1303+
}
1304+
export type ResponseContentType$getPublisher = keyof Response$getPublisher$Status$200;
1305+
export interface Params$getPublisher {
1306+
parameter: Parameter$getPublisher;
1307+
}
1308+
export type HttpMethod = \\"GET\\" | \\"PUT\\" | \\"POST\\" | \\"DELETE\\" | \\"OPTIONS\\" | \\"HEAD\\" | \\"PATCH\\" | \\"TRACE\\";
1309+
export interface ObjectLike {
1310+
[key: string]: any;
1311+
}
1312+
export interface QueryParameter {
1313+
value: any;
1314+
style?: \\"form\\" | \\"spaceDelimited\\" | \\"pipeDelimited\\" | \\"deepObject\\";
1315+
explode: boolean;
1316+
}
1317+
export interface QueryParameters {
1318+
[key: string]: QueryParameter;
1319+
}
1320+
export type SuccessResponses = Response$getBook$Status$200 | Response$getDescription$Status$200 | Response$getAuthor$Status$200 | Response$getPublisher$Status$200;
1321+
export namespace ErrorResponse {
1322+
export type getBook = void;
1323+
export type getDescription = void;
1324+
export type getAuthor = void;
1325+
export type getPublisher = void;
1326+
}
1327+
export interface ApiClient<RequestOption> {
1328+
request: <T = SuccessResponses>(httpMethod: HttpMethod, url: string, headers: ObjectLike | any, requestBody: ObjectLike | any, queryParameters: QueryParameters | undefined, options?: RequestOption) => Promise<T>;
1329+
}
1330+
export class Client<RequestOption> {
1331+
private baseUrl: string;
1332+
constructor(private apiClient: ApiClient<RequestOption>, baseUrl: string) { this.baseUrl = baseUrl.replace(/\\\\/$/, \\"\\"); }
1333+
public async getBook(params: Params$getBook, option?: RequestOption): Promise<Response$getBook$Status$200[\\"application/json\\"]> {
1334+
const url = this.baseUrl + \`/get/book/\${params.parameter.id}\`;
1335+
const headers = {
1336+
Accept: \\"application/json\\"
1337+
};
1338+
return this.apiClient.request(\\"GET\\", url, headers, undefined, undefined, option);
1339+
}
1340+
public async getDescription(params: Params$getDescription, option?: RequestOption): Promise<Response$getDescription$Status$200[\\"application/json\\"]> {
1341+
const url = this.baseUrl + \`/get/book/\${params.parameter.id}/description\`;
1342+
const headers = {
1343+
Accept: \\"application/json\\"
1344+
};
1345+
return this.apiClient.request(\\"GET\\", url, headers, undefined, undefined, option);
1346+
}
1347+
public async getAuthor(params: Params$getAuthor, option?: RequestOption): Promise<Response$getAuthor$Status$200[\\"application/json\\"]> {
1348+
const url = this.baseUrl + \`/get/author/\${params.parameter.id}\`;
1349+
const headers = {
1350+
Accept: \\"application/json\\"
1351+
};
1352+
return this.apiClient.request(\\"GET\\", url, headers, undefined, undefined, option);
1353+
}
1354+
public async getPublisher(params: Params$getPublisher, option?: RequestOption): Promise<Response$getPublisher$Status$200[\\"application/json\\"]> {
1355+
const url = this.baseUrl + \`/get/publisher/\${params.parameter.id}\`;
1356+
const headers = {
1357+
Accept: \\"application/json\\"
1358+
};
1359+
return this.apiClient.request(\\"GET\\", url, headers, undefined, undefined, option);
1360+
}
1361+
}
1362+
"
1363+
`;

test/__tests__/typedef-with-template-test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@ describe("Typedef with template", () => {
2929
const text = Utils.replaceVersionInfo(generateCode);
3030
expect(text).toMatchSnapshot();
3131
});
32+
test("remote-ref-access", () => {
33+
const generateCode = fs.readFileSync(path.join(__dirname, "../code/typedef-with-template/remote-ref-access.ts"), { encoding: "utf-8" });
34+
const text = Utils.replaceVersionInfo(generateCode);
35+
expect(text).toMatchSnapshot();
36+
});
3237
});

0 commit comments

Comments
 (0)