Skip to content

Commit 9cd52d2

Browse files
add comments
1 parent 50098e5 commit 9cd52d2

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tools/cli/internal/openapi/sunset/sunset.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@ func teamName(op *openapi3.Operation) string {
8282
return ""
8383
}
8484

85+
// successResponseExtensions searches through a map of response objects for successful HTTP status
86+
// codes (200, 201, 202, 204) and returns the extensions from the content of the first successful
87+
// response found.
88+
//
89+
// The function prioritizes responses in the following order: 200, 201, 202, 204. For each found
90+
// response, it extracts extensions from its content using the contentExtensions helper function.
91+
//
92+
// Parameters:
93+
// - responsesMap: A map of HTTP status codes to OpenAPI response objects
94+
//
95+
// Returns:
96+
// - A map of extension names to their values from the first successful response content,
97+
// or nil if no successful responses are found or if none contain relevant extensions
8598
func successResponseExtensions(responsesMap map[string]*openapi3.ResponseRef) map[string]any {
8699
if val, ok := responsesMap["200"]; ok {
87100
return contentExtensions(val.Value.Content)
@@ -99,6 +112,19 @@ func successResponseExtensions(responsesMap map[string]*openapi3.ResponseRef) ma
99112
return nil
100113
}
101114

115+
// contentExtensions extracts extensions from OpenAPI content objects, prioritizing content entries
116+
// with the oldest date in their keys.
117+
//
118+
// The function sorts content keys by date (in YYYY-MM-DD format) if present, with older dates taking
119+
// precedence. If multiple keys contain dates, it selects the entry with the earliest date. If no dates
120+
// are found, it selects the first content entry that would sort before entries with dates.
121+
//
122+
// Parameters:
123+
// - content: An OpenAPI content map with media types as keys and schema objects as values
124+
//
125+
// Returns:
126+
// - A map of extension names to their values from the selected content entry,
127+
// or nil if the content map is empty or the selected entry has no extensions
102128
func contentExtensions(content openapi3.Content) map[string]any {
103129
keysContent := slices.Collect(maps.Keys(content))
104130
// Regex to find a date in YYYY-MM-DD format.

0 commit comments

Comments
 (0)