Skip to content

Commit 7651715

Browse files
Himenonclaude
andcommitted
refactor: remove path parameter normalization from generateValidRootSchema
The normalization that forced required: true on path parameters in generateValidRootSchema was not needed for correct TypeScript type generation. Parameter.ts already handles this via isPathProperty in generatePropertySignatureObject, which always produces a required property for path parameters regardless of the required field in the spec. Remove normalizePathParameters and its unit tests, keeping generateValidRootSchema minimal. Update parameter.json snapshots to reflect the absence of the injected required: true field (TypeScript interface output is unchanged). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 0a26e17 commit 7651715

4 files changed

Lines changed: 41 additions & 255 deletions

File tree

src/__tests__/generateValidRootSchema.test.ts

Lines changed: 0 additions & 170 deletions
This file was deleted.

src/generateValidRootSchema.ts

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,22 @@
11
import type * as Types from "./types";
22

3-
const normalizePathParameters = (parameters: (Types.OpenApi.Parameter | Types.OpenApi.Reference)[] | undefined): void => {
4-
if (!parameters) {
5-
return;
6-
}
7-
for (const parameter of parameters) {
8-
if ("$ref" in parameter) {
9-
continue;
10-
}
11-
// OpenAPI 3.x spec §3.3.2: path パラメータは常に required: true
12-
if (parameter.in === "path") {
13-
parameter.required = true;
14-
}
15-
}
16-
};
17-
183
export const generateValidRootSchema = (input: Types.OpenApi.Document): Types.OpenApi.Document => {
19-
if (input.components?.parameters) {
20-
normalizePathParameters(Object.values(input.components.parameters));
21-
}
22-
234
if (!input.paths) {
245
return input;
256
}
26-
27-
const httpMethods = ["get", "put", "post", "delete", "options", "head", "patch", "trace"] as const;
28-
29-
for (const [path, pathItem] of Object.entries(input.paths)) {
30-
normalizePathParameters(pathItem.parameters);
31-
32-
for (const method of httpMethods) {
33-
const operation = pathItem[method];
7+
/** update undefined operation id */
8+
for (const [path, methods] of Object.entries(input.paths || {})) {
9+
const targets = {
10+
get: methods.get,
11+
put: methods.put,
12+
post: methods.post,
13+
delete: methods.delete,
14+
options: methods.options,
15+
head: methods.head,
16+
patch: methods.patch,
17+
trace: methods.trace,
18+
} satisfies Record<string, Types.OpenApi.Operation | undefined>;
19+
for (const [method, operation] of Object.entries(targets)) {
3420
if (!operation) {
3521
continue;
3622
}
@@ -41,9 +27,7 @@ export const generateValidRootSchema = (input: Types.OpenApi.Document): Types.Op
4127
if (!operation.operationId) {
4228
operation.operationId = `${method.toLowerCase()}${path.charAt(0).toUpperCase() + path.slice(1)}`;
4329
}
44-
normalizePathParameters(operation.parameters);
4530
}
4631
}
47-
4832
return input;
4933
};

test/__tests__/class/__snapshots__/parameter-test.ts.snap

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -689,8 +689,7 @@ exports[`Parameter > required フィールドを省略したパスパラメー
689689
"pickedParameters": [
690690
{
691691
"name": "id",
692-
"in": "path",
693-
"required": true
692+
"in": "path"
694693
}
695694
],
696695
"requestContentTypes": [],
@@ -720,8 +719,7 @@ exports[`Parameter > required フィールドを省略したパスパラメー
720719
"name": "id",
721720
"schema": {
722721
"type": "string"
723-
},
724-
"required": true
722+
}
725723
}
726724
],
727725
"responses": {
@@ -761,13 +759,11 @@ exports[`Parameter > required フィールドを省略したパスパラメー
761759
"pickedParameters": [
762760
{
763761
"name": "name",
764-
"in": "path",
765-
"required": true
762+
"in": "path"
766763
},
767764
{
768765
"name": "path",
769-
"in": "path",
770-
"required": true
766+
"in": "path"
771767
},
772768
{
773769
"name": "path",
@@ -801,16 +797,14 @@ exports[`Parameter > required フィールドを省略したパスパラメー
801797
"name": "name",
802798
"schema": {
803799
"type": "string"
804-
},
805-
"required": true
800+
}
806801
},
807802
{
808803
"in": "path",
809804
"name": "path",
810805
"schema": {
811806
"type": "string"
812-
},
813-
"required": true
807+
}
814808
},
815809
{
816810
"in": "query",
@@ -849,13 +843,11 @@ exports[`Parameter > required フィールドを省略したパスパラメー
849843
"pickedParameters": [
850844
{
851845
"name": "name",
852-
"in": "path",
853-
"required": true
846+
"in": "path"
854847
},
855848
{
856849
"name": "path",
857-
"in": "path",
858-
"required": true
850+
"in": "path"
859851
},
860852
{
861853
"name": "path",
@@ -883,16 +875,14 @@ exports[`Parameter > required フィールドを省略したパスパラメー
883875
"name": "name",
884876
"schema": {
885877
"type": "string"
886-
},
887-
"required": true
878+
}
888879
},
889880
{
890881
"in": "path",
891882
"name": "path",
892883
"schema": {
893884
"type": "string"
894-
},
895-
"required": true
885+
}
896886
},
897887
{
898888
"in": "query",
@@ -924,13 +914,11 @@ exports[`Parameter > required フィールドを省略したパスパラメー
924914
"pickedParameters": [
925915
{
926916
"name": "userId",
927-
"in": "path",
928-
"required": true
917+
"in": "path"
929918
},
930919
{
931920
"name": "postId",
932-
"in": "path",
933-
"required": true
921+
"in": "path"
934922
},
935923
{
936924
"name": "include",
@@ -964,16 +952,14 @@ exports[`Parameter > required フィールドを省略したパスパラメー
964952
"name": "userId",
965953
"schema": {
966954
"type": "string"
967-
},
968-
"required": true
955+
}
969956
},
970957
{
971958
"in": "path",
972959
"name": "postId",
973960
"schema": {
974961
"type": "integer"
975-
},
976-
"required": true
962+
}
977963
},
978964
{
979965
"in": "query",

0 commit comments

Comments
 (0)