fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #2099 from hey-api/feat/validators-request-body

feat(validators): generate schemas for request bodies

authored by

Lubos and committed by
GitHub
4de9fc93 bb2b1e0c

+592 -62
+5
.changeset/quiet-pigs-knock.md
··· 1 + --- 2 + '@hey-api/openapi-ts': patch 3 + --- 4 + 5 + feat(validators): generate schemas for request bodies
+1 -1
packages/openapi-ts-tests/test/3.1.x.test.ts
··· 696 696 }, 697 697 { 698 698 config: createConfig({ 699 - input: 'validators.json', 699 + input: 'validators.yaml', 700 700 output: 'validators', 701 701 plugins: ['valibot', 'zod'], 702 702 }),
+5
packages/openapi-ts-tests/test/__snapshots__/2.0.x/plugins/valibot/default/valibot.gen.ts
··· 438 438 export const vNonAsciiæøåÆøÅöôêÊ字符串Response = vNonAsciiStringæøåÆøÅöôêÊ字符串; 439 439 440 440 /** 441 + * Body should not be unknown 442 + */ 443 + export const vPostApiVbyApiVersionBodyData = vParameterActivityParams; 444 + 445 + /** 441 446 * OK 442 447 */ 443 448 export const vPostApiVbyApiVersionBodyResponse = vResponsePostActivityResponse;
+5
packages/openapi-ts-tests/test/__snapshots__/2.0.x/plugins/zod/default/zod.gen.ts
··· 431 431 export const zNonAsciiæøåÆøÅöôêÊ字符串Response = zNonAsciiStringæøåÆøÅöôêÊ字符串; 432 432 433 433 /** 434 + * Body should not be unknown 435 + */ 436 + export const zPostApiVbyApiVersionBodyData = zParameterActivityParams; 437 + 438 + /** 434 439 * OK 435 440 */ 436 441 export const zPostApiVbyApiVersionBodyResponse = zResponsePostActivityResponse;
+101 -1
packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/valibot/default/valibot.gen.ts
··· 1058 1058 vGenericSchemaDuplicateIssue1SystemString 1059 1059 ]); 1060 1060 1061 + export const vSimpleRequestBody = vModelWithString; 1062 + 1063 + export const vSimpleFormData = vModelWithString; 1064 + 1065 + export const vImportData = v.union([ 1066 + vModelWithReadOnlyAndWriteOnly, 1067 + vModelWithArrayReadOnlyAndWriteOnly 1068 + ]); 1069 + 1061 1070 export const vImportResponse = v.union([ 1062 1071 vModelFromZendesk, 1063 1072 vModelWithReadOnlyAndWriteOnly ··· 1073 1082 */ 1074 1083 export const vGetApiVbyApiVersionSimpleOperationResponse = v.number(); 1075 1084 1085 + /** 1086 + * This is the parameter that goes into the body 1087 + */ 1088 + export const vCallWithParametersData = v.union([ 1089 + v.object({}), 1090 + v.null() 1091 + ]); 1092 + 1093 + /** 1094 + * This is the parameter that goes into the body 1095 + */ 1096 + export const vCallWithWeirdParameterNamesData = v.union([ 1097 + vModelWithString, 1098 + v.null() 1099 + ]); 1100 + 1101 + /** 1102 + * This is a required parameter 1103 + */ 1104 + export const vGetCallWithOptionalParamData = vModelWithOneOfEnum; 1105 + 1106 + /** 1107 + * This is an optional parameter 1108 + */ 1109 + export const vPostCallWithOptionalParamData = v.object({ 1110 + offset: v.optional(v.union([ 1111 + v.number(), 1112 + v.null() 1113 + ])) 1114 + }); 1115 + 1076 1116 export const vPostCallWithOptionalParamResponse = v.union([ 1077 1117 v.number(), 1078 1118 v.void() 1079 1119 ]); 1120 + 1121 + /** 1122 + * A reusable request body 1123 + */ 1124 + export const vPostApiVbyApiVersionRequestBodyData = vSimpleRequestBody; 1125 + 1126 + /** 1127 + * A reusable request body 1128 + */ 1129 + export const vPostApiVbyApiVersionFormDataData = vSimpleFormData; 1080 1130 1081 1131 /** 1082 1132 * Success ··· 1122 1172 v.object({}) 1123 1173 ]); 1124 1174 1175 + export const vUploadFileData = v.string(); 1176 + 1125 1177 export const vUploadFileResponse = v.boolean(); 1126 1178 1127 1179 /** ··· 1145 1197 })) 1146 1198 }); 1147 1199 1200 + export const vMultipartRequestData = v.object({ 1201 + content: v.optional(v.string()), 1202 + data: v.optional(v.union([ 1203 + vModelWithString, 1204 + v.null() 1205 + ])) 1206 + }); 1207 + 1208 + export const vComplexParamsData = v.object({ 1209 + key: v.pipe(v.union([ 1210 + v.pipe(v.pipe(v.string(), v.maxLength(64), v.regex(/^[a-zA-Z0-9_]*$/)), v.readonly()), 1211 + v.null() 1212 + ]), v.readonly()), 1213 + name: v.union([ 1214 + v.pipe(v.string(), v.maxLength(255)), 1215 + v.null() 1216 + ]), 1217 + enabled: v.optional(v.boolean(), true), 1218 + type: v.picklist([ 1219 + 'Monkey', 1220 + 'Horse', 1221 + 'Bird' 1222 + ]), 1223 + listOfModels: v.optional(v.union([ 1224 + v.array(vModelWithString), 1225 + v.null() 1226 + ])), 1227 + listOfStrings: v.optional(v.union([ 1228 + v.array(v.string()), 1229 + v.null() 1230 + ])), 1231 + parameters: v.union([ 1232 + vModelWithString, 1233 + vModelWithEnum, 1234 + vModelWithArray, 1235 + vModelWithDictionary 1236 + ]), 1237 + user: v.optional(v.pipe(v.object({ 1238 + id: v.optional(v.pipe(v.pipe(v.number(), v.integer()), v.readonly())), 1239 + name: v.optional(v.pipe(v.union([ 1240 + v.pipe(v.string(), v.readonly()), 1241 + v.null() 1242 + ]), v.readonly())) 1243 + }), v.readonly())) 1244 + }); 1245 + 1148 1246 /** 1149 1247 * Success 1150 1248 */ ··· 1153 1251 /** 1154 1252 * Successful response 1155 1253 */ 1156 - export const vNonAsciiæøåÆøÅöôêÊ字符串Response = v.array(vNonAsciiStringæøåÆøÅöôêÊ字符串); 1254 + export const vNonAsciiæøåÆøÅöôêÊ字符串Response = v.array(vNonAsciiStringæøåÆøÅöôêÊ字符串); 1255 + 1256 + export const vPutWithFormUrlEncodedData = vArrayWithStrings;
+101 -1
packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/zod/default/zod.gen.ts
··· 972 972 zGenericSchemaDuplicateIssue1SystemString 973 973 ]); 974 974 975 + export const zSimpleRequestBody = zModelWithString; 976 + 977 + export const zSimpleFormData = zModelWithString; 978 + 979 + export const zImportData = z.union([ 980 + zModelWithReadOnlyAndWriteOnly, 981 + zModelWithArrayReadOnlyAndWriteOnly 982 + ]); 983 + 975 984 export const zImportResponse = z.union([ 976 985 zModelFromZendesk, 977 986 zModelWithReadOnlyAndWriteOnly ··· 987 996 */ 988 997 export const zGetApiVbyApiVersionSimpleOperationResponse = z.number(); 989 998 999 + /** 1000 + * This is the parameter that goes into the body 1001 + */ 1002 + export const zCallWithParametersData = z.union([ 1003 + z.object({}), 1004 + z.null() 1005 + ]); 1006 + 1007 + /** 1008 + * This is the parameter that goes into the body 1009 + */ 1010 + export const zCallWithWeirdParameterNamesData = z.union([ 1011 + zModelWithString, 1012 + z.null() 1013 + ]); 1014 + 1015 + /** 1016 + * This is a required parameter 1017 + */ 1018 + export const zGetCallWithOptionalParamData = zModelWithOneOfEnum; 1019 + 1020 + /** 1021 + * This is an optional parameter 1022 + */ 1023 + export const zPostCallWithOptionalParamData = z.object({ 1024 + offset: z.union([ 1025 + z.number(), 1026 + z.null() 1027 + ]).optional() 1028 + }); 1029 + 990 1030 export const zPostCallWithOptionalParamResponse = z.union([ 991 1031 z.number(), 992 1032 z.void() 993 1033 ]); 1034 + 1035 + /** 1036 + * A reusable request body 1037 + */ 1038 + export const zPostApiVbyApiVersionRequestBodyData = zSimpleRequestBody; 1039 + 1040 + /** 1041 + * A reusable request body 1042 + */ 1043 + export const zPostApiVbyApiVersionFormDataData = zSimpleFormData; 994 1044 995 1045 /** 996 1046 * Success ··· 1033 1083 z.object({}) 1034 1084 ]); 1035 1085 1086 + export const zUploadFileData = z.string(); 1087 + 1036 1088 export const zUploadFileResponse = z.boolean(); 1037 1089 1038 1090 /** ··· 1056 1108 }).optional() 1057 1109 }); 1058 1110 1111 + export const zMultipartRequestData = z.object({ 1112 + content: z.string().optional(), 1113 + data: z.union([ 1114 + zModelWithString, 1115 + z.null() 1116 + ]).optional() 1117 + }); 1118 + 1119 + export const zComplexParamsData = z.object({ 1120 + key: z.union([ 1121 + z.string().max(64).regex(/^[a-zA-Z0-9_]*$/).readonly(), 1122 + z.null() 1123 + ]).readonly(), 1124 + name: z.union([ 1125 + z.string().max(255), 1126 + z.null() 1127 + ]), 1128 + enabled: z.boolean().optional().default(true), 1129 + type: z.enum([ 1130 + 'Monkey', 1131 + 'Horse', 1132 + 'Bird' 1133 + ]), 1134 + listOfModels: z.union([ 1135 + z.array(zModelWithString), 1136 + z.null() 1137 + ]).optional(), 1138 + listOfStrings: z.union([ 1139 + z.array(z.string()), 1140 + z.null() 1141 + ]).optional(), 1142 + parameters: z.union([ 1143 + zModelWithString, 1144 + zModelWithEnum, 1145 + zModelWithArray, 1146 + zModelWithDictionary 1147 + ]), 1148 + user: z.object({ 1149 + id: z.number().int().readonly().optional(), 1150 + name: z.union([ 1151 + z.string().readonly(), 1152 + z.null() 1153 + ]).readonly().optional() 1154 + }).readonly().optional() 1155 + }); 1156 + 1059 1157 /** 1060 1158 * Success 1061 1159 */ ··· 1064 1162 /** 1065 1163 * Successful response 1066 1164 */ 1067 - export const zNonAsciiæøåÆøÅöôêÊ字符串Response = z.array(zNonAsciiStringæøåÆøÅöôêÊ字符串); 1165 + export const zNonAsciiæøåÆøÅöôêÊ字符串Response = z.array(zNonAsciiStringæøåÆøÅöôêÊ字符串); 1166 + 1167 + export const zPutWithFormUrlEncodedData = zArrayWithStrings;
+107 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/plugins/valibot/default/valibot.gen.ts
··· 1056 1056 vGenericSchemaDuplicateIssue1SystemString 1057 1057 ]); 1058 1058 1059 + /** 1060 + * A reusable request body 1061 + */ 1062 + export const vSimpleRequestBody = vModelWithString; 1063 + 1064 + /** 1065 + * A reusable request body 1066 + */ 1067 + export const vSimpleFormData = vModelWithString; 1068 + 1069 + export const vImportData = v.union([ 1070 + vModelWithReadOnlyAndWriteOnly, 1071 + vModelWithArrayReadOnlyAndWriteOnly 1072 + ]); 1073 + 1059 1074 export const vImportResponse = v.union([ 1060 1075 vModelFromZendesk, 1061 1076 vModelWithReadOnlyAndWriteOnly ··· 1071 1086 */ 1072 1087 export const vGetApiVbyApiVersionSimpleOperationResponse = v.number(); 1073 1088 1089 + /** 1090 + * This is the parameter that goes into the body 1091 + */ 1092 + export const vCallWithParametersData = v.union([ 1093 + v.object({}), 1094 + v.null() 1095 + ]); 1096 + 1097 + /** 1098 + * This is the parameter that goes into the body 1099 + */ 1100 + export const vCallWithWeirdParameterNamesData = v.union([ 1101 + vModelWithString, 1102 + v.null() 1103 + ]); 1104 + 1105 + /** 1106 + * This is a required parameter 1107 + */ 1108 + export const vGetCallWithOptionalParamData = vModelWithOneOfEnum; 1109 + 1110 + /** 1111 + * This is an optional parameter 1112 + */ 1113 + export const vPostCallWithOptionalParamData = v.object({ 1114 + offset: v.optional(v.union([ 1115 + v.number(), 1116 + v.null() 1117 + ])) 1118 + }); 1119 + 1074 1120 export const vPostCallWithOptionalParamResponse = v.union([ 1075 1121 v.number(), 1076 1122 v.void() 1077 1123 ]); 1078 1124 1079 1125 /** 1126 + * A reusable request body 1127 + */ 1128 + export const vPostApiVbyApiVersionRequestBodyData = vSimpleRequestBody; 1129 + 1130 + /** 1131 + * A reusable request body 1132 + */ 1133 + export const vPostApiVbyApiVersionFormDataData = vSimpleFormData; 1134 + 1135 + /** 1080 1136 * Success 1081 1137 */ 1082 1138 export const vCallWithNoContentResponseResponse = v.void(); ··· 1120 1176 v.object({}) 1121 1177 ]); 1122 1178 1179 + export const vUploadFileData = v.string(); 1180 + 1123 1181 export const vUploadFileResponse = v.boolean(); 1124 1182 1125 1183 /** ··· 1143 1201 })) 1144 1202 }); 1145 1203 1204 + export const vMultipartRequestData = v.object({ 1205 + content: v.optional(v.string()), 1206 + data: v.optional(v.union([ 1207 + vModelWithString, 1208 + v.null() 1209 + ])) 1210 + }); 1211 + 1212 + export const vComplexParamsData = v.object({ 1213 + key: v.pipe(v.union([ 1214 + v.pipe(v.pipe(v.string(), v.maxLength(64), v.regex(/^[a-zA-Z0-9_]*$/)), v.readonly()), 1215 + v.null() 1216 + ]), v.readonly()), 1217 + name: v.union([ 1218 + v.pipe(v.string(), v.maxLength(255)), 1219 + v.null() 1220 + ]), 1221 + enabled: v.optional(v.boolean(), true), 1222 + type: v.picklist([ 1223 + 'Monkey', 1224 + 'Horse', 1225 + 'Bird' 1226 + ]), 1227 + listOfModels: v.optional(v.union([ 1228 + v.array(vModelWithString), 1229 + v.null() 1230 + ])), 1231 + listOfStrings: v.optional(v.union([ 1232 + v.array(v.string()), 1233 + v.null() 1234 + ])), 1235 + parameters: v.union([ 1236 + vModelWithString, 1237 + vModelWithEnum, 1238 + vModelWithArray, 1239 + vModelWithDictionary 1240 + ]), 1241 + user: v.optional(v.pipe(v.object({ 1242 + id: v.optional(v.pipe(v.pipe(v.number(), v.integer()), v.readonly())), 1243 + name: v.optional(v.pipe(v.union([ 1244 + v.pipe(v.string(), v.readonly()), 1245 + v.null() 1246 + ]), v.readonly())) 1247 + }), v.readonly())) 1248 + }); 1249 + 1146 1250 /** 1147 1251 * Success 1148 1252 */ ··· 1151 1255 /** 1152 1256 * Successful response 1153 1257 */ 1154 - export const vNonAsciiæøåÆøÅöôêÊ字符串Response = v.array(vNonAsciiStringæøåÆøÅöôêÊ字符串); 1258 + export const vNonAsciiæøåÆøÅöôêÊ字符串Response = v.array(vNonAsciiStringæøåÆøÅöôêÊ字符串); 1259 + 1260 + export const vPutWithFormUrlEncodedData = vArrayWithStrings;
+107 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/plugins/zod/default/zod.gen.ts
··· 963 963 zGenericSchemaDuplicateIssue1SystemString 964 964 ]); 965 965 966 + /** 967 + * A reusable request body 968 + */ 969 + export const zSimpleRequestBody = zModelWithString; 970 + 971 + /** 972 + * A reusable request body 973 + */ 974 + export const zSimpleFormData = zModelWithString; 975 + 976 + export const zImportData = z.union([ 977 + zModelWithReadOnlyAndWriteOnly, 978 + zModelWithArrayReadOnlyAndWriteOnly 979 + ]); 980 + 966 981 export const zImportResponse = z.union([ 967 982 zModelFromZendesk, 968 983 zModelWithReadOnlyAndWriteOnly ··· 978 993 */ 979 994 export const zGetApiVbyApiVersionSimpleOperationResponse = z.number(); 980 995 996 + /** 997 + * This is the parameter that goes into the body 998 + */ 999 + export const zCallWithParametersData = z.union([ 1000 + z.object({}), 1001 + z.null() 1002 + ]); 1003 + 1004 + /** 1005 + * This is the parameter that goes into the body 1006 + */ 1007 + export const zCallWithWeirdParameterNamesData = z.union([ 1008 + zModelWithString, 1009 + z.null() 1010 + ]); 1011 + 1012 + /** 1013 + * This is a required parameter 1014 + */ 1015 + export const zGetCallWithOptionalParamData = zModelWithOneOfEnum; 1016 + 1017 + /** 1018 + * This is an optional parameter 1019 + */ 1020 + export const zPostCallWithOptionalParamData = z.object({ 1021 + offset: z.union([ 1022 + z.number(), 1023 + z.null() 1024 + ]).optional() 1025 + }); 1026 + 981 1027 export const zPostCallWithOptionalParamResponse = z.union([ 982 1028 z.number(), 983 1029 z.void() 984 1030 ]); 985 1031 986 1032 /** 1033 + * A reusable request body 1034 + */ 1035 + export const zPostApiVbyApiVersionRequestBodyData = zSimpleRequestBody; 1036 + 1037 + /** 1038 + * A reusable request body 1039 + */ 1040 + export const zPostApiVbyApiVersionFormDataData = zSimpleFormData; 1041 + 1042 + /** 987 1043 * Success 988 1044 */ 989 1045 export const zCallWithNoContentResponseResponse = z.void(); ··· 1024 1080 z.object({}) 1025 1081 ]); 1026 1082 1083 + export const zUploadFileData = z.string(); 1084 + 1027 1085 export const zUploadFileResponse = z.boolean(); 1028 1086 1029 1087 /** ··· 1047 1105 }).optional() 1048 1106 }); 1049 1107 1108 + export const zMultipartRequestData = z.object({ 1109 + content: z.string().optional(), 1110 + data: z.union([ 1111 + zModelWithString, 1112 + z.null() 1113 + ]).optional() 1114 + }); 1115 + 1116 + export const zComplexParamsData = z.object({ 1117 + key: z.union([ 1118 + z.string().max(64).regex(/^[a-zA-Z0-9_]*$/).readonly(), 1119 + z.null() 1120 + ]).readonly(), 1121 + name: z.union([ 1122 + z.string().max(255), 1123 + z.null() 1124 + ]), 1125 + enabled: z.boolean().optional().default(true), 1126 + type: z.enum([ 1127 + 'Monkey', 1128 + 'Horse', 1129 + 'Bird' 1130 + ]), 1131 + listOfModels: z.union([ 1132 + z.array(zModelWithString), 1133 + z.null() 1134 + ]).optional(), 1135 + listOfStrings: z.union([ 1136 + z.array(z.string()), 1137 + z.null() 1138 + ]).optional(), 1139 + parameters: z.union([ 1140 + zModelWithString, 1141 + zModelWithEnum, 1142 + zModelWithArray, 1143 + zModelWithDictionary 1144 + ]), 1145 + user: z.object({ 1146 + id: z.number().int().readonly().optional(), 1147 + name: z.union([ 1148 + z.string().readonly(), 1149 + z.null() 1150 + ]).readonly().optional() 1151 + }).readonly().optional() 1152 + }); 1153 + 1050 1154 /** 1051 1155 * Success 1052 1156 */ ··· 1055 1159 /** 1056 1160 * Successful response 1057 1161 */ 1058 - export const zNonAsciiæøåÆøÅöôêÊ字符串Response = z.array(zNonAsciiStringæøåÆøÅöôêÊ字符串); 1162 + export const zNonAsciiæøåÆøÅöôêÊ字符串Response = z.array(zNonAsciiStringæøåÆøÅöôêÊ字符串); 1163 + 1164 + export const zPutWithFormUrlEncodedData = zArrayWithStrings;
+11 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/validators/valibot.gen.ts
··· 20 20 v.null() 21 21 ]), null); 22 22 23 - export const vBaz = v.optional(v.pipe(v.pipe(v.string(), v.regex(/foo\nbar/)), v.readonly()), 'baz'); 23 + export const vBaz = v.optional(v.pipe(v.pipe(v.string(), v.regex(/foo\nbar/)), v.readonly()), 'baz'); 24 + 25 + export const vFoo2 = v.object({ 26 + foo: v.optional(vBar) 27 + }); 28 + 29 + export const vPatchFooData = v.object({ 30 + foo: v.optional(v.string()) 31 + }); 32 + 33 + export const vPostFooData = vFoo2;
+11 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/validators/zod.gen.ts
··· 20 20 z.null() 21 21 ]).default(null); 22 22 23 - export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz'); 23 + export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz'); 24 + 25 + export const zFoo2 = z.object({ 26 + foo: zBar.optional() 27 + }); 28 + 29 + export const zPatchFooData = z.object({ 30 + foo: z.string().optional() 31 + }); 32 + 33 + export const zPostFooData = zFoo2;
+6 -6
packages/openapi-ts-tests/test/openapi-ts.config.ts
··· 44 44 // openapi: '3.1.0', 45 45 // paths: {}, 46 46 // }, 47 - path: path.resolve(__dirname, 'spec', '3.1.x', 'full.json'), 47 + path: path.resolve(__dirname, 'spec', '3.1.x', 'validators.yaml'), 48 48 // path: 'http://localhost:4000/', 49 49 // path: 'https://get.heyapi.dev/', 50 50 // path: 'https://get.heyapi.dev/hey-api/backend?branch=main&version=1.0.0', ··· 96 96 // serviceNameBuilder: '^Parameters', 97 97 // throwOnError: true, 98 98 // transformer: '@hey-api/transformers', 99 - transformer: true, 99 + // transformer: true, 100 100 // validator: 'zod', 101 101 }, 102 102 { 103 103 // bigInt: true, 104 104 dates: true, 105 - name: '@hey-api/transformers', 105 + // name: '@hey-api/transformers', 106 106 }, 107 107 { 108 108 // enums: 'typescript+namespace', ··· 122 122 }, 123 123 { 124 124 exportFromIndex: true, 125 - name: '@tanstack/vue-query', 125 + // name: '@tanstack/vue-query', 126 126 }, 127 127 { 128 128 // comments: false, 129 129 // exportFromIndex: true, 130 - // name: 'valibot', 130 + name: 'valibot', 131 131 }, 132 132 { 133 133 // comments: false, 134 134 // exportFromIndex: true, 135 - // name: 'zod', 135 + name: 'zod', 136 136 }, 137 137 ], 138 138 // useOptions: false,
-49
packages/openapi-ts-tests/test/spec/3.1.x/validators.json
··· 1 - { 2 - "openapi": "3.1.0", 3 - "info": { 4 - "title": "OpenAPI 3.1.0 validators example", 5 - "version": "1" 6 - }, 7 - "components": { 8 - "schemas": { 9 - "Foo": { 10 - "default": null, 11 - "properties": { 12 - "foo": { 13 - "pattern": "^\\d{3}-\\d{2}-\\d{4}$", 14 - "type": "string" 15 - }, 16 - "bar": { 17 - "$ref": "#/components/schemas/Bar" 18 - }, 19 - "baz": { 20 - "items": { 21 - "$ref": "#/components/schemas/Foo" 22 - }, 23 - "type": "array" 24 - }, 25 - "qux": { 26 - "default": 0, 27 - "exclusiveMinimum": 0, 28 - "type": "integer" 29 - } 30 - }, 31 - "type": ["object", "null"] 32 - }, 33 - "Bar": { 34 - "properties": { 35 - "foo": { 36 - "$ref": "#/components/schemas/Foo" 37 - } 38 - }, 39 - "type": "object" 40 - }, 41 - "Baz": { 42 - "default": "baz", 43 - "pattern": "foo\\nbar", 44 - "readOnly": true, 45 - "type": "string" 46 - } 47 - } 48 - } 49 - }
+72
packages/openapi-ts-tests/test/spec/3.1.x/validators.yaml
··· 1 + openapi: 3.1.0 2 + info: 3 + title: OpenAPI 3.1.0 validators example 4 + version: '1' 5 + paths: 6 + /foo: 7 + patch: 8 + parameters: 9 + - in: query 10 + name: foo 11 + required: true 12 + schema: 13 + $ref: '#/components/schemas/Bar' 14 + requestBody: 15 + content: 16 + 'application/json': 17 + schema: 18 + properties: 19 + foo: 20 + type: string 21 + type: object 22 + required: true 23 + responses: 24 + '200': 25 + description: OK 26 + post: 27 + requestBody: 28 + $ref: '#/components/requestBodies/Foo' 29 + responses: 30 + '200': 31 + description: OK 32 + components: 33 + requestBodies: 34 + Foo: 35 + required: true 36 + content: 37 + 'application/json': 38 + schema: 39 + type: object 40 + properties: 41 + foo: 42 + $ref: '#/components/schemas/Bar' 43 + schemas: 44 + Foo: 45 + default: null 46 + properties: 47 + foo: 48 + pattern: ^\d{3}-\d{2}-\d{4}$ 49 + type: string 50 + bar: 51 + $ref: '#/components/schemas/Bar' 52 + baz: 53 + items: 54 + $ref: '#/components/schemas/Foo' 55 + type: array 56 + qux: 57 + default: 0 58 + exclusiveMinimum: 0 59 + type: integer 60 + type: 61 + - object 62 + - 'null' 63 + Bar: 64 + properties: 65 + foo: 66 + $ref: '#/components/schemas/Foo' 67 + type: object 68 + Baz: 69 + default: baz 70 + pattern: foo\nbar 71 + readOnly: true 72 + type: string
+30
packages/openapi-ts/src/plugins/valibot/plugin.ts
··· 848 848 plugin: Plugin.Instance<Config>; 849 849 result: Result; 850 850 }) => { 851 + if (operation.body) { 852 + schemaToValibotSchema({ 853 + $ref: operationIrRef({ 854 + case: 'camelCase', 855 + config: context.config, 856 + id: operation.id, 857 + type: 'data', 858 + }), 859 + context, 860 + plugin, 861 + result, 862 + schema: operation.body.schema, 863 + }); 864 + } 865 + 851 866 if (operation.responses) { 852 867 const { response } = operationResponsesMap(operation); 853 868 ··· 1134 1149 operation, 1135 1150 plugin, 1136 1151 result, 1152 + }); 1153 + }); 1154 + 1155 + context.subscribe('requestBody', ({ $ref, requestBody }) => { 1156 + const result: Result = { 1157 + circularReferenceTracker: new Set(), 1158 + hasCircularReference: false, 1159 + }; 1160 + 1161 + schemaToValibotSchema({ 1162 + $ref, 1163 + context, 1164 + plugin, 1165 + result, 1166 + schema: requestBody.schema, 1137 1167 }); 1138 1168 }); 1139 1169
+30
packages/openapi-ts/src/plugins/zod/plugin.ts
··· 815 815 plugin: Plugin.Instance<Config>; 816 816 result: Result; 817 817 }) => { 818 + if (operation.body) { 819 + schemaToZodSchema({ 820 + $ref: operationIrRef({ 821 + case: 'camelCase', 822 + config: context.config, 823 + id: operation.id, 824 + type: 'data', 825 + }), 826 + context, 827 + plugin, 828 + result, 829 + schema: operation.body.schema, 830 + }); 831 + } 832 + 818 833 if (operation.responses) { 819 834 const { response } = operationResponsesMap(operation); 820 835 ··· 1098 1113 operation, 1099 1114 plugin, 1100 1115 result, 1116 + }); 1117 + }); 1118 + 1119 + context.subscribe('requestBody', ({ $ref, requestBody }) => { 1120 + const result: Result = { 1121 + circularReferenceTracker: new Set(), 1122 + hasCircularReference: false, 1123 + }; 1124 + 1125 + schemaToZodSchema({ 1126 + $ref, 1127 + context, 1128 + plugin, 1129 + result, 1130 + schema: requestBody.schema, 1101 1131 }); 1102 1132 }); 1103 1133