Skip to content

Commit 4ea37e1

Browse files
authored
fix: engines fields (#74)
1 parent 5cd7b7e commit 4ea37e1

File tree

9 files changed

+106
-96
lines changed

9 files changed

+106
-96
lines changed

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = {
33
browser: true,
44
es2021: true,
55
},
6-
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:import/typescript", "prettier/@typescript-eslint"],
6+
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:import/typescript"],
77
parser: "@typescript-eslint/parser",
88
parserOptions: {
99
ecmaVersion: 12,

README.md

+23-20
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Since the parameters extracted from OpenAPI can be used freely, it can be used f
1313
## Installation
1414

1515
```bash
16+
npm i -D @himenon/openapi-typescript-code-generator
17+
# or
18+
pnpm i -D @himenon/openapi-typescript-code-generator
19+
# or
1620
yarn add -D @himenon/openapi-typescript-code-generator
1721
```
1822

@@ -118,13 +122,11 @@ import type * as Types from "@himenon/openapi-typescript-code-generator/types";
118122
/** Write the definition of the Code Template here. */
119123
const customGenerator: Types.CodeGenerator.CustomGenerator<{}> = {
120124
/** .... */
121-
}
125+
};
122126

123127
const codeGenerator = new CodeGenerator("your/openapi/spec.yml");
124128

125-
const code = codeGenerator.generateCode([
126-
customGenerator,
127-
]);
129+
const code = codeGenerator.generateCode([customGenerator]);
128130

129131
fs.writeFileSync("output/file/name", code, { encoding: "utf-8" });
130132
```
@@ -150,7 +152,7 @@ const generator: Types.CodeGenerator.GenerateFunction<Option> = (payload: Types.
150152
const customGenerator: Types.CodeGenerator.CustomGenerator<Option> = {
151153
generator: generator,
152154
option: {},
153-
}
155+
};
154156
```
155157

156158
### Define using the information extracted from OpenAPI Schema
@@ -161,19 +163,18 @@ See Type definitions for available parameters.
161163
```ts
162164
import * as Types from "@himenon/openapi-typescript-code-generator/types";
163165

164-
interface Option {
165-
}
166+
interface Option {}
166167

167168
const generator: Types.CodeGenerator.GenerateFunction<Option> = (payload: Types.CodeGenerator.Params[], option): string[] => {
168-
return payload.map((params) => {
169+
return payload.map(params => {
169170
return `function ${params.operationId}() { console.log("${params.comment}") }`;
170-
})
171+
});
171172
};
172173

173174
const customGenerator: Types.CodeGenerator.CustomGenerator<Option> = {
174175
generator: generator,
175176
option: {},
176-
}
177+
};
177178
```
178179

179180
### Define any Data Types Format
@@ -236,9 +237,9 @@ The typedef generated by this will look like this
236237

237238
```ts
238239
export namespace Schemas {
239-
export type Binary = Blob;
240-
export type IntOrString = number | string;
241-
export type AandB = A & B;
240+
export type Binary = Blob;
241+
export type IntOrString = number | string;
242+
export type AandB = A & B;
242243
}
243244
```
244245

@@ -251,25 +252,27 @@ You can directly use the API of TypeScript AST or use the wrapper API of TypeScr
251252
import * as Types from "@himenon/openapi-typescript-code-generator/types";
252253
import { TsGenerator } from "@himenon/openapi-typescript-code-generator/api";
253254

254-
interface Option {
255-
}
255+
interface Option {}
256256

257257
const factory = TsGenerator.Factory.create();
258258

259-
const generator: Types.CodeGenerator.GenerateFunction<Option> = (payload: Types.CodeGenerator.Params[], option): Types.CodeGenerator.IntermediateCode[] => {
260-
return payload.map((params) => {
259+
const generator: Types.CodeGenerator.GenerateFunction<Option> = (
260+
payload: Types.CodeGenerator.Params[],
261+
option,
262+
): Types.CodeGenerator.IntermediateCode[] => {
263+
return payload.map(params => {
261264
return factory.InterfaceDeclaration.create({
262265
export: true,
263266
name: params.functionName,
264267
members: [],
265-
})
266-
})
268+
});
269+
});
267270
};
268271

