import { convertToOpenAPISchema } from './chunk-N22YZ2SO.js';
import { toJsonSchema } from './chunk-B5MDFOOY.js';

// ../../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/valibot-D_HTw1Gn.js
function getToOpenAPISchemaFn() {
  return async (schema, context) => {
    const openapiSchema = await toJsonSchema(schema, {
      errorMode: "ignore",
      // @ts-expect-error
      overrideAction: ({ valibotAction, jsonSchema }) => {
        const _jsonSchema = convertToOpenAPISchema(jsonSchema, context);
        if (valibotAction.kind === "metadata" && valibotAction.type === "metadata" && !("$ref" in _jsonSchema)) {
          const metadata = valibotAction.metadata;
          if (metadata.example !== void 0) {
            _jsonSchema.example = metadata.example;
          }
          if (metadata.examples && metadata.examples.length > 0) {
            _jsonSchema.examples = metadata.examples;
          }
          if (metadata.ref) {
            context.components.schemas = {
              ...context.components.schemas,
              [metadata.ref]: _jsonSchema
            };
            return {
              $ref: `#/components/schemas/${metadata.ref}`
            };
          }
        }
        return _jsonSchema;
      },
      ...context.options
    });
    if ("$schema" in openapiSchema) {
      delete openapiSchema.$schema;
    }
    return openapiSchema;
  };
}

export { getToOpenAPISchemaFn as default };
//# sourceMappingURL=valibot-D_HTw1Gn-FOK7YYT6.js.map
//# sourceMappingURL=valibot-D_HTw1Gn-FOK7YYT6.js.map