Repository: RobinTail/express-zod-api (ts)

Issue:
Bug: Cannot set description on `dateIn` and `dateOut` fields
First of all: Great job on this library! It manages to strike an almost perfect balance between being super quick and easy to get started with while also not being too restrictive or opinionated. Kind of like tRPC but more "public-API-friendly".

Anyway, my team and I discovered a small bug in how the OpenAPI schema is being generated:

All fields with the `dateIn` or `dateOut` type don't keep the descriptions assigned using `.describe()`. Instead, they always have the description set to `YYYY-MM-DDTHH:mm:ss.sssZ`. It seems to be caused by [the `depictDateIn` and `depictDateOut` functions](https://github.com/RobinTail/express-zod-api/blob/1ab41c42b6a8ff7a95bc611015e8095130241faf/src/open-api-helpers.ts#L209-L244) not taking into account custom descriptions.

Pull request:
Fix: setting description for `dateIn` and `dateOut`
Fixes #672 

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b0dc9aaa..84e0a806 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,19 @@
 
 ## Version 8
 
+### v8.3.3
+
+- Fixed the bug #672 found and reported by [@shroudedcode](https://github.com/shroudedcode).
+  - Preserving the custom description of `z.dateIn()` and `z.dateOut()` schemas when generating OpenAPI documentation.
+
+```yaml
+# z.dateIn().describe("custom description")
+before:
+  description: YYYY-MM-DDTHH:mm:ss.sssZ
+after:
+  description: custom description
+```
+
 ### v8.3.2
 
 - Fixed the bug #673 found and reported by [@shroudedcode](https://github.com/shroudedcode).
diff --git a/src/open-api-helpers.ts b/src/open-api-helpers.ts
index f877ce47..bb3dffe7 100644
--- a/src/open-api-helpers.ts
+++ b/src/open-api-helpers.ts
@@ -214,11 +214,11 @@ export const depictDateIn: DepictHelper<ZodDateIn> = ({
     throw new OpenAPIError("Please use z.dateOut() for output.");
   }
   return {
+    description: "YYYY-MM-DDTHH:mm:ss.sssZ",
     ...initial,
     type: "string",
     format: "date-time",
     pattern: isoDateRegex.source,
-    description: "YYYY-MM-DDTHH:mm:ss.sssZ",
     externalDocs: {
       url: isoDateDocumentationUrl,
     },
@@ -233,10 +233,10 @@ export const depictDateOut: DepictHelper<ZodDateOut> = ({
     throw new OpenAPIError("Please use z.dateIn() for input.");
   }
   return {
+    description: "YYYY-MM-DDTHH:mm:ss.sssZ",
     ...initial,
     type: "string",
     format: "date-time",
-    description: "YYYY-MM-DDTHH:mm:ss.sssZ",
     externalDocs: {
       url: isoDateDocumentationUrl,
     },


Test patch:
diff --git a/tests/unit/__snapshots__/open-api-helpers.spec.ts.snap b/tests/unit/__snapshots__/open-api-helpers.spec.ts.snap
index 2a267098..f9c39183 100644
--- a/tests/unit/__snapshots__/open-api-helpers.spec.ts.snap
+++ b/tests/unit/__snapshots__/open-api-helpers.spec.ts.snap
@@ -34,7 +34,7 @@ exports[`Open API helpers depictBoolean() should depict ZodBoolean 1`] = `
 
 exports[`Open API helpers depictDateIn should depict ZodDateIn 1`] = `
 {
-  "description": "YYYY-MM-DDTHH:mm:ss.sssZ",
+  "description": "test",
   "externalDocs": {
     "url": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString",
   },
@@ -48,7 +48,7 @@ exports[`Open API helpers depictDateIn should throw when ZodDateIn in response 1
 
 exports[`Open API helpers depictDateOut should depict ZodDateOut 1`] = `
 {
-  "description": "YYYY-MM-DDTHH:mm:ss.sssZ",
+  "description": "test",
   "externalDocs": {
     "url": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString",
   },
diff --git a/tests/unit/__snapshots__/open-api.spec.ts.snap b/tests/unit/__snapshots__/open-api.spec.ts.snap
index dbc8c913..2ed67db7 100644
--- a/tests/unit/__snapshots__/open-api.spec.ts.snap
+++ b/tests/unit/__snapshots__/open-api.spec.ts.snap
@@ -1782,9 +1782,9 @@ paths:
                       name:
                         type: string
                       createdAt:
+                        description: YYYY-MM-DDTHH:mm:ss.sssZ
                         type: string
                         format: date-time
-                        description: YYYY-MM-DDTHH:mm:ss.sssZ
                         externalDocs:
                           url: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
                     required:
@@ -1865,10 +1865,10 @@ paths:
                       type: string
                       minLength: 1
                     birthday:
+                      description: YYYY-MM-DDTHH:mm:ss.sssZ
                       type: string
                       format: date-time
                       pattern: ^\\d{4}-\\d{2}-\\d{2}(T\\d{2}:\\d{2}:\\d{2}(\\.\\d{3})?)?Z?$
-                      description: YYYY-MM-DDTHH:mm:ss.sssZ
                       externalDocs:
                         url: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
                   required:
@@ -2081,9 +2081,9 @@ paths:
                         type: string
                         format: "null"
                       dateOut:
+                        description: YYYY-MM-DDTHH:mm:ss.sssZ
                         type: string
                         format: date-time
-                        description: YYYY-MM-DDTHH:mm:ss.sssZ
                         externalDocs:
                           url: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
                     required:
@@ -2132,10 +2132,10 @@ paths:
                 boolean:
                   type: boolean
                 dateIn:
+                  description: YYYY-MM-DDTHH:mm:ss.sssZ
                   type: string
                   format: date-time
                   pattern: ^\\d{4}-\\d{2}-\\d{2}(T\\d{2}:\\d{2}:\\d{2}(\\.\\d{3})?)?Z?$
-                  description: YYYY-MM-DDTHH:mm:ss.sssZ
                   externalDocs:
                     url: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
               required: