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

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

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

+ 1 - 1
package.json

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

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