Skip to content
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
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
pnpm build
pnpm type-check
pnpm test:code:gen
pnpm lint
pnpm test
env:
CI: true
18 changes: 16 additions & 2 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/2.0.0/schema.json",
"$schema": "https://biomejs.dev/schemas/2.4.12/schema.json",
"assist": { "actions": { "source": { "organizeImports": "on" } } },
"formatter": {
"enabled": true,
Expand All @@ -21,12 +21,26 @@
"useNumberNamespace": "error",
"noInferrableTypes": "error",
"noUselessElse": "error"
},
"correctness": {
"noUnusedImports": "error"
},
"suspicious": {
"noExplicitAny": "off",
"useIterableCallbackReturn": "off"
},
"performance": {
"noAccumulatingSpread": "off"
},
"complexity": {
"noStaticOnlyClass": "off",
"noBannedTypes": "off"
}
}
},
"files": {
"ignoreUnknown": true,
"includes": ["**", "!**/dist"],
"includes": ["**", "!**/dist", "!coverage", "!examples", "!test/code"],
"maxSize": 10485760
},
"javascript": {
Expand Down
5 changes: 2 additions & 3 deletions examples/apis/codegen.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as fs from "fs";

import { CodeGenerator } from "@himenon/openapi-typescript-code-generator";
import * as Templates from "@himenon/openapi-typescript-code-generator/dist/templates";
import * as Types from "@himenon/openapi-typescript-code-generator/dist/types";
import type * as Types from "@himenon/openapi-typescript-code-generator/dist/types";
import * as fs from "fs";

const main = () => {
const codeGenerator = new CodeGenerator("./spec/openapi.yml");
Expand Down
2 changes: 1 addition & 1 deletion examples/apis/sample-axios.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as axios from "axios";

import { ApiClient, RequestArgs, createClient } from "./client";
import { type ApiClient, createClient, type RequestArgs } from "./client";
import { generateQueryString } from "./utils";

export interface RequestOption {
Expand Down
2 changes: 1 addition & 1 deletion examples/apis/sample-debug.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ApiClient, RequestArgs, createClient } from "./client";
import { type ApiClient, createClient, type RequestArgs } from "./client";
import { generateQueryString } from "./utils";

export interface RequestOption {
Expand Down
2 changes: 1 addition & 1 deletion examples/apis/sample-fetch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fetch from "node-fetch";

import { ApiClient, RequestArgs, createClient } from "./client";
import { type ApiClient, createClient, type RequestArgs } from "./client";
import { generateQueryString } from "./utils";

export interface RequestOption {
Expand Down
2 changes: 1 addition & 1 deletion examples/apis/sample-superagent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import superagent from "superagent";

import { ApiClient, RequestArgs, createClient } from "./client";
import { type ApiClient, createClient, type RequestArgs } from "./client";
import { generateQueryString } from "./utils";

export interface RequestOption {
Expand Down
2 changes: 1 addition & 1 deletion examples/apis/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Formatter from "@himenon/openapi-parameter-formatter";

import { QueryParameters } from "./client";
import type { QueryParameters } from "./client";

export const generateQueryString = (queryParameters: QueryParameters | undefined): string | undefined => {
if (!queryParameters) {
Expand Down
3 changes: 1 addition & 2 deletions examples/pure-js/gen.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as fs from "fs";

import { CodeGenerator } from "@himenon/openapi-typescript-code-generator";
import * as fs from "fs";

const main = () => {
const codeGenerator = new CodeGenerator("spec/openapi.yml");
Expand Down
2 changes: 1 addition & 1 deletion examples/readme-sample/ast-code-template.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TsGenerator } from "@himenon/openapi-typescript-code-generator/dist/api";
import * as Types from "@himenon/openapi-typescript-code-generator/dist/types";
import type * as Types from "@himenon/openapi-typescript-code-generator/dist/types";

type Option = {};

Expand Down
3 changes: 1 addition & 2 deletions examples/readme-sample/generator-template.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as fs from "fs";

import { CodeGenerator } from "@himenon/openapi-typescript-code-generator";
import type * as Types from "@himenon/openapi-typescript-code-generator/dist/types";
import * as fs from "fs";

/** ここにCode Templateの定義を記述してください */
const customGenerator: Types.CodeGenerator.CustomGenerator<{}> = {
Expand Down
3 changes: 1 addition & 2 deletions examples/readme-sample/split-typedef-and-api-client.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as fs from "fs";

import { CodeGenerator } from "@himenon/openapi-typescript-code-generator";
import * as Templates from "@himenon/openapi-typescript-code-generator/dist/templates";
import type * as Types from "@himenon/openapi-typescript-code-generator/dist/types";
import * as fs from "fs";

const main = () => {
const codeGenerator = new CodeGenerator("your/openapi/spec.yml");
Expand Down
2 changes: 1 addition & 1 deletion examples/readme-sample/text-base-code-template.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Types from "@himenon/openapi-typescript-code-generator/dist/types";
import type * as Types from "@himenon/openapi-typescript-code-generator/dist/types";

interface Option {
showLog?: boolean;
Expand Down
3 changes: 1 addition & 2 deletions examples/readme-sample/typedef-and-api-client.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as fs from "fs";

import { CodeGenerator } from "@himenon/openapi-typescript-code-generator";
import * as Templates from "@himenon/openapi-typescript-code-generator/dist/templates";
import type * as Types from "@himenon/openapi-typescript-code-generator/dist/types";
import * as fs from "fs";

const main = () => {
const codeGenerator = new CodeGenerator("your/openapi/spec.yml");
Expand Down
3 changes: 1 addition & 2 deletions examples/readme-sample/typedef-only.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as fs from "fs";

import { CodeGenerator } from "@himenon/openapi-typescript-code-generator";
import * as fs from "fs";

const main = () => {
const codeGenerator = new CodeGenerator("your/openapi/spec.yml");
Expand Down
2 changes: 1 addition & 1 deletion examples/readme-sample/use-extract-schema-params.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Types from "@himenon/openapi-typescript-code-generator/dist/types";
import type * as Types from "@himenon/openapi-typescript-code-generator/dist/types";

type Option = {};

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
"scripts": {
"build": "tsup",
"clean": "pnpm ts ./scripts/clean.ts",
"format": "biome format --write .",
"format": "biome check --write --unsafe .",
"lerna:version:up": "lerna version --yes",
"lint": "biome lint .",
"lint": "biome check .",
"release:github:registry": "pnpm publish --no-git-checks --registry https://npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN}",
"release:npm:registry": "pnpm publish --no-git-checks",
"test": "run-p test:depcruise test:vitest test:code:gen:* test:snapshot",
Expand Down
2 changes: 1 addition & 1 deletion scripts/tools/shell.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ResultPromise, execa } from "execa";
import { execa, type ResultPromise } from "execa";

export const shell = (command: string, cwd: string = process.cwd()): ResultPromise => {
return execa(command, {
Expand Down
5 changes: 2 additions & 3 deletions scripts/validate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as fs from "fs";
import * as path from "path";

import * as fs from "node:fs";
import * as path from "node:path";
import * as yaml from "js-yaml";
import OpenAPISchemaValidator from "openapi-schema-validator";

Expand Down
4 changes: 2 additions & 2 deletions scripts/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const main = async () => {
try {
console.log((await shell("pnpm build")).stdout);
console.log((await shell("pnpm run test:code:gen")).stdout);
} catch (error) {
} catch (_error) {
console.error("Failed");
}
});
Expand All @@ -24,7 +24,7 @@ const main = async () => {
console.log(`Watch Change file ... ${path}`);
try {
console.log((await shell("pnpm run test:code:gen")).stdout);
} catch (error) {
} catch (_error) {
console.error("Failed");
}
});
Expand Down
6 changes: 3 additions & 3 deletions scripts/writer/Class.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from "fs";
import { posix as path } from "path";
import * as fs from "node:fs";
import { posix as path } from "node:path";

import { CodeGenerator, Option as CodeGeneratorOption } from "../../dist";
import { CodeGenerator, type Option as CodeGeneratorOption } from "../../dist";
import * as Templates from "../../dist/templates";
import type * as Types from "../../dist/types";

Expand Down
6 changes: 3 additions & 3 deletions scripts/writer/CurryingFunctional.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from "fs";
import { posix as path } from "path";
import * as fs from "node:fs";
import { posix as path } from "node:path";

import { CodeGenerator, Option as CodeGeneratorOption } from "../../dist";
import { CodeGenerator, type Option as CodeGeneratorOption } from "../../dist";
import * as Templates from "../../dist/templates";
import type * as Types from "../../dist/types";

Expand Down
6 changes: 3 additions & 3 deletions scripts/writer/Functional.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from "fs";
import { posix as path } from "path";
import * as fs from "node:fs";
import { posix as path } from "node:path";

import { CodeGenerator, Option as CodeGeneratorOption } from "../../dist";
import { CodeGenerator, type Option as CodeGeneratorOption } from "../../dist";
import * as Templates from "../../dist/templates";
import type * as Types from "../../dist/types";

Expand Down
4 changes: 2 additions & 2 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * as TsGenerator from "./internal/TsGenerator";
export * as OpenApiTools from "./internal/OpenApiTools";
export { FileSystem } from "./internal/FileSystem";
export * as OpenApiTools from "./internal/OpenApiTools";
export * as ResolveReference from "./internal/ResolveReference";
export * as TsGenerator from "./internal/TsGenerator";
export * as Validator from "./internal/Validator";
2 changes: 1 addition & 1 deletion src/code-templates/_shared/ApiClientArgument.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ts from "typescript";
import type ts from "typescript";

import type { TsGenerator } from "../../api";
import type { CodeGenerator } from "../../types";
Expand Down
2 changes: 1 addition & 1 deletion src/code-templates/_shared/MethodBody/CallRequest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ts from "typescript";
import type ts from "typescript";

import type { TsGenerator } from "../../../api";
import type { CodeGenerator } from "../../../types";
Expand Down
2 changes: 1 addition & 1 deletion src/code-templates/_shared/MethodBody/HeaderParameter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ts from "typescript";
import type ts from "typescript";

import type { TsGenerator } from "../../../api";
import * as Utils from "../utils";
Expand Down
2 changes: 1 addition & 1 deletion src/code-templates/_shared/MethodBody/PathParameter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ts from "typescript";
import type ts from "typescript";

import type { TsGenerator } from "../../../api";
import type { CodeGenerator } from "../../../types";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it, test } from "vitest";
import ts from "typescript";
import { describe, expect, test } from "vitest";

import { TsGenerator } from "../../../../api";
import type { CodeGenerator } from "../../../../types";
Expand Down
2 changes: 1 addition & 1 deletion src/code-templates/_shared/MethodBody/createEncodingMap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Encoding, MediaType } from "../../../typedef/OpenApi";
import type { Encoding, MediaType } from "../../../typedef/OpenApi";

type EncodingMap = Record<string, Encoding>;

Expand Down
6 changes: 3 additions & 3 deletions src/code-templates/_shared/MethodBody/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import ts from "typescript";
import type ts from "typescript";

import type { TsGenerator } from "../../../api";
import type { CodeGenerator } from "../../../types";
import { escapeText2 as escapeText } from "../../../utils";
import * as Utils from "../utils";
import type * as Utils from "../utils";
import * as CallRequest from "./CallRequest";
import { createEncodingMap } from "./createEncodingMap";
import * as HeaderParameter from "./HeaderParameter";
import * as PathParameter from "./PathParameter";
import * as QueryParameter from "./QueryParameter";
import { createEncodingMap } from "./createEncodingMap";
import type { MethodType } from "./types";

export const create = (factory: TsGenerator.Factory.Type, params: CodeGenerator.Params, methodType: MethodType): ts.Statement[] => {
Expand Down
2 changes: 1 addition & 1 deletion src/code-templates/_shared/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, it, test } from "vitest";
import { describe, expect, test } from "vitest";
import * as Utils from "../utils";

type OK = Utils.VariableElement;
Expand Down
4 changes: 2 additions & 2 deletions src/code-templates/_shared/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ts from "typescript";
import type ts from "typescript";

import type { TsGenerator } from "../../api";
import * as Utils from "../../utils";
Expand All @@ -19,7 +19,7 @@ export type Params$TemplateExpression = Item[];

const getTemplateSpan = (
factory: TsGenerator.Factory.Type,
currentIndex: number,
_currentIndex: number,
nextIndex: number,
lastIndex: number,
currentItem: ExpressionItem,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ts from "typescript";
import type ts from "typescript";

import type { TsGenerator } from "../../../api";

Expand Down
4 changes: 2 additions & 2 deletions src/code-templates/class-api-client/ApiClientClass/Method.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EOL } from "os";
import { EOL } from "node:os";

import ts from "typescript";
import type ts from "typescript";

import type { TsGenerator } from "../../../api";
import type { CodeGenerator } from "../../../types";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ts from "typescript";
import type ts from "typescript";

import type { TsGenerator } from "../../../api";
import type { CodeGenerator } from "../../../types";
Expand Down
4 changes: 2 additions & 2 deletions src/code-templates/class-api-client/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import ts from "typescript";
import type ts from "typescript";

import { TsGenerator } from "../../api";
import type { CodeGenerator } from "../../types";
import * as ApiClientArgument from "../_shared/ApiClientArgument";
import type { Option } from "../_shared/types";
import * as ApiClientClass from "./ApiClientClass";

export { Option };
export type { Option };

export const generator: CodeGenerator.GenerateFunction<Option> = (
codeGeneratorParamsList: CodeGenerator.Params[],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ts from "typescript";
import type ts from "typescript";

import type { TsGenerator } from "../../../api";
import type { CodeGenerator } from "../../../types";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EOL } from "os";
import { EOL } from "node:os";
import ts from "typescript";

import type { TsGenerator } from "../../../api";
Expand Down
7 changes: 3 additions & 4 deletions src/code-templates/currying-functional-api-client/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import ts from "typescript";
import type ts from "typescript";

import { TsGenerator } from "../../api";
import type { CodeGenerator } from "../../types";
import * as ApiClientArgument from "../_shared/ApiClientArgument";
import * as ApiClientInterface from "../_shared/ApiClientInterface";
import * as FunctionalApiClient from "./FunctionalApiClient";

import type { Option } from "../_shared/types";
import * as FunctionalApiClient from "./FunctionalApiClient";

export { Option };
export type { Option };

export const generator: CodeGenerator.GenerateFunction<Option> = (
codeGeneratorParamsList: CodeGenerator.Params[],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ts from "typescript";
import type ts from "typescript";

import type { TsGenerator } from "../../../api";
import type { CodeGenerator } from "../../../types";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ts from "typescript";
import type ts from "typescript";
import type { TsGenerator } from "../../../api";

export const create = (factory: TsGenerator.Factory.Type): ts.TypeAliasDeclaration[] => {
Expand Down
Loading
Loading