Browse Source

v1.1.7: SwaggerDoc:addSecurityScheme() method

CrazyDoctor 3 weeks ago
parent
commit
6b09531c2a

+ 2 - 0
dist/base/swagger/SwaggerDoc.d.ts

@@ -9,6 +9,7 @@ declare class SwaggerDoc {
     private requestBody?;
     private parameters;
     private responses;
+    private security;
     static get(route: string): SwaggerDoc;
     static post(route: string): SwaggerDoc;
     private constructor();
@@ -18,6 +19,7 @@ declare class SwaggerDoc {
     setRequestBody(requestBody: SwaggerRequestBody): SwaggerDoc;
     addParameter(param: SwaggerParameter): SwaggerDoc;
     addResponse(res: SwaggerResponse): SwaggerDoc;
+    addSecurityScheme(scheme: string): SwaggerDoc;
     toAnnotation(): string;
     private getMethod;
     private deserializeSchema;

+ 11 - 0
dist/base/swagger/SwaggerDoc.js

@@ -12,6 +12,7 @@ class SwaggerDoc {
     constructor(method) {
         this.parameters = [];
         this.responses = [];
+        this.security = [];
         this.method = method;
     }
     setRoute(route) {
@@ -38,6 +39,10 @@ class SwaggerDoc {
         this.responses.push(res);
         return this;
     }
+    addSecurityScheme(scheme) {
+        this.security.push(scheme);
+        return this;
+    }
     toAnnotation() {
         let annotation = '/**\n';
         annotation += ' *\t@swagger\n';
@@ -47,6 +52,12 @@ class SwaggerDoc {
             annotation += ` *\t\t\tsummary: ${this.summary}\n`;
         if (this.description)
             annotation += ` *\t\t\tdescription: ${this.description}\n`;
+        if (this.security.length > 0) {
+            annotation += ' *\t\t\tsecurity:\n';
+            for (const scheme of this.security) {
+                annotation += ` *\t\t\t\t- ${scheme}: []\n`;
+            }
+        }
         if (this.parameters.length > 0) {
             annotation += ' *\t\t\tparameters:\n';
             for (const param of this.parameters) {

File diff suppressed because it is too large
+ 0 - 0
dist/base/swagger/SwaggerDoc.js.map


+ 13 - 0
lib/base/swagger/SwaggerDoc.ts

@@ -12,6 +12,7 @@ class SwaggerDoc {
 	private requestBody?: SwaggerRequestBody;
 	private parameters: SwaggerParameter[] = [];
 	private responses: SwaggerResponse[] = [];
+	private security: string[] = [];
 
 	public static get(route: string): SwaggerDoc {
 		return new SwaggerDoc(HttpMethod.GET).setRoute(route);
@@ -55,6 +56,11 @@ class SwaggerDoc {
 		return this;
 	}
 
+	public addSecurityScheme(scheme: string): SwaggerDoc {
+		this.security.push(scheme);
+		return this;
+	}
+
 	public toAnnotation(): string {
 		let annotation  =   '/**\n';
 		annotation      +=  ' *\t@swagger\n';
@@ -66,6 +72,13 @@ class SwaggerDoc {
         
 		if(this.description)
 			annotation  +=  ` *\t\t\tdescription: ${this.description}\n`;
+
+		if(this.security.length > 0) {
+			annotation	+=	' *\t\t\tsecurity:\n';
+			for(const scheme of this.security) {
+				annotation	+=	` *\t\t\t\t- ${scheme}: []\n`;
+			}
+		}
         
 		if(this.parameters.length > 0) {
 			annotation	+=	' *\t\t\tparameters:\n';

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "org.crazydoctor.expressts",
-  "version": "1.1.6",
+  "version": "1.1.7",
   "devDependencies": {
     "@types/express-session": "^1.17.7",
     "@types/node": "^20.4.9",

Some files were not shown because too many files changed in this diff