From 51a400e4ab486a626711d65c62e6d08a9be96612 Mon Sep 17 00:00:00 2001 From: MuaDDuB Date: Tue, 23 Jan 2024 21:48:41 +0100 Subject: [PATCH 1/4] Add support to date and datetime in interface --- src/autoswagger.ts | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/src/autoswagger.ts b/src/autoswagger.ts index 741c610..3c4205f 100644 --- a/src/autoswagger.ts +++ b/src/autoswagger.ts @@ -1257,14 +1257,30 @@ export class AutoSwagger { isArray = true; } let indicator = "type"; - if (!this.standardTypes.includes(type)) { - indicator = "$ref"; - type = "#/components/schemas/" + type; - } let prop = {}; - prop[indicator] = type; - prop["example"] = example; - prop["nullable"] = notRequired; + + if( type.toLowerCase() === "datetime") { + prop[indicator] = 'string'; + prop["format"] = "date-time" + prop["example"] = "2021-03-23T16:13:08.489+01:00" + prop["nullable"] = notRequired; + } + else if( type.toLowerCase() === "date") { + prop[indicator] = 'string'; + prop["format"] = "date" + prop["example"] = "2021-03-23" + prop["nullable"] = notRequired; + } + else { + if (!this.standardTypes.includes(type)) { + indicator = "$ref"; + type = "#/components/schemas/" + type; + } + + prop[indicator] = type; + prop["example"] = example; + prop["nullable"] = notRequired; + } if (isArray) { props[field] = { type: "array", items: prop }; @@ -1403,6 +1419,13 @@ export class AutoSwagger { example = "2021-03-23T16:13:08.489+01:00"; } + if (type === "date") { + indicator = "type"; + type = "string"; + format = "date"; + example = "2021-03-23"; + } + if (field === "email") { indicator = "type"; type = "string"; From f60c735f1cf3adacadf726d15d093cbb95c177c5 Mon Sep 17 00:00:00 2001 From: MuaDDuB Date: Tue, 23 Jan 2024 22:57:41 +0100 Subject: [PATCH 2/4] Allow having multiple export interface in a same file --- src/autoswagger.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/autoswagger.ts b/src/autoswagger.ts index 3c4205f..a6c12b4 100644 --- a/src/autoswagger.ts +++ b/src/autoswagger.ts @@ -1187,8 +1187,7 @@ export class AutoSwagger { const lines = data.split("\n"); lines.forEach((line, index) => { line = line.trim(); - if (line.startsWith("export") && !line.startsWith("export default")) - return; + if ( line.startsWith("//") || line.startsWith("/*") || @@ -1197,11 +1196,13 @@ export class AutoSwagger { return; if ( line.startsWith("interface ") || - line.startsWith("export default interface ") + line.startsWith("export default interface ") || + line.startsWith("export interface ") ) { props = {}; name = line; name = name.replace("export default ", ""); + name = name.replace("export ", ""); name = name.replace("interface ", ""); name = name.replace("{", ""); name = name.trim(); From 6ea44a043fbc27d3dc6e5e68e02293dc5e2f5de2 Mon Sep 17 00:00:00 2001 From: MuaDDuB Date: Tue, 23 Jan 2024 23:20:00 +0100 Subject: [PATCH 3/4] Fix an issue with computed that have the parenthesis at the end of the line --- src/autoswagger.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/autoswagger.ts b/src/autoswagger.ts index a6c12b4..e4ecefe 100644 --- a/src/autoswagger.ts +++ b/src/autoswagger.ts @@ -1369,7 +1369,7 @@ export class AutoSwagger { field = field.replace("()", ""); field = field.replace("get ", ""); - type = type.replace("{", ""); + type = type.replace("{", "").trim(); if (this.options.snakeCase) { field = snakeCase(field); From 5273cf5bed6fcdd9f1563ae076c9f835ba5cd0e2 Mon Sep 17 00:00:00 2001 From: MuaDDuB Date: Tue, 23 Jan 2024 23:33:55 +0100 Subject: [PATCH 4/4] Fix an issue when having a schema as array --- src/autoswagger.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/autoswagger.ts b/src/autoswagger.ts index e4ecefe..32b8f0e 100644 --- a/src/autoswagger.ts +++ b/src/autoswagger.ts @@ -1406,10 +1406,9 @@ export class AutoSwagger { ) { isArray = true; if ( - type.slice(type.length - 2, type.length) === "[]" && - this.standardTypes.includes(type.toLowerCase()) + type.slice(type.length - 2, type.length) === "[]" ) { - type = type.toLowerCase().split("[]")[0]; + type = type.split("[]")[0]; } }