Skip to content

Commit ee61a6e

Browse files
committed
annotate mapped query parameter if the source schema is a simple data type, resolves openapi-processor/openapi-processor-core#53
1 parent 1c2e9cd commit ee61a6e

7 files changed

Lines changed: 58 additions & 2 deletions

File tree

src/main/kotlin/io/openapiprocessor/spring/model/parameters/QueryParameter.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ class QueryParameter(
3737
return false
3838
}
3939

40-
// usually a pojo....
40+
// Mapped should NOT be annotated if it was object schema
41+
// Mapped should be annotated if it was a simple schema
4142
if (dataType is MappedDataType) {
42-
return false
43+
return dataType.simpleDataType
4344
}
4445

4546
return true

src/testInt/groovy/com/github/hauner/openapi/processor/spring/TestSets.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class TestSets {
2323
'params-complex-data-types',
2424
'params-pageable-mapping',
2525
'params-path-simple-data-types',
26+
'params-query-annotate-simple-mapping',
2627
'params-request-body',
2728
'params-request-body-multipart-mapping',
2829
'params-simple-data-types'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
items:
2+
- generated/api/Api.java
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* DO NOT MODIFY - this class was auto generated by openapi-processor-spring
3+
*
4+
* test
5+
* time
6+
* https://docs.openapiprocessor.io/spring
7+
*/
8+
9+
package generated.api;
10+
11+
import java.util.UUID;
12+
import org.springframework.web.bind.annotation.GetMapping;
13+
import org.springframework.web.bind.annotation.RequestParam;
14+
15+
public interface Api {
16+
17+
@GetMapping(path = "/foo")
18+
void getFoo(@RequestParam(name = "id") UUID id);
19+
20+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
items:
2+
- inputs/openapi.yaml
3+
- inputs/mapping.yaml
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
openapi-processor-mapping: v2
2+
3+
options:
4+
package-name: generated
5+
6+
map:
7+
types:
8+
- type: string:uuid => java.util.UUID
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
openapi: 3.0.2
2+
info:
3+
title: test simple data type mapping
4+
version: 1.0.0
5+
6+
paths:
7+
8+
/foo:
9+
get:
10+
parameters:
11+
- name: id
12+
description: mapped to java UUID
13+
in: query
14+
required: true
15+
schema:
16+
type: string
17+
format: uuid
18+
responses:
19+
'204':
20+
description: empty
21+

0 commit comments

Comments
 (0)