Skip to content

Commit 131f44d

Browse files
committed
remove parameter duplication
1 parent 1120338 commit 131f44d

5 files changed

Lines changed: 79 additions & 132 deletions

File tree

src/main/groovy/com/github/hauner/openapi/spring/model/parameters/CookieParameter.groovy

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,59 +16,25 @@
1616

1717
package com.github.hauner.openapi.spring.model.parameters
1818

19-
import com.github.hauner.openapi.spring.model.datatypes.DataType
20-
2119
/**
2220
* OpenAPI cookie parameter.
2321
*
2422
* @author Martin Hauner
2523
*/
2624
class CookieParameter extends Parameter {
27-
String name
28-
boolean required
29-
DataType dataType
3025

3126
String getAnnotationName () {
3227
"CookieValue"
3328
}
3429

35-
String getAnnotationWithPackage () {
36-
"org.springframework.web.bind.annotation.${annotationName}"
37-
}
38-
39-
String getAnnotation () {
40-
"@${annotationName}"
41-
}
42-
43-
Set<String> getDataTypeImports () {
44-
dataType.imports
45-
}
46-
47-
/**
48-
* Is the parameter required?
49-
*
50-
* @return true if the parameter is required, otherwise false.
51-
*/
52-
boolean isRequired () {
53-
required
54-
}
55-
5630
ParameterConstraints getConstraints() {
5731
null
5832
}
5933

60-
/**
61-
* Create annotation?
62-
*/
6334
boolean withAnnotation () {
6435
true
6536
}
6637

67-
/**
68-
* Create annotation with parameters?
69-
*
70-
* @return true if the annotation should have parameters, false otherwise
71-
*/
7238
boolean withParameters () {
7339
true
7440
}

src/main/groovy/com/github/hauner/openapi/spring/model/parameters/HeaderParameter.groovy

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,59 +16,25 @@
1616

1717
package com.github.hauner.openapi.spring.model.parameters
1818

19-
import com.github.hauner.openapi.spring.model.datatypes.DataType
20-
2119
/**
2220
* OpenAPI header parameter.
2321
*
2422
* @author Martin Hauner
2523
*/
2624
class HeaderParameter extends Parameter {
27-
String name
28-
boolean required
29-
DataType dataType
3025

3126
String getAnnotationName () {
3227
"RequestHeader"
3328
}
3429

35-
String getAnnotationWithPackage () {
36-
"org.springframework.web.bind.annotation.${annotationName}"
37-
}
38-
39-
String getAnnotation () {
40-
"@${annotationName}"
41-
}
42-
43-
Set<String> getDataTypeImports () {
44-
dataType.imports
45-
}
46-
47-
/**
48-
* Is the parameter required?
49-
*
50-
* @return true if the parameter is required, otherwise false.
51-
*/
52-
boolean isRequired () {
53-
required
54-
}
55-
5630
ParameterConstraints getConstraints() {
5731
null
5832
}
5933

60-
/**
61-
* Create annotation?
62-
*/
6334
boolean withAnnotation () {
6435
true
6536
}
6637

67-
/**
68-
* Create annotation with parameters?
69-
*
70-
* @return true if the annotation should have parameters, false otherwise
71-
*/
7238
boolean withParameters () {
7339
true
7440
}

src/main/groovy/com/github/hauner/openapi/spring/model/parameters/Parameter.groovy

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,84 @@
1616

1717
package com.github.hauner.openapi.spring.model.parameters
1818

19+
import com.github.hauner.openapi.spring.model.datatypes.DataType
20+
1921
/**
2022
* Parameter description of an OpenAPI parameter.
2123
*
2224
* @author Martin Hauner
2325
*/
24-
class Parameter {
26+
abstract class Parameter {
27+
protected String name
28+
protected boolean required
29+
protected DataType dataType
30+
31+
/**
32+
* The plain name of the annotation for this parameter (ie. without the @). Possible results
33+
* are "RequestParam", "PathVariable", "CookieValue" or "RequestHeader".
34+
*
35+
* @return the name of the annotation
36+
*/
37+
abstract String getAnnotationName ()
38+
39+
/**
40+
* The fully qualified class name of the annotation.
41+
*
42+
* @return the fully qualified class name of the annotation
43+
*/
44+
String getAnnotationWithPackage () {
45+
"org.springframework.web.bind.annotation.${annotationName}"
46+
}
47+
48+
/**
49+
* The full annotation name with a leading @.
50+
*
51+
* @return the full annotation name with a leading @
52+
*/
53+
String getAnnotation () {
54+
"@${annotationName}"
55+
}
56+
57+
/**
58+
* The imports required for the parameter data type.
59+
*
60+
* @return the imports of the parameter type.
61+
*/
62+
Set<String> getDataTypeImports () {
63+
dataType.imports
64+
}
65+
66+
/**
67+
* Provides the parameters constraint details, if any.
68+
*
69+
* @return the constraint details or null if the parameter has no constraints
70+
*/
71+
ParameterConstraints getConstraints () {
72+
null
73+
}
74+
75+
/**
76+
* Required or optional parameter?
77+
*
78+
* @return true if required, false otherwise
79+
*/
80+
boolean isRequired () {
81+
required
82+
}
83+
84+
/**
85+
* Create annotation? Some parameters should not have a parameter annotation.
86+
*
87+
* @return true if the parameter should have an annotation, else false
88+
*/
89+
abstract boolean withAnnotation ()
90+
91+
/**
92+
* Create annotation with parameters? Some parameters should have a parameter annotation but
93+
* without any parameters to the annotation.
94+
*
95+
* @return true if the annotation itself should have parameters, false otherwise
96+
*/
97+
abstract boolean withParameters ()
2598

2699
}

src/main/groovy/com/github/hauner/openapi/spring/model/parameters/PathParameter.groovy

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,59 +16,25 @@
1616

1717
package com.github.hauner.openapi.spring.model.parameters
1818

19-
import com.github.hauner.openapi.spring.model.datatypes.DataType
20-
2119
/**
2220
* OpenAPI path parameter.
2321
*
2422
* @author Martin Hauner
2523
*/
2624
class PathParameter extends Parameter {
27-
String name
28-
boolean required
29-
DataType dataType
3025

3126
String getAnnotationName () {
3227
"PathVariable"
3328
}
3429

35-
String getAnnotationWithPackage () {
36-
"org.springframework.web.bind.annotation.${annotationName}"
37-
}
38-
39-
String getAnnotation () {
40-
"@${annotationName}"
41-
}
42-
43-
Set<String> getDataTypeImports () {
44-
dataType.imports
45-
}
46-
47-
/**
48-
* Is the parameter required?
49-
*
50-
* @return true if the parameter is required, otherwise false.
51-
*/
52-
boolean isRequired () {
53-
required
54-
}
55-
5630
ParameterConstraints getConstraints() {
5731
null
5832
}
5933

60-
/**
61-
* Create annotation?
62-
*/
6334
boolean withAnnotation () {
6435
true
6536
}
6637

67-
/**
68-
* Create annotation with parameters?
69-
*
70-
* @return true if the annotation should have parameters, false otherwise
71-
*/
7238
boolean withParameters () {
7339
true
7440
}

src/main/groovy/com/github/hauner/openapi/spring/model/parameters/QueryParameter.groovy

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.github.hauner.openapi.spring.model.parameters
1818

19-
import com.github.hauner.openapi.spring.model.datatypes.DataType
2019
import com.github.hauner.openapi.spring.model.datatypes.MapDataType
2120
import com.github.hauner.openapi.spring.model.datatypes.MappedDataType
2221
import com.github.hauner.openapi.spring.model.datatypes.ObjectDataType
@@ -27,46 +26,26 @@ import com.github.hauner.openapi.spring.model.datatypes.ObjectDataType
2726
* @author Martin Hauner
2827
*/
2928
class QueryParameter extends Parameter {
30-
String name
31-
boolean required
32-
DataType dataType
3329

3430
String getAnnotationName () {
3531
"RequestParam"
3632
}
3733

38-
String getAnnotationWithPackage () {
39-
"org.springframework.web.bind.annotation.${annotationName}"
40-
}
41-
42-
String getAnnotation () {
43-
"@${annotationName}"
44-
}
45-
46-
Set<String> getDataTypeImports () {
47-
dataType.imports
48-
}
49-
50-
/**
51-
* Is the parameter required?
52-
*
53-
* @return true if the parameter is required, otherwise false.
54-
*/
5534
boolean isRequired () {
5635
if (dataType instanceof MapDataType) {
5736
return true
5837
}
5938

60-
required
39+
this.@required
6140
}
6241

6342
ParameterConstraints getConstraints() {
6443
new ParameterConstraints(constraints: dataType.constraints)
6544
}
6645

6746
/**
68-
* Create annotation? If the query parameter is mapped to a pojo object it should not have a
69-
* {@code @RequestParam} annotation.
47+
* If the query parameter is mapped to a pojo object it should not have a {@code @RequestParam}
48+
* annotation.
7049
*/
7150
boolean withAnnotation () {
7251
! (
@@ -76,12 +55,9 @@ class QueryParameter extends Parameter {
7655
}
7756

7857
/**
79-
* todo this is not right.
80-
*
81-
* Create annotation with parameters? If the query parameter is mapped to a pojo object it
82-
* should not have any parameters.
58+
* todo validate.
8359
*
84-
* @return true if the annotation should have parameters, false otherwise
60+
* If the query parameter is mapped to a pojo object it should not have any parameters.
8561
*/
8662
boolean withParameters () {
8763
! (dataType instanceof ObjectDataType)

0 commit comments

Comments
 (0)