Skip to content

Commit b2254b9

Browse files
authored
Normalize headers in components (#22672)
* normalize headers in components * update comment
1 parent f1322a0 commit b2254b9

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ protected void normalize() {
356356
normalizeComponentsSecuritySchemes();
357357
normalizeComponentsSchemas();
358358
normalizeComponentsResponses();
359+
normalizeComponentsHeaders();
359360
}
360361

361362
/**
@@ -558,8 +559,21 @@ protected void normalizeHeaders(Map<String, Header> headers) {
558559

559560
for (String headerKey : headers.keySet()) {
560561
Header h = headers.get(headerKey);
561-
Schema updatedHeader = normalizeSchema(h.getSchema(), new HashSet<>());
562-
h.setSchema(updatedHeader);
562+
if (h.getSchema() != null) { // not a $ref header
563+
// example of header class
564+
// description: null
565+
// required: null
566+
// deprecated: null
567+
// style: null
568+
// explode: null
569+
// schema: null
570+
// examples: null
571+
// example: null
572+
// content: null
573+
// $ref: #/components/headers/Location
574+
Schema updatedHeader = normalizeSchema(h.getSchema(), new HashSet<>());
575+
h.setSchema(updatedHeader);
576+
}
563577
}
564578
}
565579

@@ -638,6 +652,18 @@ protected void normalizeComponentsResponses() {
638652
}
639653
}
640654

655+
/**
656+
* Normalizes schemas in component's headers.
657+
*/
658+
protected void normalizeComponentsHeaders() {
659+
Map<String, Header> headers = openAPI.getComponents().getHeaders();
660+
if (headers == null) {
661+
return;
662+
}
663+
664+
normalizeHeaders(headers);
665+
}
666+
641667
/**
642668
* Auto fix a self referencing schema using any type to replace the self-referencing sub-item.
643669
*

0 commit comments

Comments
 (0)