Skip to content

Commit d003748

Browse files
committed
Merge branch 'martinitus-2801-infinite-recursion-with-all-of'
2 parents 353ffae + 3114c10 commit d003748

File tree

7 files changed

+322
-2
lines changed

7 files changed

+322
-2
lines changed

Diff for: springdoc-openapi-starter-common/src/main/java/org/springdoc/core/converters/PolymorphicModelConverter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* * * *
2222
* * *
2323
* *
24-
*
24+
*
2525
*/
2626

2727
package org.springdoc.core.converters;
@@ -128,7 +128,7 @@ public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterato
128128
if(resolvedSchema.get$ref().contains(Components.COMPONENTS_SCHEMAS_REF)) {
129129
String schemaName = resolvedSchema.get$ref().substring(Components.COMPONENTS_SCHEMAS_REF.length());
130130
Schema existingSchema = context.getDefinedModels().get(schemaName);
131-
if (existingSchema != null && existingSchema.getOneOf() != null) {
131+
if (existingSchema != null && (existingSchema.getOneOf() != null || existingSchema.getAllOf() != null)) {
132132
return resolvedSchema;
133133
}
134134
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app13
20+
21+
import org.springdoc.core.properties.SpringDocConfigProperties
22+
import org.springdoc.core.properties.SpringDocConfigProperties.ApiDocs.OpenApiVersion
23+
import org.springframework.boot.autoconfigure.SpringBootApplication
24+
import org.springframework.boot.test.context.SpringBootTest
25+
import org.springframework.context.annotation.Bean
26+
import org.springframework.context.annotation.ComponentScan
27+
import org.springframework.context.annotation.Configuration
28+
import test.org.springdoc.api.AbstractKotlinSpringDocMVCTest
29+
30+
31+
class SpringDocApp13Test : AbstractKotlinSpringDocMVCTest() {
32+
33+
@SpringBootApplication
34+
class DemoApplication {
35+
@Bean
36+
fun springDocConfigProperties():SpringDocConfigProperties{
37+
val x= SpringDocConfigProperties()
38+
x.apiDocs.version = OpenApiVersion.OPENAPI_3_1
39+
return x
40+
}
41+
}
42+
43+
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app13
20+
21+
22+
import io.swagger.v3.oas.annotations.media.Schema
23+
import org.springframework.web.bind.annotation.PostMapping
24+
import org.springframework.web.bind.annotation.RequestBody
25+
import org.springframework.web.bind.annotation.RequestMapping
26+
import org.springframework.web.bind.annotation.RestController
27+
28+
@Schema(description = "Generic description")
29+
data class KeyValue(
30+
val key: String,
31+
val value: String,
32+
)
33+
34+
@Schema
35+
data class SomeDTO(
36+
@Schema(description = "Description A") val fieldA: KeyValue,
37+
@Schema(description = "Description B") val fieldB: KeyValue,
38+
)
39+
40+
41+
42+
@RestController
43+
@RequestMapping("/test")
44+
class TestController {
45+
@PostMapping("/test")
46+
fun create(@RequestBody some: SomeDTO) {
47+
48+
}
49+
}
50+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app14
20+
21+
import org.springframework.boot.autoconfigure.SpringBootApplication
22+
import org.springframework.context.annotation.ComponentScan
23+
import test.org.springdoc.api.AbstractKotlinSpringDocMVCTest
24+
25+
class SpringDocApp14Test : AbstractKotlinSpringDocMVCTest() {
26+
27+
@SpringBootApplication
28+
class DemoApplication
29+
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app14
20+
21+
import io.swagger.v3.oas.annotations.media.Schema
22+
import org.springframework.web.bind.annotation.PostMapping
23+
import org.springframework.web.bind.annotation.RequestBody
24+
import org.springframework.web.bind.annotation.RequestMapping
25+
import org.springframework.web.bind.annotation.RestController
26+
27+
@Schema(description = "Generic description")
28+
data class KeyValue(
29+
val key: String,
30+
val value: String,
31+
)
32+
33+
@Schema
34+
data class SomeDTO(
35+
@Schema(description = "Description A", allOf = [KeyValue::class]) val field_a: KeyValue,
36+
@Schema(description = "Description B", allOf = [KeyValue::class]) val field_b: KeyValue,
37+
)
38+
39+
@RestController
40+
@RequestMapping("/test")
41+
class TestController {
42+
43+
@PostMapping("/test")
44+
fun create(@RequestBody some: SomeDTO) {
45+
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"openapi" : "3.1.0",
3+
"info" : {
4+
"title" : "OpenAPI definition",
5+
"version" : "v0"
6+
},
7+
"servers" : [ {
8+
"url" : "http://localhost",
9+
"description" : "Generated server url"
10+
} ],
11+
"paths" : {
12+
"/test/test" : {
13+
"post" : {
14+
"tags" : [ "test-controller" ],
15+
"operationId" : "create",
16+
"requestBody" : {
17+
"content" : {
18+
"application/json" : {
19+
"schema" : {
20+
"$ref" : "#/components/schemas/SomeDTO"
21+
}
22+
}
23+
},
24+
"required" : true
25+
},
26+
"responses" : {
27+
"200" : {
28+
"description" : "OK"
29+
}
30+
}
31+
}
32+
}
33+
},
34+
"components" : {
35+
"schemas" : {
36+
"KeyValue" : {
37+
"required" : [ "key", "value" ],
38+
"type" : "object",
39+
"description" : "Generic description",
40+
"properties" : {
41+
"key" : {
42+
"type" : "string"
43+
},
44+
"value" : {
45+
"type" : "string"
46+
}
47+
}
48+
},
49+
"SomeDTO" : {
50+
"required": [
51+
"fieldA",
52+
"fieldB"
53+
],
54+
"type": "object",
55+
"properties": {
56+
"fieldA": {
57+
"description": "Description A",
58+
"$ref": "#/components/schemas/KeyValue"
59+
},
60+
"fieldB": {
61+
"description": "Description B",
62+
"$ref": "#/components/schemas/KeyValue"
63+
}
64+
}
65+
}
66+
}
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"openapi": "3.0.1",
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+
"/test/test": {
15+
"post": {
16+
"tags": [
17+
"test-controller"
18+
],
19+
"operationId": "create",
20+
"requestBody": {
21+
"content": {
22+
"application/json": {
23+
"schema": {
24+
"$ref": "#/components/schemas/SomeDTO"
25+
}
26+
}
27+
},
28+
"required": true
29+
},
30+
"responses": {
31+
"200": {
32+
"description": "OK"
33+
}
34+
}
35+
}
36+
}
37+
},
38+
"components": {
39+
"schemas": {
40+
"KeyValue": {
41+
"required": [
42+
"key",
43+
"value"
44+
],
45+
"type": "object",
46+
"description": "Generic description",
47+
"allOf": [
48+
{
49+
"$ref": "#/components/schemas/KeyValue"
50+
},
51+
{
52+
"type": "object",
53+
"properties": {
54+
"key": {
55+
"type": "string"
56+
},
57+
"value": {
58+
"type": "string"
59+
}
60+
}
61+
}
62+
]
63+
},
64+
"SomeDTO": {
65+
"required": [
66+
"field_a",
67+
"field_b"
68+
],
69+
"type": "object",
70+
"properties": {
71+
"field_a": {
72+
"$ref": "#/components/schemas/KeyValue"
73+
},
74+
"field_b": {
75+
"$ref": "#/components/schemas/KeyValue"
76+
}
77+
}
78+
}
79+
}
80+
}
81+
}

0 commit comments

Comments
 (0)