Skip to content

Commit 3c1d815

Browse files
tools/importer-rest-api-specs: adding a workaround covering Azure/azure-rest-api-specs#27351
1 parent 7744d5d commit 3c1d815

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package dataworkarounds
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/hashicorp/go-azure-helpers/lang/pointer"
7+
"github.com/hashicorp/pandora/tools/importer-rest-api-specs/models"
8+
)
9+
10+
var _ workaround = workaroundBotService27351{}
11+
12+
type workaroundBotService27351 struct {
13+
}
14+
15+
func (workaroundBotService27351) IsApplicable(apiDefinition *models.AzureApiDefinition) bool {
16+
// This workaround fixes an issue where the BotService Channel URI is defined using two subtly different Resource IDs.
17+
// Fix: https://github.com/Azure/azure-rest-api-specs/pull/27351
18+
//
19+
// The DELETE and GET define the Uri Parameter `channelName` as a String - whereas the PATCH and POST define it as
20+
// a Constant.
21+
// The result of this is that whilst we switch out the Resource ID for a Common ID, this inconsistency means we end up
22+
// with 2 different Resource IDs in the output, the Common ID (`BotServiceChannelId`) using a Constant Segment and another
23+
// Resource ID (`ChannelId`) using a String segment.
24+
//
25+
// As such this workaround fixes this issue by normalizing the resulting output - since these are the same endpoint/should
26+
// support the same values for this URI Segment.
27+
serviceMatches := apiDefinition.ServiceName == "BotService"
28+
apiVersions := map[string]struct{}{
29+
"2021-05-01-preview": {},
30+
"2022-06-15-preview": {},
31+
"2023-09-15-preview": {},
32+
"2020-06-02": {},
33+
"2021-03-01": {},
34+
"2022-09-15": {},
35+
}
36+
_, apiVersionMatches := apiVersions[apiDefinition.ApiVersion]
37+
return serviceMatches && apiVersionMatches
38+
}
39+
40+
func (workaroundBotService27351) Name() string {
41+
return "BotService / 27351"
42+
}
43+
44+
func (workaroundBotService27351) Process(input models.AzureApiDefinition) (*models.AzureApiDefinition, error) {
45+
output := input
46+
47+
resource, ok := output.Resources["Channel"]
48+
if !ok {
49+
return nil, fmt.Errorf("expected a Resource named `Channel` but didn't get one")
50+
}
51+
// ensure we've got the Resource ID we're going to switch over to
52+
if _, ok := resource.ResourceIds["BotServiceChannelId"]; !ok {
53+
return nil, fmt.Errorf("expected a Resource ID named `BotServiceChannelId` but didn't get one")
54+
}
55+
56+
// ensure we've got the mismatched Resource ID in order to remove it
57+
if _, ok := resource.ResourceIds["ChannelId"]; !ok {
58+
return nil, fmt.Errorf("expected a Resource ID named `ChannelId` but didn't get one")
59+
}
60+
delete(resource.ResourceIds, "ChannelId")
61+
62+
for operationName, operation := range resource.Operations {
63+
if operation.ResourceIdName != nil && *operation.ResourceIdName == "ChannelId" {
64+
operation.ResourceIdName = pointer.To("BotServiceChannelId")
65+
}
66+
resource.Operations[operationName] = operation
67+
}
68+
69+
output.Resources["Channel"] = resource
70+
71+
return &output, nil
72+
}

tools/importer-rest-api-specs/components/parser/dataworkarounds/workarounds.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ var workarounds = []workaround{
1313
workaroundAutomation25108{},
1414
workaroundAutomation25435{},
1515
workaroundBatch21291{},
16+
workaroundBotService27351{},
1617
workaroundContainerService21394{},
1718
workaroundDataFactory23013{},
1819
workaroundDevCenter26189{},
1920
workaroundHDInsight26838{},
2021
workaroundLoadTest20961{},
2122
workaroundRedis22407{},
2223
workaroundMachineLearning25142{},
23-
2424
workaroundRecoveryServicesSiteRecovery26680{},
2525

2626
// @tombuildsstuff: this is an odd place for this however this allows working around inconsistencies in the Swagger

0 commit comments

Comments
 (0)