From a8f2935ce2a01652c4589d3608f9e08fb7f8de9c Mon Sep 17 00:00:00 2001 From: Urata Daiki <7nohe@users.noreply.github.com> Date: Mon, 14 Oct 2024 22:31:13 +0900 Subject: [PATCH] chore: Update CLI option to disable using operationId for generating operation names --- docs/src/content/docs/guides/cli-options.mdx | 4 +- examples/react-app/package.json | 2 +- examples/routes.json | 148 +++++++++++++++++++ src/cli.mts | 7 +- src/generate.mts | 5 +- 5 files changed, 157 insertions(+), 9 deletions(-) create mode 100644 examples/routes.json diff --git a/docs/src/content/docs/guides/cli-options.mdx b/docs/src/content/docs/guides/cli-options.mdx index e7e8ce5..5ac41a8 100644 --- a/docs/src/content/docs/guides/cli-options.mdx +++ b/docs/src/content/docs/guides/cli-options.mdx @@ -57,9 +57,9 @@ The available options are: - `biome` - `eslint` -### --operationId +### --noOperationId -Use operation ID to generate operation names? The default value is `true`. +Do not use operation ID to generate operation names. The default value is `true`. ### --enums \ diff --git a/examples/react-app/package.json b/examples/react-app/package.json index db1d4c7..4c1c47e 100644 --- a/examples/react-app/package.json +++ b/examples/react-app/package.json @@ -9,7 +9,7 @@ "dev:mock": "prism mock ../petstore.yaml --dynamic", "build": "tsc && vite build", "preview": "vite preview", - "generate:api": "rimraf ./openapi && node ../../dist/cli.mjs -i ../petstore.yaml --format=biome --lint=biome -c @hey-api/client-axios", + "generate:api": "rimraf ./openapi && node ../../dist/cli.mjs -i ../routes.json --format=biome --lint=biome -c @hey-api/client-axios", "test:generated": "tsc -p ./tsconfig.json --noEmit" }, "dependencies": { diff --git a/examples/routes.json b/examples/routes.json new file mode 100644 index 0000000..a53b9d0 --- /dev/null +++ b/examples/routes.json @@ -0,0 +1,148 @@ +{ + "openapi": "3.0.3", + "info": { + "title": "api", + "description": "", + "license": { + "name": "" + }, + "version": "0.0.0" + }, + "paths": { + "/api/v1/boards/export": { + "get": { + "tags": ["boards"], + "summary": "Returns an export of a collection of boards.", + "operationId": "export", + "parameters": [ + { + "name": "name", + "in": "query", + "description": "The name of the resultant file (including extension).", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "boards[]", + "in": "query", + "description": "The boards to be included in this export.", + "required": true, + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/BoardId" + } + } + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/octet-stream": { + "schema": { + "type": "string", + "format": "binary" + } + } + } + } + } + } + }, + "/api/v1/documents/{file}/export": { + "get": { + "tags": ["documents"], + "summary": "Exports the document as a PDF with annotations included.", + "operationId": "export", + "parameters": [ + { + "name": "file", + "in": "path", + "required": true, + "schema": { + "$ref": "#/components/schemas/FileId" + } + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/pdf": { + "schema": { + "type": "string", + "format": "binary" + } + } + } + } + } + } + }, + "/api/v1/tags/export": { + "get": { + "tags": ["tags"], + "summary": "Returns an export of a collection of tags.", + "operationId": "export", + "parameters": [ + { + "name": "name", + "in": "query", + "description": "The name of the resultant file (including extension).", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "tags[]", + "in": "query", + "description": "The tags to be included in this export.", + "required": true, + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/TagId" + } + } + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/octet-stream": { + "schema": { + "type": "string", + "format": "binary" + } + } + } + } + } + } + } + }, + "components": { + "schemas": { + "BoardId": { + "type": "string", + "format": "base58 encoded UUID", + "example": "CBD7wDFfZFjQfkvZ5BfC9" + }, + "FileId": { + "type": "string", + "format": "base58 encoded UUID", + "example": "CBD7wDFfZFjQfkvZ5BfC9" + }, + "TagId": { + "type": "string", + "format": "base58 encoded UUID", + "example": "CBD7wDFfZFjQfkvZ5BfC9" + } + } + } +} diff --git a/src/cli.mts b/src/cli.mts index 8106534..461d70f 100644 --- a/src/cli.mts +++ b/src/cli.mts @@ -14,7 +14,7 @@ export type LimitedUserConfig = { client?: "@hey-api/client-fetch" | "@hey-api/client-axios"; format?: "biome" | "prettier"; lint?: "biome" | "eslint"; - operationId?: boolean; + noOperationId?: boolean; enums?: "javascript" | "typescript" | false; useDateType?: boolean; debug?: boolean; @@ -58,7 +58,10 @@ async function setupProgram() { "Process output folder with linter?", ).choices(["biome", "eslint"]), ) - .option("--operationId", "Use operation ID to generate operation names?") + .option( + "--noOperationId", + "Do not use operationId to generate operation names", + ) .addOption( new Option( "--enums ", diff --git a/src/generate.mts b/src/generate.mts index 068354c..229f0c7 100644 --- a/src/generate.mts +++ b/src/generate.mts @@ -31,10 +31,7 @@ export async function generate(options: LimitedUserConfig, version: string) { services: { export: true, asClass: false, - operationId: - formattedOptions.operationId !== undefined - ? formattedOptions.operationId - : true, + operationId: !formattedOptions.noOperationId, }, types: { dates: formattedOptions.useDateType,