Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e99f059

Browse files
committed
Added java.sql.Date as a native primitive type
fixes springfox#1162
1 parent 56463de commit e99f059

6 files changed

Lines changed: 67 additions & 8 deletions

File tree

springfox-schema/src/main/java/springfox/documentation/schema/Types.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright 2015 the original author or authors.
3+
* Copyright 2015-2016 the original author or authors.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -62,6 +62,7 @@ private Types() {
6262
.put(Character.TYPE, "string")
6363

6464
.put(Date.class, "date-time")
65+
.put(java.sql.Date.class, "date-time")
6566
.put(String.class, "string")
6667
.put(Object.class, "object")
6768
.put(Long.class, "long")

springfox-schema/src/test/groovy/springfox/documentation/schema/SimpleTypeSpec.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class SimpleTypeSpec extends SchemaSpecification {
8888
"anObjectDouble" | Double | "java.lang.Double"
8989
"currency" | Currency| "java.util.Currency"
9090
"uuid" | UUID | "java.util.UUID"
91+
"aDate" | Date | "java.util.Date"
92+
"aSqlDate" | java.sql.Date | "java.sql.Date"
9193
}
9294

9395
@Ignore

springfox-schema/src/test/java/springfox/documentation/schema/SimpleType.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright 2015 the original author or authors.
3+
* Copyright 2015-2016 the original author or authors.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -43,6 +43,24 @@ public class SimpleType {
4343
Double anObjectDouble;
4444
Currency currency;
4545
UUID uuid;
46+
Date aDate;
47+
java.sql.Date aSqlDate;
48+
49+
public Date getaDate() {
50+
return aDate;
51+
}
52+
53+
public void setaDate(Date aDate) {
54+
this.aDate = aDate;
55+
}
56+
57+
public java.sql.Date getaSqlDate() {
58+
return aSqlDate;
59+
}
60+
61+
public void setaSqlDate(java.sql.Date aSqlDate) {
62+
this.aSqlDate = aSqlDate;
63+
}
4664

4765
public Byte getAnObjectByte() {
4866
return anObjectByte;

springfox-spring-web/src/main/java/springfox/documentation/spring/web/readers/parameter/ModelAttributeParameterExpander.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright 2015 the original author or authors.
3+
* Copyright 2015-2016 the original author or authors.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -69,8 +69,11 @@ public ModelAttributeParameterExpander(TypeResolver resolver) {
6969
this.resolver = resolver;
7070
}
7171

72-
public void expand(final String parentName, final Class<?> paramType,
73-
final List<Parameter> parameters, DocumentationContext documentationContext) {
72+
public void expand(
73+
final String parentName,
74+
final Class<?> paramType,
75+
final List<Parameter> parameters,
76+
DocumentationContext documentationContext) {
7477

7578
Set<String> beanPropNames = getBeanPropertyNames(paramType);
7679
Iterable<Field> fields = from(getInstanceFields(paramType))
@@ -93,8 +96,12 @@ public void expand(final String parentName, final Class<?> paramType,
9396
String dataTypeName = Optional.fromNullable(typeNameFor(each.getFieldType()))
9497
.or(each.getFieldType().getSimpleName());
9598
LOG.debug("Building parameter for field: {}, with type: ", each, each.getFieldType());
96-
ParameterExpansionContext parameterExpansionContext = new ParameterExpansionContext(dataTypeName, parentName,
97-
each.getField(), documentationContext.getDocumentationType(), new ParameterBuilder());
99+
ParameterExpansionContext parameterExpansionContext = new ParameterExpansionContext(
100+
dataTypeName,
101+
parentName,
102+
each.getField(),
103+
documentationContext.getDocumentationType(),
104+
new ParameterBuilder());
98105
parameters.add(pluginsManager.expandParameter(parameterExpansionContext));
99106
}
100107
}

springfox-spring-web/src/test/java/springfox/documentation/spring/web/dummy/controllers/BugsController.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright 2015 the original author or authors.
3+
* Copyright 2015-2016 the original author or authors.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@
2626
import org.springframework.web.bind.annotation.RequestParam;
2727
import org.springframework.web.bind.annotation.RestController;
2828

29+
import java.sql.Date;
2930
import java.util.Map;
3031

3132
@RestController
@@ -43,4 +44,9 @@ public ResponseEntity<Void> bug1306(@RequestParam Map<String, String> paramMap)
4344
public ResponseEntity<String> bug1209() {
4445
return ResponseEntity.ok("");
4546
}
47+
48+
@RequestMapping(value = "1162", method = RequestMethod.POST)
49+
public ResponseEntity<Date> bug1162() {
50+
return ResponseEntity.ok(new Date(new java.util.Date().getTime()));
51+
}
4652
}

swagger-contract-tests/src/test/resources/contract/swagger2/declaration-bugs-service.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,31 @@
2626
"application/json"
2727
],
2828
"paths": {
29+
"/bugs/1162": {
30+
"post": {
31+
"tags": [
32+
"bugs-controller"
33+
],
34+
"summary": "bug1162",
35+
"operationId": "bug1162UsingPOST_1",
36+
"consumes": [
37+
"application/json"
38+
],
39+
"produces": [
40+
"application/xml",
41+
"application/json"
42+
],
43+
"responses": {
44+
"200": {
45+
"description": "OK",
46+
"schema": {
47+
"type": "string",
48+
"format": "date-time"
49+
}
50+
}
51+
}
52+
}
53+
},
2954
"/bugs/1209": {
3055
"post": {
3156
"tags": [

0 commit comments

Comments
 (0)