// ../../node_modules/.pnpm/@standard-community+standard-openapi@0.2.9_@standard-community+standard-json@0.3.5_@sta_a8f2af4507f30d3c5e839067d4aa4952/node_modules/@standard-community/standard-openapi/dist/vendors/convert.js
function convertToOpenAPISchema(jsonSchema, context) {
  const _jsonSchema = JSON.parse(JSON.stringify(jsonSchema));
  if ("nullable" in _jsonSchema && _jsonSchema.nullable === true) {
    if (_jsonSchema.type) {
      if (Array.isArray(_jsonSchema.type)) {
        if (!_jsonSchema.type.includes("null")) {
          _jsonSchema.type.push("null");
        }
      } else {
        _jsonSchema.type = [_jsonSchema.type, "null"];
      }
    } else {
      _jsonSchema.type = ["null"];
    }
    delete _jsonSchema.nullable;
  }
  if (_jsonSchema.$schema) {
    delete _jsonSchema.$schema;
  }
  const nestedSchemaKeys = [
    "properties",
    "additionalProperties",
    "items",
    "additionalItems",
    "allOf",
    "anyOf",
    "oneOf",
    "not",
    "if",
    "then",
    "else",
    "definitions",
    "$defs",
    "patternProperties",
    "propertyNames",
    "contains"
    // "unevaluatedProperties",
    // "unevaluatedItems",
  ];
  nestedSchemaKeys.forEach((key) => {
    if (_jsonSchema[key] && (typeof _jsonSchema[key] === "object" || Array.isArray(_jsonSchema[key]))) {
      if (key === "properties" || key === "definitions" || key === "$defs" || key === "patternProperties") {
        for (const subKey in _jsonSchema[key]) {
          _jsonSchema[key][subKey] = convertToOpenAPISchema(
            _jsonSchema[key][subKey],
            context
          );
        }
      } else if (key === "allOf" || key === "anyOf" || key === "oneOf") {
        _jsonSchema[key] = _jsonSchema[key].map(
          (item) => convertToOpenAPISchema(item, context)
        );
      } else if (key === "items") {
        if (Array.isArray(_jsonSchema[key])) {
          _jsonSchema[key] = _jsonSchema[key].map(
            (item) => convertToOpenAPISchema(item, context)
          );
        } else {
          _jsonSchema[key] = convertToOpenAPISchema(_jsonSchema[key], context);
        }
      } else {
        _jsonSchema[key] = convertToOpenAPISchema(_jsonSchema[key], context);
      }
    }
  });
  if (_jsonSchema.ref || _jsonSchema.$id) {
    const { ref, $id, ...component } = _jsonSchema;
    const id = ref || $id;
    context.components.schemas = {
      ...context.components.schemas,
      [id]: component
    };
    return {
      $ref: `#/components/schemas/${id}`
    };
  } else if (_jsonSchema.$ref) {
    const { $ref, $defs } = _jsonSchema;
    const ref = $ref.split("/").pop();
    context.components.schemas = {
      ...context.components.schemas,
      ...$defs
    };
    return {
      $ref: `#/components/schemas/${ref}`
    };
  }
  return _jsonSchema;
}

export { convertToOpenAPISchema };
//# sourceMappingURL=chunk-N22YZ2SO.js.map
//# sourceMappingURL=chunk-N22YZ2SO.js.map