Skip to content

Commit

Permalink
Add spring controller datetimeformat annotations (#150)
Browse files Browse the repository at this point in the history
* Add spring ctrl datetimeformat annotations

* Handle required:true in spring ctrl for date + date-time fields

* Handle required:true in spring ctrl for date + date-time fields

Co-authored-by: George Walker <[email protected]>
  • Loading branch information
george-walker and george-walker-zalando authored Oct 3, 2022
1 parent 540afe7 commit 5e83b7b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.cjbooms.fabrikt.model.BodyParameter
import com.cjbooms.fabrikt.model.ControllerType
import com.cjbooms.fabrikt.model.Controllers
import com.cjbooms.fabrikt.model.HeaderParam
import com.cjbooms.fabrikt.model.KotlinTypeInfo
import com.cjbooms.fabrikt.model.PathParam
import com.cjbooms.fabrikt.model.QueryParam
import com.cjbooms.fabrikt.model.RequestParameter
Expand Down Expand Up @@ -167,9 +168,9 @@ class SpringControllerInterfaceGenerator(
if (parameter.defaultValue != null)
it.addMember("defaultValue = %S", parameter.defaultValue)

if ( parameter.type == LocalDate::class.asTypeName() )
if ( parameter.typeInfo is KotlinTypeInfo.Date )
this.addAnnotation( SpringAnnotations.dateTimeFormat( SpringImports.DateTimeFormat.ISO_DATE ) )
else if (parameter.type == OffsetDateTime::class.asTypeName())
else if (parameter.typeInfo is KotlinTypeInfo.DateTime )
this.addAnnotation( SpringAnnotations.dateTimeFormat( SpringImports.DateTimeFormat.ISO_DATE_TIME ) )

this.addAnnotation(it.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ paths:
parameters:
- in: query
name: aDate
required: true
required: false
schema:
type: string
format: date
Expand All @@ -25,4 +25,4 @@ paths:
type: integer
responses:
'204':
description: example
description: example
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ interface ExampleController {
/**
*
*
* @param aDate
* @param bDateTime
* @param cInt
* @param aDate
*/
@RequestMapping(
value = ["/example"],
produces = [],
method = [RequestMethod.GET]
)
fun get(
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) @RequestParam(value = "aDate", required = true)
aDate: LocalDate,
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) @RequestParam(
value = "bDateTime",
required =
true
)
bDateTime: OffsetDateTime,
@RequestParam(value = "cInt", required = true) cInt: Int
@RequestParam(value = "cInt", required = true) cInt: Int,
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) @RequestParam(value = "aDate", required = false)
aDate: LocalDate?
): ResponseEntity<Unit>
}
}

0 comments on commit 5e83b7b

Please sign in to comment.