Skip to content

Commit 1a756bd

Browse files
authored
fix: after release some bugs (#4)
1 parent 0e7a480 commit 1a756bd

File tree

6 files changed

+18
-19
lines changed

6 files changed

+18
-19
lines changed

.dependency-cruiser.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,13 @@ module.exports = {
6565
},
6666
to: {
6767
dependencyTypes: ["npm-dev"],
68+
pathNot: "typescript",
6869
},
6970
},
71+
{
72+
name: "no-duplicate-dep-types",
73+
severity: "ignore",
74+
},
7075
{
7176
name: "optional-deps-used",
7277
severity: "info",
@@ -91,6 +96,7 @@ module.exports = {
9196
from: {},
9297
to: {
9398
dependencyTypes: ["npm-peer"],
99+
pathNot: "typescript",
94100
},
95101
},
96102
],

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The hierarchical structure of the directory is converted to the hierarchical str
1515
yarn add -D @himenon/openapi-typescript-code-generator
1616
```
1717

18-
### デモ
18+
### DEMO
1919

2020
- [DEMO](./example/README.md)
2121

example/codegen.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import * as CodeGenerator from "../lib"; // = @himenon/openapi-typescript-code-g
44

55
const main = () => {
66
const params: CodeGenerator.Params = {
7-
version: "v3",
87
entryPoint: "./spec/openapi.yml",
98
enableValidate: true,
109
};
11-
fs.mkdirSync("test/code", { recursive: true });
1210
const code = CodeGenerator.generateTypeScriptCode(params);
1311
fs.writeFileSync("client.ts", code, { encoding: "utf-8" });
1412
};

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@
7575
"@types/json-schema": "7.0.6",
7676
"ajv": "7.0.3",
7777
"dot-prop": "6.0.1",
78-
"js-yaml": "4.0.0",
79-
"typescript": "4.1.3"
78+
"js-yaml": "4.0.0"
8079
},
8180
"devDependencies": {
8281
"@commitlint/cli": "11.0.0",
@@ -112,8 +111,12 @@
112111
"sort-package-json": "1.48.1",
113112
"ts-jest": "26.4.4",
114113
"ts-node": "9.1.1",
114+
"typescript": "4.1.3",
115115
"yarn-deduplicate": "3.1.0"
116116
},
117+
"peerDependencies": {
118+
"typescript": "4.1.3"
119+
},
117120
"publishConfig": {
118121
"access": "public"
119122
},

scripts/testCodeGen.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as CodeGenerator from "../lib";
44

55
const main = () => {
66
const params: CodeGenerator.Params = {
7-
version: "v3",
87
entryPoint: "test/api.test.domain/index.yml",
98
log: {
109
validator: {

src/index.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import * as Validator from "./Validator";
1010
export { Converter };
1111

1212
export interface Params {
13-
version: "v3";
1413
entryPoint: string;
1514
option?: Partial<Converter.v3.Option>;
1615
/** default: true */
@@ -20,23 +19,17 @@ export interface Params {
2019
};
2120
}
2221

23-
export const generateTypeScriptCode = ({ version, entryPoint, option, enableValidate = true, log }: Params): string => {
22+
export const generateTypeScriptCode = ({ entryPoint, option, enableValidate = true, log }: Params): string => {
2423
const schema = fileSystem.loadJsonOrYaml(entryPoint);
2524
const resolvedReferenceDocument = ResolveReference.resolve(entryPoint, entryPoint, JSON.parse(JSON.stringify(schema)));
2625

2726
if (enableValidate) {
2827
Validator.v3.validate(resolvedReferenceDocument, log && log.validator);
2928
}
3029

31-
switch (version) {
32-
case "v3": {
33-
const convertOption: Converter.v3.Option = option
34-
? { makeApiClient: option.makeApiClient || DefaultCodeTemplate.makeClientApiClient }
35-
: { makeApiClient: DefaultCodeTemplate.makeClientApiClient };
36-
const { createFunction, generateLeadingComment } = Converter.v3.create(entryPoint, schema, resolvedReferenceDocument, convertOption);
37-
return [generateLeadingComment(), TypeScriptCodeGenerator.generate(createFunction)].join(EOL + EOL + EOL);
38-
}
39-
default:
40-
return "UnSupport OpenAPI Version";
41-
}
30+
const convertOption: Converter.v3.Option = option
31+
? { makeApiClient: option.makeApiClient || DefaultCodeTemplate.makeClientApiClient }
32+
: { makeApiClient: DefaultCodeTemplate.makeClientApiClient };
33+
const { createFunction, generateLeadingComment } = Converter.v3.create(entryPoint, schema, resolvedReferenceDocument, convertOption);
34+
return [generateLeadingComment(), TypeScriptCodeGenerator.generate(createFunction)].join(EOL + EOL + EOL);
4235
};

0 commit comments

Comments
 (0)