openapi3-ts
Version:
TS Model & utils for OpenAPI 3.x specification.
3 lines (2 loc) • 4.3 kB
JavaScript
"use strict";const a=require("yaml"),r=require("./server-DVBno7Ee.js");function p(e){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const s=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(o,t,s.get?s:{enumerable:!0,get:()=>e[t]})}}return o.default=e,Object.freeze(o)}const m=p(a);class n{static create(o){return new n(o)}constructor(o){this.rootDoc=o||{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(o,t){return JSON.stringify(this.rootDoc,o,t)}getSpecAsYaml(o,t){return m.stringify(this.rootDoc,o,t)}static isValidOpenApiVersion(o){o=o||"";const t=/(\d+)\.(\d+).(\d+)/.exec(o);return!!(t&&parseInt(t[1],10)>=3)}addOpenApiVersion(o){if(!n.isValidOpenApiVersion(o))throw new Error("Invalid OpenApi version: "+o+". Follow convention: 3.x.y");return this.rootDoc.openapi=o,this}addInfo(o){return this.rootDoc.info=o,this}addContact(o){return this.rootDoc.info.contact=o,this}addLicense(o){return this.rootDoc.info.license=o,this}addTitle(o){return this.rootDoc.info.title=o,this}addDescription(o){return this.rootDoc.info.description=o,this}addTermsOfService(o){return this.rootDoc.info.termsOfService=o,this}addVersion(o){return this.rootDoc.info.version=o,this}addPath(o,t){return this.rootDoc.paths=this.rootDoc.paths||{},this.rootDoc.paths[o]={...this.rootDoc.paths[o]||{},...t},this}addSchema(o,t){return this.rootDoc.components=this.rootDoc.components||{},this.rootDoc.components.schemas=this.rootDoc.components.schemas||{},this.rootDoc.components.schemas[o]=t,this}addResponse(o,t){return this.rootDoc.components=this.rootDoc.components||{},this.rootDoc.components.responses=this.rootDoc.components.responses||{},this.rootDoc.components.responses[o]=t,this}addParameter(o,t){return this.rootDoc.components=this.rootDoc.components||{},this.rootDoc.components.parameters=this.rootDoc.components.parameters||{},this.rootDoc.components.parameters[o]=t,this}addExample(o,t){return this.rootDoc.components=this.rootDoc.components||{},this.rootDoc.components.examples=this.rootDoc.components.examples||{},this.rootDoc.components.examples[o]=t,this}addRequestBody(o,t){return this.rootDoc.components=this.rootDoc.components||{},this.rootDoc.components.requestBodies=this.rootDoc.components.requestBodies||{},this.rootDoc.components.requestBodies[o]=t,this}addHeader(o,t){return this.rootDoc.components=this.rootDoc.components||{},this.rootDoc.components.headers=this.rootDoc.components.headers||{},this.rootDoc.components.headers[o]=t,this}addSecurityScheme(o,t){return this.rootDoc.components=this.rootDoc.components||{},this.rootDoc.components.securitySchemes=this.rootDoc.components.securitySchemes||{},this.rootDoc.components.securitySchemes[o]=t,this}addLink(o,t){return this.rootDoc.components=this.rootDoc.components||{},this.rootDoc.components.links=this.rootDoc.components.links||{},this.rootDoc.components.links[o]=t,this}addCallback(o,t){return this.rootDoc.components=this.rootDoc.components||{},this.rootDoc.components.callbacks=this.rootDoc.components.callbacks||{},this.rootDoc.components.callbacks[o]=t,this}addServer(o){return this.rootDoc.servers=this.rootDoc.servers||[],this.rootDoc.servers.push(o),this}addTag(o){return this.rootDoc.tags=this.rootDoc.tags||[],this.rootDoc.tags.push(o),this}addExternalDocs(o){return this.rootDoc.externalDocs=o,this}addWebhook(o,t){var s;return(s=this.rootDoc).webhooks??(s.webhooks={}),this.rootDoc.webhooks[o]=t,this}}function c(e,o){if(!r.SpecificationExtension.isValidExtension(o))return e?e[o]:void 0}function i(e){return Object.prototype.hasOwnProperty.call(e,"$ref")}function h(e){return!Object.prototype.hasOwnProperty.call(e,"$ref")}const d=Object.freeze(Object.defineProperty({__proto__:null,OpenApiBuilder:n,Server:r.Server,ServerVariable:r.ServerVariable,addExtension:r.addExtension,getExtension:r.getExtension,getPath:c,isReferenceObject:i,isSchemaObject:h},Symbol.toStringTag,{value:"Module"}));exports.OpenApiBuilder=n;exports.getPath=c;exports.isReferenceObject=i;exports.isSchemaObject=h;exports.oas31=d;
//# sourceMappingURL=oas31-Bx381qKf.js.map