var{defineProperty:m,getOwnPropertyNames:A,getOwnPropertyDescriptor:R}=Object,k=Object.prototype.hasOwnProperty;function P(e){return this[e]}var j=(e)=>{var t=(d??=new WeakMap).get(e),o;if(t)return t;if(t=m({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function"){for(var n of A(e))if(!k.call(t,n))m(t,n,{get:P.bind(e,n),enumerable:!(o=R(e,n))||o.enumerable})}return d.set(e,t),t},d;var b=(e)=>e;function v(e,t){this[e]=b.bind(null,t)}var E=(e,t)=>{for(var o in t)m(e,o,{get:t[o],enumerable:!0,configurable:!0,set:v.bind(t,o)})};var $=(e,t)=>()=>(e&&(t=e(e=0)),t);import u from"zod";function h(e){return{input:e.io.input?u.toJSONSchema(e.io.input.getZod()):null,output:e.io.output?u.toJSONSchema(e.io.output.getZod()):null,meta:{name:e.meta.key,version:e.meta.version,kind:e.meta.kind,description:e.meta.description,tags:e.meta.tags??[],stability:e.meta.stability??"stable"}}}function y(e,t){return`/${e.replace(/\./g,"/")}/v${t}`}function x(e){return e.replace(/\./g,"_").slice(0,64)}function F(e,t){let o=e.replace(/\./g,"_"),n=t.replace(/\./g,"_");return`${o}-v${n}`}function _(e){return x(e)}function N(e,t){return`${e.replace(/\./g,"_")}_v${t}`}import{compareVersions as I}from"compare-versions";function g(e,t){return`${e.replace(/\./g,"_")}_v${t}`}function O(e,t,o){return`${e}_${g(t,o)}`}function w(e,t){return(t??(e==="query"?"GET":"POST")).toLowerCase()}function T(e){let t=e.transport?.rest?.path??y(e.meta.key,e.meta.version);return t.startsWith("/")?t:`/${t}`}function G(e,t={}){let o=e.list().filter((r)=>r.meta.kind==="command"||r.meta.kind==="query").slice().sort((r,s)=>{let p=r.meta.key.localeCompare(s.meta.key);return p!==0?p:I(r.meta.version,s.meta.version)}),n={openapi:"3.1.0",info:{title:t.title??"ContractSpec API",version:t.version??"0.0.0",...t.description?{description:t.description}:{}},...t.servers?{servers:t.servers}:{},paths:{},components:{schemas:{}}};for(let r of o){let s=h(r),p=w(r.meta.kind,r.transport?.rest?.method),S=T(r),l=g(r.meta.key,r.meta.version),f=n.paths[S]??={},a={operationId:l,summary:r.meta.description??r.meta.key,description:r.meta.description,tags:r.meta.tags??[],"x-contractspec":{name:r.meta.key,version:r.meta.version,kind:r.meta.kind},responses:{}};if(s.input){let i=O("Input",r.meta.key,r.meta.version);n.components.schemas[i]=s.input,a.requestBody={required:!0,content:{"application/json":{schema:{$ref:`#/components/schemas/${i}`}}}}}let c={};if(s.output){let i=O("Output",r.meta.key,r.meta.version);n.components.schemas[i]=s.output,c["200"]={description:"OK",content:{"application/json":{schema:{$ref:`#/components/schemas/${i}`}}}}}else c["200"]={description:"OK"};a.responses=c,f[p]=a}return n}var J=[{id:"docs.tech.contracts.openapi-export",title:"OpenAPI export (OpenAPI 3.1) from OperationSpecRegistry",summary:"Generate a deterministic OpenAPI document from a OperationSpecRegistry using jsonSchemaForSpec + REST transport metadata.",kind:"reference",visibility:"public",route:"/docs/tech/contracts/openapi-export",tags:["contracts","openapi","rest"],body:`## OpenAPI export (OpenAPI 3.1) from OperationSpecRegistry

### Purpose

ContractSpec specs can be exported into an **OpenAPI 3.1** document for tooling (SDK generation, docs, gateways).

The export is **spec-first**:

- Uses \`jsonSchemaForSpec(spec)\` for input/output JSON Schema (from SchemaModel → zod → JSON Schema)
- Uses \`spec.transport.rest.method/path\` when present
- Falls back to deterministic defaults:
  - Method: \`POST\` for commands, \`GET\` for queries
  - Path: \`defaultRestPath(name, version)\` → \`/<dot/name>/v<version>\`

### Library API

- Function: \`openApiForRegistry(registry, options?)\`
- Location: \`@contractspec/lib.contracts-spec/openapi\`

### CLI

Export OpenAPI from a registry module:

\`\`\`bash
contractspec openapi --registry ./src/registry.ts --out ./openapi.json
\`\`\`

The registry module must export one of:

- \`registry: OperationSpecRegistry\`
- \`default(): OperationSpecRegistry | Promise<OperationSpecRegistry>\`
- \`createRegistry(): OperationSpecRegistry | Promise<OperationSpecRegistry>\`

### Notes / limitations (current)

- Responses are generated as a basic \`200\` response (plus schemas when available).
- Query (GET) inputs are currently represented as a JSON request body when an input schema exists.
- Errors are not yet expanded into OpenAPI responses; that will be added when we standardize error envelopes.`}];export{J as tech_contracts_openapi_export_DocBlocks,G as openApiForRegistry};
