Skip to content

Commit 96d3267

Browse files
authored
Merge pull request #80 from hauner/#78
fixed default handling for non String types
2 parents d433af7 + 31e1ac5 commit 96d3267

2 files changed

Lines changed: 24 additions & 10 deletions

File tree

src/main/groovy/com/github/hauner/openapi/spring/writer/MethodWriter.groovy

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,12 @@ class MethodWriter {
147147
ps.join (', ')
148148
}
149149

150-
private String quote (String content) {
151-
'"' + content + '"'
150+
private String getDefault (Parameter parameter) {
151+
quote(parameter.constraints.default as String)
152152
}
153153

154-
private def getDefault(Parameter parameter) {
155-
def value = parameter.constraints.default
156-
if (value instanceof String) {
157-
quote(value)
158-
} else {
159-
value
160-
}
154+
private String quote (String content) {
155+
'"' + content + '"'
161156
}
162157

163158
}

src/test/groovy/com/github/hauner/openapi/spring/writer/MethodWriterSpec.groovy

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ class MethodWriterSpec extends Specification {
389389
"""
390390
}
391391
392-
void "writes simple (optional) parameter with default value" () {
392+
void "writes simple (optional) parameter with string default value" () {
393393
def endpoint = new Endpoint (path: '/foo', method: HttpMethod.GET, responses: [
394394
'204': [new Response (responseType: new NoneDataType())]
395395
], parameters: [
@@ -408,6 +408,25 @@ class MethodWriterSpec extends Specification {
408408
"""
409409
}
410410
411+
void "writes simple (optional) parameter with number default value" () {
412+
def endpoint = new Endpoint (path: '/foo', method: HttpMethod.GET, responses: [
413+
'204': [new Response (responseType: new NoneDataType())]
414+
], parameters: [
415+
new QueryParameter(name: 'foo', required: false,
416+
dataType: new LongDataType (
417+
constraints: new DataTypeConstraints (defaultValue: 5)))
418+
])
419+
420+
when:
421+
writer.write (target, endpoint)
422+
423+
then:
424+
target.toString () == """\
425+
@GetMapping(path = "${endpoint.path}")
426+
ResponseEntity<Void> getFoo(@RequestParam(name = "foo", required = false, defaultValue = "5") Long foo);
427+
"""
428+
}
429+
411430
void "writes mapping annotation with multiple result content types" () {
412431
def endpoint = new Endpoint (path: '/foo', method: HttpMethod.GET, responses: [
413432
'200' : [

0 commit comments

Comments
 (0)