Skip to content

Commit f57de36

Browse files
author
m2
committed
add v30 test case
1 parent 9378350 commit f57de36

File tree

9 files changed

+529
-0
lines changed

9 files changed

+529
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package test.org.springdoc.api.v31.app15
2+
3+
import io.swagger.v3.oas.annotations.media.Schema
4+
import org.springframework.web.bind.annotation.GetMapping
5+
import org.springframework.web.bind.annotation.RequestMapping
6+
import org.springframework.web.bind.annotation.RestController
7+
8+
@RestController
9+
@RequestMapping("/api/demo")
10+
class DocumentsApiController {
11+
12+
@GetMapping
13+
suspend fun getDocuments(
14+
request: DemoRequest
15+
): DemoDto = DemoDto(42)
16+
}
17+
18+
data class DemoDto(
19+
var id: Long,
20+
)
21+
22+
/**
23+
field following test cases:
24+
```
25+
| case required | 11true | 10true | 01false | 00false | N1false | N0true |
26+
| :-------------------- | :----- | :----- | :------ | :------ | :----- | :------ |
27+
| schema required value | true | true | false | false | none | none |
28+
| field nullable | true | false | true | false | true | false |
29+
```
30+
*/
31+
class DemoRequest(
32+
33+
@field:Schema(required = true)
34+
val field11true: String?,
35+
36+
@field:Schema(required = true)
37+
val field10true: String,
38+
39+
@field:Schema(requiredMode = Schema.RequiredMode.NOT_REQUIRED)
40+
val field01false: String?,
41+
42+
@field:Schema(requiredMode = Schema.RequiredMode.NOT_REQUIRED)
43+
val field00false: String,
44+
45+
@field:Schema
46+
val fieldN1false: String?,
47+
48+
@field:Schema
49+
val fieldN0true: String,
50+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package test.org.springdoc.api.v31.app15
2+
3+
import org.springframework.boot.autoconfigure.SpringBootApplication
4+
import test.org.springdoc.api.v31.AbstractKotlinSpringDocMVCTest
5+
6+
class SpringDocApp15Test : AbstractKotlinSpringDocMVCTest() {
7+
@SpringBootApplication
8+
class DemoApplication
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package test.org.springdoc.api.v31.app16
2+
3+
import io.swagger.v3.oas.annotations.media.Schema
4+
import org.springframework.web.bind.annotation.GetMapping
5+
import org.springframework.web.bind.annotation.RequestMapping
6+
import org.springframework.web.bind.annotation.RestController
7+
8+
@RestController
9+
@RequestMapping("/api/demo")
10+
class DocumentsApiController {
11+
12+
@GetMapping
13+
suspend fun getDocuments(
14+
request: DemoRequest
15+
): DemoDto = DemoDto(42)
16+
}
17+
18+
data class DemoDto(
19+
var id: Long,
20+
)
21+
22+
/**
23+
field following test cases:
24+
```
25+
| case required | 11true | 10true | 01false | 00false | N1false | N0true |
26+
| :-------------------- | :----- | :----- | :------ | :------ | :----- | :------ |
27+
| schema required value | true | true | false | false | none | none |
28+
| field nullable | true | false | true | false | true | false |
29+
```
30+
*/
31+
class DemoRequest(
32+
33+
@field:Schema(required = true)
34+
val field11true: String?,
35+
36+
@field:Schema(required = true)
37+
val field10true: String,
38+
39+
@field:Schema(requiredMode = Schema.RequiredMode.NOT_REQUIRED)
40+
val field01false: String?,
41+
42+
@field:Schema(requiredMode = Schema.RequiredMode.NOT_REQUIRED)
43+
val field00false: String,
44+
45+
@field:Schema
46+
val fieldN1false: String?,
47+
48+
@field:Schema
49+
val fieldN0true: String,
50+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package test.org.springdoc.api.v31.app16
2+
3+
import org.springdoc.core.utils.Constants.SPRINGDOC_DEFAULT_FLAT_PARAM_OBJECT
4+
import org.springframework.boot.autoconfigure.SpringBootApplication
5+
import org.springframework.test.context.TestPropertySource
6+
import test.org.springdoc.api.v31.AbstractKotlinSpringDocMVCTest
7+
8+
@TestPropertySource(properties = ["$SPRINGDOC_DEFAULT_FLAT_PARAM_OBJECT=true"])
9+
class SpringDocApp16Test : AbstractKotlinSpringDocMVCTest() {
10+
@SpringBootApplication
11+
class DemoApplication
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package test.org.springdoc.api.v31.app17
2+
3+
import io.swagger.v3.oas.annotations.media.ArraySchema
4+
import io.swagger.v3.oas.annotations.media.Schema
5+
import jakarta.validation.Valid
6+
import jakarta.validation.constraints.DecimalMin
7+
import jakarta.validation.constraints.Min
8+
import jakarta.validation.constraints.NotEmpty
9+
import jakarta.validation.constraints.Size
10+
import org.springframework.validation.annotation.Validated
11+
import org.springframework.web.bind.annotation.GetMapping
12+
import org.springframework.web.bind.annotation.RequestMapping
13+
import org.springframework.web.bind.annotation.RestController
14+
15+
@Validated
16+
@RestController
17+
@RequestMapping("/api/demo")
18+
class DocumentsApiController {
19+
20+
@Valid
21+
@GetMapping
22+
suspend fun validOverrideAndOrder(
23+
@Valid request: ChildBar
24+
): DemoDto = DemoDto(42)
25+
}
26+
27+
data class DemoDto(
28+
var id: Long,
29+
)
30+
31+
@Schema(description = "ParentFoo Request")
32+
open class ParentFoo(
33+
@field:NotEmpty // use flat-param-object. to remove or merge annotations by use DelegatingMethodParameterCustomizer
34+
@field:Size(min = 10, max = 20)
35+
@field:ArraySchema(schema = Schema(description = "wrong: list[minItems = 10, maxItems = 20] wrong: string[minLength = 30, maxLength = 40]"))
36+
open var fooList: List<@Size(min = 30, max = 40) String> = listOf()
37+
)
38+
39+
@Schema(description = "ChildBar Request")
40+
data class ChildBar(
41+
@field:Size(min = 11, max = 21) // should override parent
42+
@field:ArraySchema(schema = Schema(description = "expect: list[minItems = 11, maxItems = 21] expect: string[minLength = 31, maxLength = 41]"))
43+
override var fooList: List<@Size(min = 31, max = 41) String>,
44+
45+
@field:Size(min = 12, max = 22) // genericType should work
46+
@field:ArraySchema(schema = Schema(description = "expect: list[minItems = 12, maxItems = 22] expect: string[minLength = 32, maxLength = 42]"))
47+
var barList: List<@Size(min = 32, max = 42) String> = listOf(),
48+
49+
@field:DecimalMin("1") // will be override by min
50+
@field:Min(2)
51+
@field:Schema(description = "expect: minimum = 2")
52+
var validOrder1: Long,
53+
54+
@field:Min(2) // will be override by DecimalMin
55+
@field:DecimalMin("1")
56+
@field:Schema(description = "expect: minimum = 1")
57+
var validOrder2: Long,
58+
) : ParentFoo()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package test.org.springdoc.api.v31.app17
2+
3+
import jakarta.validation.constraints.NotEmpty
4+
import org.junit.jupiter.api.Assertions
5+
import org.springdoc.core.customizers.DelegatingMethodParameterCustomizer
6+
import org.springdoc.core.extractor.DelegatingMethodParameter
7+
import org.springdoc.core.utils.Constants.SPRINGDOC_DEFAULT_FLAT_PARAM_OBJECT
8+
import org.springframework.boot.autoconfigure.SpringBootApplication
9+
import org.springframework.context.annotation.Bean
10+
import org.springframework.core.MethodParameter
11+
import org.springframework.test.context.TestPropertySource
12+
import test.org.springdoc.api.v31.AbstractKotlinSpringDocMVCTest
13+
14+
@TestPropertySource(properties = ["$SPRINGDOC_DEFAULT_FLAT_PARAM_OBJECT=true"])
15+
class SpringDocApp17Test : AbstractKotlinSpringDocMVCTest() {
16+
@SpringBootApplication
17+
class DemoApplication {
18+
19+
@Bean
20+
fun optionalKotlinDelegatingMethodParameterCustomizer(): DelegatingMethodParameterCustomizer {
21+
return object : DelegatingMethodParameterCustomizer {
22+
override fun customizeList(
23+
originalParameter: MethodParameter,
24+
methodParameters: MutableList<MethodParameter>
25+
) {
26+
val fieldNameSet = mutableSetOf<String>()
27+
methodParameters.forEachIndexed { index, it ->
28+
if (it is DelegatingMethodParameter && it.isParameterObject && it.field != null) {
29+
val field = it.field!!
30+
if (fieldNameSet.contains(field.name)) {
31+
val fieldAnnotations = field.annotations
32+
Assertions.assertTrue(fieldAnnotations.any { it is NotEmpty })
33+
// remove parent field
34+
methodParameters.removeAt(index)
35+
} else fieldNameSet.add(field.name)
36+
}
37+
}
38+
if (methodParameters.size > 1) {
39+
methodParameters.sortBy { it.parameterIndex }
40+
}
41+
}
42+
43+
override fun customize(
44+
originalParameter: MethodParameter,
45+
methodParameter: MethodParameter
46+
) {
47+
}
48+
}
49+
}
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{
2+
"openapi": "3.1.0",
3+
"info": {
4+
"title": "OpenAPI definition",
5+
"version": "v0"
6+
},
7+
"servers": [
8+
{
9+
"url": "http://localhost",
10+
"description": "Generated server url"
11+
}
12+
],
13+
"paths": {
14+
"/api/demo": {
15+
"get": {
16+
"tags": [
17+
"documents-api-controller"
18+
],
19+
"operationId": "getDocuments",
20+
"parameters": [
21+
{
22+
"name": "request",
23+
"in": "query",
24+
"required": true,
25+
"schema": {
26+
"$ref": "#/components/schemas/DemoRequest"
27+
}
28+
}
29+
],
30+
"responses": {
31+
"200": {
32+
"description": "OK",
33+
"content": {
34+
"*/*": {
35+
"schema": {
36+
"$ref": "#/components/schemas/DemoDto"
37+
}
38+
}
39+
}
40+
}
41+
}
42+
}
43+
}
44+
},
45+
"components": {
46+
"schemas": {
47+
"DemoRequest": {
48+
"type": "object",
49+
"properties": {
50+
"field11true": {
51+
"type": "string"
52+
},
53+
"field10true": {
54+
"type": "string"
55+
},
56+
"field01false": {
57+
"type": "string"
58+
},
59+
"field00false": {
60+
"type": "string"
61+
},
62+
"fieldN1false": {
63+
"type": "string"
64+
},
65+
"fieldN0true": {
66+
"type": "string"
67+
}
68+
},
69+
"required": [
70+
"field10true",
71+
"field11true",
72+
"fieldN0true"
73+
]
74+
},
75+
"DemoDto": {
76+
"type": "object",
77+
"properties": {
78+
"id": {
79+
"type": "integer",
80+
"format": "int64"
81+
}
82+
},
83+
"required": [
84+
"id"
85+
]
86+
}
87+
}
88+
}
89+
}

0 commit comments

Comments
 (0)