Skip to content

Commit 471ebd2

Browse files
frantumadaniel-kmiecik
authored andcommitted
fix: refs #4907 - fix 'openapi.openapi' field processing for 3.1
1 parent a8caa73 commit 471ebd2

File tree

2 files changed

+101
-1
lines changed

2 files changed

+101
-1
lines changed

modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2/Reader.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,13 @@ public OpenAPI read(Class<?> cls,
289289
final javax.ws.rs.Path apiPath = ReflectionUtils.getAnnotation(cls, javax.ws.rs.Path.class);
290290
final boolean openapi31 = Boolean.TRUE.equals(config.isOpenAPI31());
291291

292-
if (openapi31) {
292+
if (
293+
openapi31 &&
294+
(
295+
config.getOpenAPI() == null ||
296+
config.getOpenAPI().getOpenapi() == null ||
297+
config.getOpenAPI().getOpenapi().startsWith("3.0")
298+
) && config.getOpenAPIVersion() == null) {
293299
openAPI.setOpenapi("3.1.0");
294300
}
295301

modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/ReaderTest.java

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5409,4 +5409,98 @@ public void testTicket4878() {
54095409
SerializationMatchers.assertEqualsToYaml31(openAPI, yaml);
54105410
ModelConverters.reset();
54115411
}
5412+
5413+
@Test(description = "Test model resolution for global path parameters with openAPI 3.1")
5414+
public void testTicket4907() {
5415+
ModelConverters.reset();
5416+
5417+
// openAPI31 true and no other config
5418+
SwaggerConfiguration config = new SwaggerConfiguration().openAPI31(true);
5419+
Reader reader = new Reader(config);
5420+
OpenAPI openAPI = reader.read(Ticket4878Resource.class);
5421+
String yaml = "openapi: 3.1.0\n" +
5422+
"paths:\n" +
5423+
" /{globalPathParam}/{localPathParam}:\n" +
5424+
" get:\n" +
5425+
" operationId: getMethod\n" +
5426+
" parameters:\n" +
5427+
" - name: globalPathParam\n" +
5428+
" in: path\n" +
5429+
" required: true\n" +
5430+
" schema:\n" +
5431+
" type: string\n" +
5432+
" $comment: 3.1 property for global path param\n" +
5433+
" - name: localPathParam\n" +
5434+
" in: path\n" +
5435+
" required: true\n" +
5436+
" schema:\n" +
5437+
" type: string\n" +
5438+
" $comment: 3.1 property for local path param\n" +
5439+
" responses:\n" +
5440+
" default:\n" +
5441+
" description: default response\n" +
5442+
" content:\n" +
5443+
" '*/*': {}\n";
5444+
SerializationMatchers.assertEqualsToYaml31(openAPI, yaml);
5445+
5446+
// openAPI31 true and openAPI set
5447+
config.setOpenAPI(new OpenAPI().openapi("3.1.1"));
5448+
reader = new Reader(config);
5449+
openAPI = reader.read(Ticket4878Resource.class);
5450+
yaml = "openapi: 3.1.1\n" +
5451+
"paths:\n" +
5452+
" /{globalPathParam}/{localPathParam}:\n" +
5453+
" get:\n" +
5454+
" operationId: getMethod\n" +
5455+
" parameters:\n" +
5456+
" - name: globalPathParam\n" +
5457+
" in: path\n" +
5458+
" required: true\n" +
5459+
" schema:\n" +
5460+
" type: string\n" +
5461+
" $comment: 3.1 property for global path param\n" +
5462+
" - name: localPathParam\n" +
5463+
" in: path\n" +
5464+
" required: true\n" +
5465+
" schema:\n" +
5466+
" type: string\n" +
5467+
" $comment: 3.1 property for local path param\n" +
5468+
" responses:\n" +
5469+
" default:\n" +
5470+
" description: default response\n" +
5471+
" content:\n" +
5472+
" '*/*': {}\n";
5473+
SerializationMatchers.assertEqualsToYaml31(openAPI, yaml);
5474+
5475+
// openAPI31 true and openAPIVersion set
5476+
config.setOpenAPI(null);
5477+
config.setOpenAPIVersion("3.1.1");
5478+
reader = new Reader(config);
5479+
openAPI = reader.read(Ticket4878Resource.class);
5480+
yaml = "openapi: 3.1.1\n" +
5481+
"paths:\n" +
5482+
" /{globalPathParam}/{localPathParam}:\n" +
5483+
" get:\n" +
5484+
" operationId: getMethod\n" +
5485+
" parameters:\n" +
5486+
" - name: globalPathParam\n" +
5487+
" in: path\n" +
5488+
" required: true\n" +
5489+
" schema:\n" +
5490+
" type: string\n" +
5491+
" $comment: 3.1 property for global path param\n" +
5492+
" - name: localPathParam\n" +
5493+
" in: path\n" +
5494+
" required: true\n" +
5495+
" schema:\n" +
5496+
" type: string\n" +
5497+
" $comment: 3.1 property for local path param\n" +
5498+
" responses:\n" +
5499+
" default:\n" +
5500+
" description: default response\n" +
5501+
" content:\n" +
5502+
" '*/*': {}\n";
5503+
SerializationMatchers.assertEqualsToYaml31(openAPI, yaml);
5504+
ModelConverters.reset();
5505+
}
54125506
}

0 commit comments

Comments
 (0)