1+ package io .swagger .v3 .core .resolving ;
2+
3+ import com .google .common .collect .ImmutableMap ;
4+ import io .swagger .v3 .core .util .AnnotationsUtils ;
5+ import io .swagger .v3 .oas .annotations .Operation ;
6+ import io .swagger .v3 .oas .annotations .headers .Header ;
7+ import io .swagger .v3 .oas .annotations .responses .ApiResponse ;
8+ import io .swagger .v3 .oas .models .headers .Header .StyleEnum ;
9+ import org .testng .Assert ;
10+ import org .testng .annotations .DataProvider ;
11+ import org .testng .annotations .Test ;
12+
13+ import java .lang .reflect .Method ;
14+ import java .util .Arrays ;
15+ import java .util .Map ;
16+ import java .util .Optional ;
17+
18+ public class AnnotationsUtilsHeadersTest {
19+
20+ private io .swagger .v3 .oas .models .headers .Header header () {
21+ return new io .swagger .v3 .oas .models .headers .Header ().style (StyleEnum .SIMPLE );
22+ }
23+
24+ @ DataProvider
25+ private Object [][] expectedData () {
26+ return new Object [][]{
27+ {"methodOne" , Optional .empty ()},
28+ {"methodTwo" , Optional .empty ()},
29+ {"methodThree" , Optional .empty ()},
30+ {"methodFour" , Optional .of (ImmutableMap .of (
31+ "" , header ().description ("header" ),
32+ "header1" , header (),
33+ "header2" , header ().description ("header 2" ),
34+ "header3" , header ().$ref ("#/components/schemas/header3" )
35+ ))},
36+ };
37+ }
38+
39+ @ Test (dataProvider = "expectedData" )
40+ public void extensionsTest (String methodName ,
41+ Optional <Map <String , io .swagger .v3 .oas .models .headers .Header >> expected )
42+ throws NoSuchMethodException {
43+ final Method method = getClass ().getDeclaredMethod (methodName );
44+ final Header [] headers =
45+ Arrays .stream (method .getAnnotation (Operation .class ).responses ())
46+ .flatMap (response -> Arrays .stream (response .headers ())).toArray (Header []::new );
47+
48+ final Optional <Map <String , io .swagger .v3 .oas .models .headers .Header >> optionalMap =
49+ AnnotationsUtils .getHeaders (headers , null );
50+
51+ Assert .assertEquals (optionalMap , expected );
52+ }
53+
54+ @ Operation (description = "method" )
55+ private void methodOne () {
56+
57+ }
58+
59+ @ Operation (description = "method" , responses = {
60+ @ ApiResponse ()
61+ })
62+ private void methodTwo () {
63+
64+ }
65+
66+ @ Operation (description = "method" , responses = {
67+ @ ApiResponse (headers = {
68+ @ Header (name = "" )
69+ })
70+ })
71+ private void methodThree () {
72+
73+ }
74+
75+ @ Operation (description = "method" , responses = {
76+ @ ApiResponse (headers = {
77+ @ Header (name = "" , description = "header" ),
78+ @ Header (name = "header1" ),
79+ @ Header (name = "header2" , description = "header 2" ),
80+ @ Header (name = "header3" , ref = "#/components/schemas/header3" )
81+ })
82+ })
83+ private void methodFour () {
84+
85+ }
86+ }
0 commit comments