Skip to content

Commit f6cbf70

Browse files
Merge pull request #2214 from hashicorp/b/datafactory-runtime-discriminator
tools/importer-rest-api-specs: working around Azure/azure-rest-api-specs#23013
2 parents d1e2b5f + 382404d commit f6cbf70

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 = workaroundDataFactory23013{}
11+
12+
// workaroundDataFactory23013 works around the `IntegrationRuntimeReference` and `LinkedServiceReference` models both
13+
// defining a `type` field indicating that these are discriminated types but not defined as a Discriminated Type
14+
// Swagger PR: https://github.com/Azure/azure-rest-api-specs/pull/23013
15+
type workaroundDataFactory23013 struct{}
16+
17+
func (workaroundDataFactory23013) IsApplicable(apiDefinition *models.AzureApiDefinition) bool {
18+
return apiDefinition.ServiceName == "DataFactory" && apiDefinition.ApiVersion == "2018-06-01"
19+
}
20+
21+
func (workaroundDataFactory23013) Name() string {
22+
return "DataFactory / 23013"
23+
}
24+
25+
func (workaroundDataFactory23013) Process(apiDefinition models.AzureApiDefinition) (*models.AzureApiDefinition, error) {
26+
resource, ok := apiDefinition.Resources["DataFlowDebugSession"]
27+
if !ok {
28+
return nil, fmt.Errorf("couldn't find API Resource DataFlowDebugSession")
29+
}
30+
31+
// add the new discriminated parent type
32+
resource.Models["Reference"] = models.ModelDetails{
33+
TypeHintIn: pointer.To("Type"),
34+
Fields: map[string]models.FieldDetails{
35+
"Type": {
36+
ObjectDefinition: &models.ObjectDefinition{
37+
Type: models.ObjectDefinitionString,
38+
},
39+
Required: true,
40+
JsonName: "type",
41+
},
42+
},
43+
}
44+
45+
// update the existing models to be discriminated types and remove the `type` field from them
46+
// ` and `LinkedServiceReference
47+
modelNames := []string{
48+
"IntegrationRuntimeReference",
49+
"LinkedServiceReference",
50+
}
51+
for _, modelName := range modelNames {
52+
model, ok := resource.Models[modelName]
53+
if !ok {
54+
return nil, fmt.Errorf("couldn't find model %q", modelName)
55+
}
56+
delete(model.Fields, "Type")
57+
model.ParentTypeName = pointer.To("Reference")
58+
model.TypeHintValue = pointer.To(modelName)
59+
resource.Models[modelName] = model
60+
}
61+
62+
// delete the now unused `Type` constant
63+
delete(resource.Constants, "Type")
64+
65+
apiDefinition.Resources["DataFlowDebugSession"] = resource
66+
return &apiDefinition, nil
67+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
var workarounds = []workaround{
1111
workaroundBatch21291{},
1212
workaroundContainerService21394{},
13+
workaroundDataFactory23013{},
1314
workaroundLoadTest20961{},
1415
workaroundRedis22407{},
1516

0 commit comments

Comments
 (0)