Skip to content

Commit a8f2935

Browse files
committed
chore: Update CLI option to disable using operationId for generating operation names
1 parent f65ac4e commit a8f2935

File tree

5 files changed

+157
-9
lines changed

5 files changed

+157
-9
lines changed

docs/src/content/docs/guides/cli-options.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ The available options are:
5757
- `biome`
5858
- `eslint`
5959

60-
### --operationId
60+
### --noOperationId
6161

62-
Use operation ID to generate operation names? The default value is `true`.
62+
Do not use operation ID to generate operation names. The default value is `true`.
6363

6464
### --enums \<value\>
6565

examples/react-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"dev:mock": "prism mock ../petstore.yaml --dynamic",
1010
"build": "tsc && vite build",
1111
"preview": "vite preview",
12-
"generate:api": "rimraf ./openapi && node ../../dist/cli.mjs -i ../petstore.yaml --format=biome --lint=biome -c @hey-api/client-axios",
12+
"generate:api": "rimraf ./openapi && node ../../dist/cli.mjs -i ../routes.json --format=biome --lint=biome -c @hey-api/client-axios",
1313
"test:generated": "tsc -p ./tsconfig.json --noEmit"
1414
},
1515
"dependencies": {

examples/routes.json

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
{
2+
"openapi": "3.0.3",
3+
"info": {
4+
"title": "api",
5+
"description": "",
6+
"license": {
7+
"name": ""
8+
},
9+
"version": "0.0.0"
10+
},
11+
"paths": {
12+
"/api/v1/boards/export": {
13+
"get": {
14+
"tags": ["boards"],
15+
"summary": "Returns an export of a collection of boards.",
16+
"operationId": "export",
17+
"parameters": [
18+
{
19+
"name": "name",
20+
"in": "query",
21+
"description": "The name of the resultant file (including extension).",
22+
"required": true,
23+
"schema": {
24+
"type": "string"
25+
}
26+
},
27+
{
28+
"name": "boards[]",
29+
"in": "query",
30+
"description": "The boards to be included in this export.",
31+
"required": true,
32+
"schema": {
33+
"type": "array",
34+
"items": {
35+
"$ref": "#/components/schemas/BoardId"
36+
}
37+
}
38+
}
39+
],
40+
"responses": {
41+
"200": {
42+
"description": "",
43+
"content": {
44+
"application/octet-stream": {
45+
"schema": {
46+
"type": "string",
47+
"format": "binary"
48+
}
49+
}
50+
}
51+
}
52+
}
53+
}
54+
},
55+
"/api/v1/documents/{file}/export": {
56+
"get": {
57+
"tags": ["documents"],
58+
"summary": "Exports the document as a PDF with annotations included.",
59+
"operationId": "export",
60+
"parameters": [
61+
{
62+
"name": "file",
63+
"in": "path",
64+
"required": true,
65+
"schema": {
66+
"$ref": "#/components/schemas/FileId"
67+
}
68+
}
69+
],
70+
"responses": {
71+
"200": {
72+
"description": "",
73+
"content": {
74+
"application/pdf": {
75+
"schema": {
76+
"type": "string",
77+
"format": "binary"
78+
}
79+
}
80+
}
81+
}
82+
}
83+
}
84+
},
85+
"/api/v1/tags/export": {
86+
"get": {
87+
"tags": ["tags"],
88+
"summary": "Returns an export of a collection of tags.",
89+
"operationId": "export",
90+
"parameters": [
91+
{
92+
"name": "name",
93+
"in": "query",
94+
"description": "The name of the resultant file (including extension).",
95+
"required": true,
96+
"schema": {
97+
"type": "string"
98+
}
99+
},
100+
{
101+
"name": "tags[]",
102+
"in": "query",
103+
"description": "The tags to be included in this export.",
104+
"required": true,
105+
"schema": {
106+
"type": "array",
107+
"items": {
108+
"$ref": "#/components/schemas/TagId"
109+
}
110+
}
111+
}
112+
],
113+
"responses": {
114+
"200": {
115+
"description": "",
116+
"content": {
117+
"application/octet-stream": {
118+
"schema": {
119+
"type": "string",
120+
"format": "binary"
121+
}
122+
}
123+
}
124+
}
125+
}
126+
}
127+
}
128+
},
129+
"components": {
130+
"schemas": {
131+
"BoardId": {
132+
"type": "string",
133+
"format": "base58 encoded UUID",
134+
"example": "CBD7wDFfZFjQfkvZ5BfC9"
135+
},
136+
"FileId": {
137+
"type": "string",
138+
"format": "base58 encoded UUID",
139+
"example": "CBD7wDFfZFjQfkvZ5BfC9"
140+
},
141+
"TagId": {
142+
"type": "string",
143+
"format": "base58 encoded UUID",
144+
"example": "CBD7wDFfZFjQfkvZ5BfC9"
145+
}
146+
}
147+
}
148+
}

src/cli.mts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export type LimitedUserConfig = {
1414
client?: "@hey-api/client-fetch" | "@hey-api/client-axios";
1515
format?: "biome" | "prettier";
1616
lint?: "biome" | "eslint";
17-
operationId?: boolean;
17+
noOperationId?: boolean;
1818
enums?: "javascript" | "typescript" | false;
1919
useDateType?: boolean;
2020
debug?: boolean;
@@ -58,7 +58,10 @@ async function setupProgram() {
5858
"Process output folder with linter?",
5959
).choices(["biome", "eslint"]),
6060
)
61-
.option("--operationId", "Use operation ID to generate operation names?")
61+
.option(
62+
"--noOperationId",
63+
"Do not use operationId to generate operation names",
64+
)
6265
.addOption(
6366
new Option(
6467
"--enums <value>",

src/generate.mts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ export async function generate(options: LimitedUserConfig, version: string) {
3131
services: {
3232
export: true,
3333
asClass: false,
34-
operationId:
35-
formattedOptions.operationId !== undefined
36-
? formattedOptions.operationId
37-
: true,
34+
operationId: !formattedOptions.noOperationId,
3835
},
3936
types: {
4037
dates: formattedOptions.useDateType,

0 commit comments

Comments
 (0)