transform()

in lib/transform/nullableTransformer.ts [11:75]


  transform({ objSchemas, allParams, arrSchemas, jsonLoader, logging }) {
    for (const sch of objSchemas) {
      try {
        if (sch.properties !== undefined) {
          for (const key of Object.keys(sch.properties)) {
            sch.properties[key] = transformNullable(
              sch.properties[key],
              jsonLoader,
              !sch.required?.includes(key)
            );
          }
        }

        const aProperty = sch.additionalProperties;
        if (typeof aProperty === "object" && aProperty !== null) {
          sch.additionalProperties = transformNullable(
            aProperty,
            jsonLoader,
            undefined,
            aProperty.type === "object"
          );
        }
      } catch (e) {
        if (logging) {
          logging(
            `Fail to transform ${sch}. ErrorMessage:${e?.message};ErrorStack:${e?.stack}.`,
            LiveValidatorLoggingLevels.error
          );
        } else {
          console.log(
            `Fail to transform ${sch}. ErrorMessage:${e?.message};ErrorStack:${e?.stack}.`
          );
        }
      }
    }

    for (const sch of arrSchemas) {
      try {
        if (sch.items) {
          if (Array.isArray(sch.items)) {
            sch.items = sch.items.map((item) => transformNullable(item, jsonLoader));
          } else {
            sch.items = transformNullable(sch.items, jsonLoader);
          }
        }
      } catch (e) {
        if (logging) {
          logging(
            `Fail to transform ${sch}. ErrorMessage:${e?.message};ErrorStack:${e?.stack}.`,
            LiveValidatorLoggingLevels.error
          );
        } else {
          console.log(
            `Fail to transform ${sch}. ErrorMessage:${e?.message};ErrorStack:${e?.stack}.`
          );
        }
      }
    }

    for (const param of allParams) {
      if (param.in === "query" && param.allowEmptyValue) {
        param.nullable = true;
      }
    }
  },