@@ -197,6 +197,7 @@ export function getSchemaForType(
197197 const program = dpgContext . program ;
198198 const { usage } = options ?? { } ;
199199 const type = getEffectiveModelFromType ( program , typeInput ) ;
200+
200201 if ( schemaCache . has ( type ) ) {
201202 return schemaCache . get ( type ) ;
202203 }
@@ -213,7 +214,20 @@ export function getSchemaForType(
213214
214215 if ( type . kind === "ModelProperty" ) {
215216 const typeSchema : Schema = getSchemaForType ( dpgContext , type . type , options ) ;
216- if ( isStringType ( program , type . type ) || isNumericType ( program , type . type ) ) {
217+ const encodeData = getEncode ( program , type ) ;
218+ if ( encodeData && typeSchema . type === SchemaType . DateTime ) {
219+ const propertySchema = { ...typeSchema } ;
220+ switch ( encodeData . encoding ) {
221+ case "rfc1123" :
222+ case "rfc7231" :
223+ ( < any > propertySchema ) . format = "date-time-rfc1123" ;
224+ break ;
225+ default :
226+ break ;
227+ }
228+ schemaCache . set ( type , < Schema > propertySchema ) ;
229+ return propertySchema ;
230+ } else if ( isStringType ( program , type . type ) || isNumericType ( program , type . type ) ) {
217231 // applyIntrinsicDecorators for string and numeric types
218232 // unlike m4, min/max length and pattern, secrets, etc. are not part of the schema
219233 let propertySchema = { ...typeSchema } ;
@@ -395,7 +409,16 @@ function mergeFormatAndEncoding(
395409 case undefined :
396410 return encodeAsFormat ?? encoding ;
397411 case "date-time" :
398- return encoding ;
412+ switch ( encoding ) {
413+ case "rfc3339" :
414+ return "date-time" ;
415+ case "unixTimestamp" :
416+ return "unixtime" ;
417+ case "rfc7231" :
418+ return "date-time-rfc7231" ;
419+ default :
420+ return encoding ;
421+ }
399422 case "duration" :
400423 default :
401424 return encodeAsFormat ?? encoding ;
0 commit comments