269272
const customGenerator: Types.CodeGenerator.CustomGenerator<Option> = {
270273
generator: generator,
271274
option: {},
272-
}
275+
};
273276
```
274277

275278
## API

docs/ja/README-ja.md

+19-20
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,11 @@ import type * as Types from "@himenon/openapi-typescript-code-generator/types";
116116
/** ここにCode Templateの定義を記述してください */
117117
const customGenerator: Types.CodeGenerator.CustomGenerator<{}> = {
118118
/** .... */
119-
}
119+
};
120120

121121
const codeGenerator = new CodeGenerator("your/openapi/spec.yml");
122122

123-
const code = codeGenerator.generateCode([
124-
customGenerator,
125-
]);
123+
const code = codeGenerator.generateCode([customGenerator]);
126124

127125
fs.writeFileSync("output/file/name", code, { encoding: "utf-8" });
128126
```
@@ -148,7 +146,7 @@ const generator: Types.CodeGenerator.GenerateFunction<Option> = (payload: Types.
148146
const customGenerator: Types.CodeGenerator.CustomGenerator<Option> = {
149147
generator: generator,
150148
option: {},
151-
}
149+
};
152150
```
153151

154152
### OpenAPI Schema から抽出した情報を利用した定義をする
@@ -159,19 +157,18 @@ const customGenerator: Types.CodeGenerator.CustomGenerator<Option> = {
159157
```ts
160158
import * as Types from "@himenon/openapi-typescript-code-generator/types";
161159

162-
interface Option {
163-
}
160+
interface Option {}
164161

165162
const generator: Types.CodeGenerator.GenerateFunction<Option> = (payload: Types.CodeGenerator.Params[], option): string[] => {
166-
return payload.map((params) => {
163+
return payload.map(params => {
167164
return `function ${params.operationId}() { console.log("${params.comment}") }`;
168-
})
165+
});
169166
};
170167

171168
const customGenerator: Types.CodeGenerator.CustomGenerator<Option> = {
172169
generator: generator,
173170
option: {},
174-
}
171+
};
175172
```
176173

177174
### 任意の Data Types Format を定義する
@@ -234,9 +231,9 @@ const codeGenerator = new CodeGenerator(inputFilename, option);
234231

235232
```ts
236233
export namespace Schemas {
237-
export type Binary = Blob;
238-
export type IntOrString = number | string;
239-
export type AandB = A & B;
234+
export type Binary = Blob;
235+
export type IntOrString = number | string;
236+
export type AandB = A & B;
240237
}
241238
```
242239

@@ -249,25 +246,27 @@ TypeScript AST の API を利用したコードの拡張が可能です。
249246
import * as Types from "@himenon/openapi-typescript-code-generator/types";
250247
import { TsGenerator } from "@himenon/openapi-typescript-code-generator/api";
251248

252-
interface Option {
253-
}
249+
interface Option {}
254250

255251
const factory = TsGenerator.Factory.create();
256252

257-
const generator: Types.CodeGenerator.GenerateFunction<Option> = (payload: Types.CodeGenerator.Params[], option): Types.CodeGenerator.IntermediateCode[] => {
258-
return payload.map((params) => {
253+
const generator: Types.CodeGenerator.GenerateFunction<Option> = (
254+
payload: Types.CodeGenerator.Params[],
255+
option,
256+
): Types.CodeGenerator.IntermediateCode[] => {
257+
return payload.map(params => {
259258
return factory.InterfaceDeclaration.create({
260259
export: true,
261260
name: params.functionName,
262261
members: [],
263-
})
264-
})
262+
});
263+
});
265264
};
266265

267266
const customGenerator: Types.CodeGenerator.CustomGenerator<Option> = {
268267
generator: generator,
269268
option: {},
270-
}
269+
};
271270
```
272271

273272
## API

package.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,7 @@
109109
"typescript": "4.2.3"
110110
},
111111
"engines": {
112-
"node": ">=16",
113-
"npm": "forbidden, use pnpm",
114-
"pnpm": ">=6",
115-
"yarn": "forbidden, use pnpm"
112+
"pnpm": ">=6"
116113
},
117114
"publishConfig": {
118115
"access": "public"

0 commit comments

Comments
 (0)