5
5
import io .swagger .v3 .oas .models .PathItem ;
6
6
import io .swagger .v3 .oas .models .callbacks .Callback ;
7
7
import io .swagger .v3 .oas .models .examples .Example ;
8
+ import io .swagger .v3 .oas .models .headers .Header ;
8
9
import io .swagger .v3 .oas .models .media .ArraySchema ;
9
10
import io .swagger .v3 .oas .models .media .ComposedSchema ;
10
11
import io .swagger .v3 .oas .models .media .MediaType ;
13
14
import io .swagger .v3 .oas .models .parameters .Parameter ;
14
15
import io .swagger .v3 .oas .models .parameters .RequestBody ;
15
16
import io .swagger .v3 .oas .models .responses .ApiResponse ;
17
+ import io .swagger .v3 .oas .models .responses .ApiResponses ;
16
18
import io .swagger .v3 .parser .models .RefFormat ;
17
19
import org .slf4j .Logger ;
18
20
import org .slf4j .LoggerFactory ;
@@ -48,6 +50,7 @@ public ResolverFully(boolean aggregateCombinators) {
48
50
private Map <String , Schema > resolvedModels = new HashMap <>();
49
51
private Map <String , Example > examples ;
50
52
private Map <String , RequestBody > requestBodies ;
53
+ private Map <String , Header > headers ;
51
54
52
55
53
56
public void resolveFully (OpenAPI openAPI ) {
@@ -72,6 +75,13 @@ public void resolveFully(OpenAPI openAPI) {
72
75
}
73
76
}
74
77
78
+ if (openAPI .getComponents () != null && openAPI .getComponents ().getHeaders () != null ) {
79
+ headers = openAPI .getComponents ().getHeaders ();
80
+ if (headers == null ) {
81
+ headers = new HashMap <>();
82
+ }
83
+ }
84
+
75
85
if (openAPI .getPaths () != null ) {
76
86
for (String pathname : openAPI .getPaths ().keySet ()) {
77
87
PathItem pathItem = openAPI .getPaths ().get (pathname );
@@ -138,9 +148,10 @@ public void resolvePath(PathItem pathItem){
138
148
}
139
149
}
140
150
// responses
141
- if (op .getResponses () != null ) {
142
- for (String code : op .getResponses ().keySet ()) {
143
- ApiResponse response = op .getResponses ().get (code );
151
+ ApiResponses responses = op .getResponses ();
152
+ if (responses != null ) {
153
+ for (String code : responses .keySet ()) {
154
+ ApiResponse response = responses .get (code );
144
155
if (response .getContent () != null ) {
145
156
Map <String , MediaType > content = response .getContent ();
146
157
for (String mediaType : content .keySet ()){
@@ -155,11 +166,31 @@ public void resolvePath(PathItem pathItem){
155
166
}
156
167
}
157
168
}
169
+ Map <String , Header > headers = response .getHeaders ();
170
+ if (headers != null ) {
171
+ for (Map .Entry <String , Header > header : headers .entrySet ()) {
172
+ Header value = header .getValue ();
173
+ Header resolvedValue = value .get$ref () != null ? resolveHeader (value ) : value ;
174
+ header .setValue (resolvedValue );
175
+ }
176
+ }
158
177
}
159
178
}
160
179
}
161
180
}
162
181
182
+ public Header resolveHeader (Header header ){
183
+ RefFormat refFormat = computeRefFormat (header .get$ref ());
184
+ String $ref = header .get$ref ();
185
+ if (!isAnExternalRefFormat (refFormat )){
186
+ if (headers != null && !headers .isEmpty ()) {
187
+ String referenceKey = computeDefinitionName ($ref );
188
+ return headers .getOrDefault (referenceKey , header );
189
+ }
190
+ }
191
+ return header ;
192
+ }
193
+
163
194
public RequestBody resolveRequestBody (RequestBody requestBody ){
164
195
RefFormat refFormat = computeRefFormat (requestBody .get$ref ());
165
196
String $ref = requestBody .get$ref ();
0 commit comments