Skip to content

Commit afdd28f

Browse files
Allow data plane module paths. (Azure#23815)
Data plane module paths don't include `resourcemanager` and `arm`, so they were failing the previous regex. I modified it to allow both types, and, if it's data plane, to allow 'az' as the prefix. This was causing a build failure for me here: https://github.com/Azure/azure-rest-api-specs/pull/31719/checks?check_run_id=33822699487
1 parent 2ea046b commit afdd28f

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

eng/tools/generator/typespec/typespec-go.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,16 @@ func NewGoEmitterOptions(emitOption any) (*GoEmitterOptions, error) {
4242
return &option, err
4343
}
4444

45-
const moduleRegex = `^github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/(\w+)/arm(\w+)$`
45+
const moduleRegex = `^github.com/Azure/azure-sdk-for-go/sdk/` +
46+
`(` +
47+
`resourcemanager/\w+/arm\w+` + // either an ARM package (ie: github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/servicebus/armservicebus)
48+
`|` +
49+
`.+?/az[^/]+` + // or a data plane package (ie, github.com/Azure/azure-sdk-for-go/sdk/messaging/eventgrid/aznamespaces)
50+
`)$`
4651

4752
var (
4853
ErrModuleEmpty = errors.New("typesepec-go option `module` is required")
49-
ErrModuleFormat = errors.New("module must be in the format of github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/xxx/armxxx")
54+
ErrModuleFormat = errors.New("module must be in the format of github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/xxx/armxxx or github.com/Azure/azure-sdk-for-go/sdk/xxx/azxxx")
5055
)
5156

5257
func (o *GoEmitterOptions) Validate() error {

eng/tools/generator/typespec/typespec-go_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@ import (
77
"github.com/stretchr/testify/assert"
88
)
99

10+
func TestGoEmitterOptionsAreValid(t *testing.T) {
11+
modules := []string{
12+
"github.com/Azure/azure-sdk-for-go/sdk/messaging/eventgrid/aznamespaces",
13+
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/servicebus/armservicebus",
14+
}
15+
16+
for _, module := range modules {
17+
t.Run("Check "+module, func(t *testing.T) {
18+
// module format is correct
19+
goOption := map[string]any{
20+
"module": module,
21+
}
22+
goEmitOptions, err := typespec.NewGoEmitterOptions(goOption)
23+
assert.NoError(t, err)
24+
err = goEmitOptions.Validate()
25+
assert.NoError(t, err)
26+
})
27+
}
28+
}
29+
1030
func TestGoEmitterOptionsValidate(t *testing.T) {
1131
goOption := map[string]any{
1232
"module": "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/xxx/armxxx",

0 commit comments

Comments
 (0)