UNPKG

openapi3-ts

Version:

TS Model & utils for OpenAPI 3.x specification.

2 lines 4.09 kB
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./server-DR6RR5E8.js");let t=require("yaml");t=e.s(t);var n=class e{static create(t){return new e(t)}constructor(e){this.rootDoc=e||{openapi:`3.1.0`,info:{title:`app`,version:`version`},paths:{},components:{schemas:{},responses:{},parameters:{},examples:{},requestBodies:{},headers:{},securitySchemes:{},links:{},callbacks:{}},tags:[],servers:[]}}getSpec(){return this.rootDoc}getSpecAsJson(e,t){return JSON.stringify(this.rootDoc,e,t)}getSpecAsYaml(e,n){return t.stringify(this.rootDoc,e,n)}static isValidOpenApiVersion(e){e||=``;let t=/(\d+)\.(\d+).(\d+)/.exec(e);return!!(t&&parseInt(t[1],10)>=3)}addOpenApiVersion(t){if(!e.isValidOpenApiVersion(t))throw Error(`Invalid OpenApi version: `+t+`. Follow convention: 3.x.y`);return this.rootDoc.openapi=t,this}addInfo(e){return this.rootDoc.info=e,this}addContact(e){return this.rootDoc.info.contact=e,this}addLicense(e){return this.rootDoc.info.license=e,this}addTitle(e){return this.rootDoc.info.title=e,this}addDescription(e){return this.rootDoc.info.description=e,this}addTermsOfService(e){return this.rootDoc.info.termsOfService=e,this}addVersion(e){return this.rootDoc.info.version=e,this}addPath(e,t){return this.rootDoc.paths=this.rootDoc.paths||{},this.rootDoc.paths[e]={...this.rootDoc.paths[e]||{},...t},this}addSchema(e,t){return this.rootDoc.components=this.rootDoc.components||{},this.rootDoc.components.schemas=this.rootDoc.components.schemas||{},this.rootDoc.components.schemas[e]=t,this}addResponse(e,t){return this.rootDoc.components=this.rootDoc.components||{},this.rootDoc.components.responses=this.rootDoc.components.responses||{},this.rootDoc.components.responses[e]=t,this}addParameter(e,t){return this.rootDoc.components=this.rootDoc.components||{},this.rootDoc.components.parameters=this.rootDoc.components.parameters||{},this.rootDoc.components.parameters[e]=t,this}addExample(e,t){return this.rootDoc.components=this.rootDoc.components||{},this.rootDoc.components.examples=this.rootDoc.components.examples||{},this.rootDoc.components.examples[e]=t,this}addRequestBody(e,t){return this.rootDoc.components=this.rootDoc.components||{},this.rootDoc.components.requestBodies=this.rootDoc.components.requestBodies||{},this.rootDoc.components.requestBodies[e]=t,this}addHeader(e,t){return this.rootDoc.components=this.rootDoc.components||{},this.rootDoc.components.headers=this.rootDoc.components.headers||{},this.rootDoc.components.headers[e]=t,this}addSecurityScheme(e,t){return this.rootDoc.components=this.rootDoc.components||{},this.rootDoc.components.securitySchemes=this.rootDoc.components.securitySchemes||{},this.rootDoc.components.securitySchemes[e]=t,this}addLink(e,t){return this.rootDoc.components=this.rootDoc.components||{},this.rootDoc.components.links=this.rootDoc.components.links||{},this.rootDoc.components.links[e]=t,this}addCallback(e,t){return this.rootDoc.components=this.rootDoc.components||{},this.rootDoc.components.callbacks=this.rootDoc.components.callbacks||{},this.rootDoc.components.callbacks[e]=t,this}addServer(e){return this.rootDoc.servers=this.rootDoc.servers||[],this.rootDoc.servers.push(e),this}addTag(e){return this.rootDoc.tags=this.rootDoc.tags||[],this.rootDoc.tags.push(e),this}addExternalDocs(e){return this.rootDoc.externalDocs=e,this}addWebhook(e,t){return this.rootDoc.webhooks??={},this.rootDoc.webhooks[e]=t,this}};function r(t,n){if(!e.a.isValidExtension(n))return t?t[n]:void 0}function i(e){return Object.prototype.hasOwnProperty.call(e,`$ref`)}function a(e){return!Object.prototype.hasOwnProperty.call(e,`$ref`)}var o=e.o({OpenApiBuilder:()=>n,Server:()=>e.t,ServerVariable:()=>e.n,addExtension:()=>e.r,getExtension:()=>e.i,getPath:()=>r,isReferenceObject:()=>i,isSchemaObject:()=>a});exports.OpenApiBuilder=n,exports.Server=e.t,exports.ServerVariable=e.n,exports.addExtension=e.r,exports.getExtension=e.i,exports.getPath=r,exports.isReferenceObject=i,exports.isSchemaObject=a,Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return o}}); //# sourceMappingURL=oas31.js.map