Skip to content

fix: after release some bugs #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .dependency-cruiser.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ module.exports = {
},
to: {
dependencyTypes: ["npm-dev"],
pathNot: "typescript",
},
},
{
name: "no-duplicate-dep-types",
severity: "ignore",
},
{
name: "optional-deps-used",
severity: "info",
Expand All @@ -91,6 +96,7 @@ module.exports = {
from: {},
to: {
dependencyTypes: ["npm-peer"],
pathNot: "typescript",
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The hierarchical structure of the directory is converted to the hierarchical str
yarn add -D @himenon/openapi-typescript-code-generator
```

### デモ
### DEMO

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

Expand Down
2 changes: 0 additions & 2 deletions example/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import * as CodeGenerator from "../lib"; // = @himenon/openapi-typescript-code-g

const main = () => {
const params: CodeGenerator.Params = {
version: "v3",
entryPoint: "./spec/openapi.yml",
enableValidate: true,
};
fs.mkdirSync("test/code", { recursive: true });
const code = CodeGenerator.generateTypeScriptCode(params);
fs.writeFileSync("client.ts", code, { encoding: "utf-8" });
};
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@
"@types/json-schema": "7.0.6",
"ajv": "7.0.3",
"dot-prop": "6.0.1",
"js-yaml": "4.0.0",
"typescript": "4.1.3"
"js-yaml": "4.0.0"
},
"devDependencies": {
"@commitlint/cli": "11.0.0",
Expand Down Expand Up @@ -112,8 +111,12 @@
"sort-package-json": "1.48.1",
"ts-jest": "26.4.4",
"ts-node": "9.1.1",
"typescript": "4.1.3",
"yarn-deduplicate": "3.1.0"
},
"peerDependencies": {
"typescript": "4.1.3"
},
"publishConfig": {
"access": "public"
},
Expand Down
1 change: 0 additions & 1 deletion scripts/testCodeGen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as CodeGenerator from "../lib";

const main = () => {
const params: CodeGenerator.Params = {
version: "v3",
entryPoint: "test/api.test.domain/index.yml",
log: {
validator: {
Expand Down
19 changes: 6 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import * as Validator from "./Validator";
export { Converter };

export interface Params {
version: "v3";
entryPoint: string;
option?: Partial<Converter.v3.Option>;
/** default: true */
Expand All @@ -20,23 +19,17 @@ export interface Params {
};
}

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

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

switch (version) {
case "v3": {
const convertOption: Converter.v3.Option = option
? { makeApiClient: option.makeApiClient || DefaultCodeTemplate.makeClientApiClient }
: { makeApiClient: DefaultCodeTemplate.makeClientApiClient };
const { createFunction, generateLeadingComment } = Converter.v3.create(entryPoint, schema, resolvedReferenceDocument, convertOption);
return [generateLeadingComment(), TypeScriptCodeGenerator.generate(createFunction)].join(EOL + EOL + EOL);
}
default:
return "UnSupport OpenAPI Version";
}
const convertOption: Converter.v3.Option = option
? { makeApiClient: option.makeApiClient || DefaultCodeTemplate.makeClientApiClient }
: { makeApiClient: DefaultCodeTemplate.makeClientApiClient };
const { createFunction, generateLeadingComment } = Converter.v3.create(entryPoint, schema, resolvedReferenceDocument, convertOption);
return [generateLeadingComment(), TypeScriptCodeGenerator.generate(createFunction)].join(EOL + EOL + EOL);
};