|
| 1 | +import * as fs from "fs"; |
| 2 | +import * as path from "path"; |
| 3 | + |
| 4 | +import { CodeGenerator } from "../../src"; |
| 5 | +import * as Templates from "../../src/templates"; |
| 6 | +import type * as Types from "../../src/types"; |
| 7 | + |
| 8 | +describe("raw-json-generate", () => { |
| 9 | + test("the raw json input result and the json file path result are same", () => { |
| 10 | + const generateCode = JSON.parse(fs.readFileSync(path.join(__dirname, "../kubernetes/openapi-v1.18.5.json"), { encoding: "utf-8" })); |
| 11 | + |
| 12 | + const codeGenerator1 = new CodeGenerator(generateCode); |
| 13 | + const codeGenerator2 = new CodeGenerator(path.join(__dirname, "../kubernetes/openapi-v1.18.5.json")); |
| 14 | + |
| 15 | + const apiClientGeneratorTemplate: Types.CodeGenerator.CustomGenerator<Templates.ApiClient.Option> = { |
| 16 | + generator: Templates.ApiClient.generator, |
| 17 | + option: {}, |
| 18 | + }; |
| 19 | + |
| 20 | + const code1 = codeGenerator1.generateTypeDefinition([ |
| 21 | + codeGenerator1.getAdditionalTypeDefinitionCustomCodeGenerator(), |
| 22 | + apiClientGeneratorTemplate, |
| 23 | + ]); |
| 24 | + |
| 25 | + const code2 = codeGenerator2.generateTypeDefinition([ |
| 26 | + codeGenerator1.getAdditionalTypeDefinitionCustomCodeGenerator(), |
| 27 | + apiClientGeneratorTemplate, |
| 28 | + ]); |
| 29 | + |
| 30 | + expect(code1).toBe(code2); |
| 31 | + }); |
| 32 | + test("yaml file path loadable", () => { |
| 33 | + const codeGenerator = new CodeGenerator(path.join(__dirname, "../api.test.domain/index.yml")); |
| 34 | + |
| 35 | + const apiClientGeneratorTemplate: Types.CodeGenerator.CustomGenerator<Templates.ApiClient.Option> = { |
| 36 | + generator: Templates.ApiClient.generator, |
| 37 | + option: {}, |
| 38 | + }; |
| 39 | + |
| 40 | + const code = codeGenerator.generateTypeDefinition([ |
| 41 | + codeGenerator.getAdditionalTypeDefinitionCustomCodeGenerator(), |
| 42 | + apiClientGeneratorTemplate, |
| 43 | + ]); |
| 44 | + |
| 45 | + expect(code).not.toBeFalsy(); |
| 46 | + }); |
| 47 | +}); |
0 commit comments