@faapi/faapi 6.19.0 → 6.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/testing.js CHANGED
@@ -2674,6 +2674,28 @@ function collectRouteSchemaSources(routes, rootDir) {
2674
2674
  typeInfo: resolver.resolve(paramsArg.typeName) ?? null
2675
2675
  });
2676
2676
  }
2677
+ if (inputType === "body") {
2678
+ const queryArg = meta.params.find((p) => p.type === "query");
2679
+ if (queryArg?.typeName) {
2680
+ sources.push({
2681
+ urlPath: entry.urlPath,
2682
+ filePath,
2683
+ schemaName: getSchemaName(method, "query"),
2684
+ typeInfo: resolver.resolve(queryArg.typeName) ?? null
2685
+ });
2686
+ }
2687
+ } else if (hasBody(method)) {
2688
+ const bodyArg = meta.params.find((p) => p.type === "body") ?? meta.params.find((p) => p.type === "form");
2689
+ if (bodyArg?.typeName) {
2690
+ sources.push({
2691
+ urlPath: entry.urlPath,
2692
+ filePath,
2693
+ schemaName: getSchemaName(method, "body"),
2694
+ typeInfo: resolver.resolve(bodyArg.typeName) ?? null,
2695
+ coerce: bodyArg.type === "form" || void 0
2696
+ });
2697
+ }
2698
+ }
2677
2699
  }
2678
2700
  }
2679
2701
  return { sources, resolversByFile };
@@ -4989,7 +5011,32 @@ function createRoutePipeline(opts) {
4989
5011
  ...paramsResult.data
4990
5012
  } : match.params;
4991
5013
  }
4992
- const body = inputType === "query" && hasBody(route.method) ? await resolveBodyForQueryMethod(request) : hasBody(route.method) ? result.data : void 0;
5014
+ if (inputType === "body") {
5015
+ const rawQuery = queryToObject(url.searchParams);
5016
+ const queryResult = await validateInput(schemaPath, route.method, "query", rawQuery);
5017
+ if (!queryResult.valid) {
5018
+ throw new ValidationError("\u53C2\u6570\u6821\u9A8C\u5931\u8D25", queryResult.issues);
5019
+ }
5020
+ if (queryResult.data !== rawQuery && typeof queryResult.data === "object" && queryResult.data !== null) {
5021
+ ctx.__validatedQuery = {
5022
+ ...rawQuery,
5023
+ ...queryResult.data
5024
+ };
5025
+ }
5026
+ }
5027
+ let body;
5028
+ if (inputType === "query" && hasBody(route.method)) {
5029
+ const parsed = await resolveBodyForQueryMethod(request);
5030
+ if (parsed !== void 0) {
5031
+ const bodyResult = await validateInput(schemaPath, route.method, "body", parsed);
5032
+ if (!bodyResult.valid) {
5033
+ throw new ValidationError("\u53C2\u6570\u6821\u9A8C\u5931\u8D25", bodyResult.issues);
5034
+ }
5035
+ body = bodyResult.data;
5036
+ }
5037
+ } else if (hasBody(route.method)) {
5038
+ body = result.data;
5039
+ }
4993
5040
  if (route.middlewares === void 0 && route.injectors === void 0 && route.middlewarePaths) {
4994
5041
  await ensureMiddlewaresCompiled(route.middlewarePaths, rootDir);
4995
5042
  const bundle = await loadMergedMiddlewares(route.middlewarePaths);