Skip to content

Commit 5c4fae9

Browse files
CLOUDP-292068: Remove x-xgen-IPA-exception from version split OASes (#351)
1 parent c86a5cf commit 5c4fae9

File tree

4 files changed

+377
-5
lines changed

4 files changed

+377
-5
lines changed

tools/cli/internal/openapi/filter/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The Atlas Admin API OpenAPI specifications are used not only to document REST en
88
- Filtering per version, so that only the endpoints that are available in that version are shown.
99
## What filters are available?
1010
### List of filters
11-
[ExtensionFilter is a filter that updates the x-sunset and x-xgen-version extensions to a date string](../internal/openapi/filter/extension.go?plain=1#L24)
11+
[ExtensionFilter is a filter that deletes the x-xgen-ipa-exception extensions, updates the x-sunset and x-xgen-version](../internal/openapi/filter/extension.go?plain=1#L24)
1212
[HiddenEnvsFilter is a filter that removes paths, operations,](../internal/openapi/filter/hidden_envs.go?plain=1#L28)
1313
[InfoFilter is a filter that modifies the Info object in the OpenAPI spec.](../internal/openapi/filter/info.go?plain=1#L23)
1414
[OperationsFilter is a filter that removes the x-xgen-owner-team extension from operations](../internal/openapi/filter/operations.go?plain=1#L20)

tools/cli/internal/openapi/filter/extension.go

Lines changed: 117 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ type ExtensionFilter struct {
3131
}
3232

3333
const (
34-
sunsetExtension = "x-sunset"
35-
xGenExtension = "x-xgen-version"
36-
format = "2006-01-02T15:04:05Z07:00"
34+
sunsetExtension = "x-sunset"
35+
xGenExtension = "x-xgen-version"
36+
ipaExceptionExtension = "x-xgen-IPA-exception"
37+
format = "2006-01-02T15:04:05Z07:00"
3738
)
3839

3940
func (f *ExtensionFilter) Apply() error {
@@ -42,27 +43,38 @@ func (f *ExtensionFilter) Apply() error {
4243
continue
4344
}
4445
updateExtensionToDateString(pathItem.Extensions)
46+
deleteIpaExceptionExtension(pathItem.Extensions)
4547

4648
for _, operation := range pathItem.Operations() {
4749
if operation == nil {
4850
continue
4951
}
5052

5153
updateExtensionToDateString(operation.Extensions)
54+
deleteIpaExceptionExtension(operation.Extensions)
55+
56+
if operation.Parameters != nil {
57+
updateExtensionsForOperationParameters(operation.Parameters)
58+
}
59+
60+
updateExtensionsForRequestBody(operation.RequestBody)
5261

5362
latestVersionMatch := apiversion.FindLatestContentVersionMatched(operation, f.metadata.targetVersion)
63+
5464
for _, response := range operation.Responses.Map() {
5565
if response == nil {
5666
continue
5767
}
5868

5969
updateExtensionToDateString(response.Extensions)
70+
deleteIpaExceptionExtension(response.Extensions)
6071

6172
if response.Value == nil {
6273
continue
6374
}
6475

6576
updateExtensionToDateString(response.Value.Extensions)
77+
deleteIpaExceptionExtension(response.Value.Extensions)
6678

6779
if response.Value.Content == nil {
6880
continue
@@ -80,9 +92,111 @@ func (f *ExtensionFilter) Apply() error {
8092
f.deleteSunsetIfDeprecatedByHiddenVersions(latestVersionMatch, request.Value.Content)
8193
}
8294
}
95+
if f.oas.Tags != nil {
96+
updateExtensionsForTags(&f.oas.Tags)
97+
}
98+
if f.oas.Components != nil {
99+
updateExtensionsForComponents(f.oas.Components)
100+
}
83101
return nil
84102
}
85103

104+
func updateExtensionsForRequestBody(requestBody *openapi3.RequestBodyRef) {
105+
if requestBody == nil {
106+
return
107+
}
108+
deleteIpaExceptionExtension(requestBody.Extensions)
109+
_, contentsInVersion := getVersionsInContentType(requestBody.Value.Content)
110+
for _, content := range contentsInVersion {
111+
deleteIpaExceptionExtension(content.Extensions)
112+
updateExtensionsForSchema(content.Schema)
113+
}
114+
}
115+
116+
func updateExtensionsForOperationParameters(parameters openapi3.Parameters) {
117+
for _, parameter := range parameters {
118+
if parameter.Value == nil || parameter.Value.Schema == nil {
119+
continue
120+
}
121+
deleteIpaExceptionExtension(parameter.Value.Schema.Extensions)
122+
if parameter.Value.Schema.Value == nil {
123+
continue
124+
}
125+
deleteIpaExceptionExtension(parameter.Value.Schema.Value.Extensions)
126+
}
127+
}
128+
129+
func updateExtensionsForComponents(components *openapi3.Components) {
130+
for _, schema := range components.Schemas {
131+
updateExtensionsForSchema(schema)
132+
}
133+
for _, parameter := range components.Parameters {
134+
if parameter != nil {
135+
deleteIpaExceptionExtension(parameter.Extensions)
136+
}
137+
}
138+
}
139+
140+
func updateExtensionsForTags(tags *openapi3.Tags) {
141+
for _, tag := range *tags {
142+
if tag != nil {
143+
deleteIpaExceptionExtension(tag.Extensions)
144+
}
145+
}
146+
}
147+
148+
func updateExtensionsForSchema(schema *openapi3.SchemaRef) {
149+
if schema != nil {
150+
deleteIpaExceptionExtension(schema.Extensions)
151+
}
152+
if schema.Value != nil {
153+
deleteIpaExceptionExtension(schema.Value.Extensions)
154+
for _, allOf := range schema.Value.AllOf {
155+
if allOf.Value == nil {
156+
continue
157+
}
158+
for _, property := range allOf.Value.Properties {
159+
if property.Value != nil {
160+
deleteIpaExceptionExtension(property.Value.Extensions)
161+
}
162+
}
163+
}
164+
for _, anyOf := range schema.Value.AnyOf {
165+
if anyOf.Value == nil {
166+
continue
167+
}
168+
for _, property := range anyOf.Value.Properties {
169+
if property.Value != nil {
170+
deleteIpaExceptionExtension(property.Value.Extensions)
171+
}
172+
}
173+
}
174+
for _, oneOf := range schema.Value.OneOf {
175+
if oneOf.Value == nil {
176+
continue
177+
}
178+
for _, property := range oneOf.Value.Properties {
179+
if property.Value != nil {
180+
deleteIpaExceptionExtension(property.Value.Extensions)
181+
}
182+
}
183+
}
184+
for _, property := range schema.Value.Properties {
185+
if property.Value != nil {
186+
deleteIpaExceptionExtension(property.Value.Extensions)
187+
}
188+
}
189+
}
190+
}
191+
192+
func deleteIpaExceptionExtension(extensions map[string]any) {
193+
if extensions == nil || extensions[ipaExceptionExtension] == nil {
194+
return
195+
}
196+
197+
delete(extensions, ipaExceptionExtension)
198+
}
199+
86200
func updateExtensionToDateString(extensions map[string]any) {
87201
if extensions == nil {
88202
return

0 commit comments

Comments
 (0)