Skip to content

Commit 7e78f05

Browse files
committed
Testing pattern with specifying Schema in response headers.
Confirm that setting Header annotations specified in the Schema attribute in ApiResponse's headers attribute does not result in errors.
1 parent 679fb4d commit 7e78f05

File tree

3 files changed

+147
-0
lines changed

3 files changed

+147
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * * Copyright 2019-2024 the original author or authors.
6+
* * * *
7+
* * * * Licensed under the Apache License, Version 2.0 (the "License");
8+
* * * * you may not use this file except in compliance with the License.
9+
* * * * You may obtain a copy of the License at
10+
* * * *
11+
* * * * https://www.apache.org/licenses/LICENSE-2.0
12+
* * * *
13+
* * * * Unless required by applicable law or agreed to in writing, software
14+
* * * * distributed under the License is distributed on an "AS IS" BASIS,
15+
* * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* * * * See the License for the specific language governing permissions and
17+
* * * * limitations under the License.
18+
* * *
19+
* *
20+
*
21+
*/
22+
23+
package test.org.springdoc.api.v30.app218;
24+
25+
26+
import io.swagger.v3.oas.annotations.Operation;
27+
import io.swagger.v3.oas.annotations.headers.Header;
28+
import io.swagger.v3.oas.annotations.media.Schema;
29+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
30+
import org.springframework.http.HttpHeaders;
31+
import org.springframework.web.bind.annotation.GetMapping;
32+
import org.springframework.web.bind.annotation.RequestMapping;
33+
import org.springframework.web.bind.annotation.RestController;
34+
35+
import java.net.URI;
36+
37+
38+
@RestController
39+
@RequestMapping("/")
40+
public class HelloController {
41+
42+
@Operation(
43+
summary = "Summary",
44+
description = "This is description.",
45+
tags = {"Sample"},
46+
responses = {
47+
@ApiResponse(
48+
responseCode = "201",
49+
description = "201 (Created)",
50+
headers =
51+
@Header(
52+
name = HttpHeaders.LOCATION,
53+
description = "Sample endpoint",
54+
schema = @Schema(implementation = URI.class)
55+
)
56+
)
57+
}
58+
)
59+
@GetMapping
60+
public String get() {
61+
return "Hello World!";
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
*
3+
* * Copyright 2019-2024 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.v30.app218;
20+
21+
import org.springdoc.core.customizers.SpecPropertiesCustomizer;
22+
import org.springframework.boot.autoconfigure.SpringBootApplication;
23+
import org.springframework.boot.test.context.SpringBootTest;
24+
import test.org.springdoc.api.v30.AbstractSpringDocV30Test;
25+
26+
/**
27+
* <p>
28+
* A test for {@link SpecPropertiesCustomizer}
29+
*/
30+
@SpringBootTest
31+
public class SpringDocApp218Test extends AbstractSpringDocV30Test {
32+
33+
@SpringBootApplication
34+
static class SpringDocTestApp {}
35+
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
"/": {
15+
"get": {
16+
"tags": [
17+
"Sample"
18+
],
19+
"summary": "Summary",
20+
"description": "This is description.",
21+
"operationId": "get",
22+
"responses": {
23+
"201": {
24+
"description": "201 (Created)",
25+
"headers": {
26+
"Location": {
27+
"description": "Sample endpoint",
28+
"style": "simple",
29+
"schema": {
30+
"type": "string",
31+
"format": "uri"
32+
}
33+
}
34+
},
35+
"content": {
36+
"*/*": {
37+
"schema": {
38+
"type": "string"
39+
}
40+
}
41+
}
42+
}
43+
}
44+
}
45+
}
46+
},
47+
"components": {}
48+
}

0 commit comments

Comments
 (0)