Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { join } from "path";
import { Suppression } from "suppressions";
import { parse as yamlParse } from "yaml";
Expand Down Expand Up @@ -340,43 +340,76 @@
return skipForRestLevelClientOrManagementPlaneInTsEmitter(config, folder);
}
}
// ----- Go data plane sub rules -----
export class TspConfigGoDpServiceDirMatchPatternSubRule extends TspconfigEmitterOptionsSubRuleBase {

// ----- Go common sub rules -----
export class TspConfigGoModuleMatchPatternSubRule extends TspconfigEmitterOptionsSubRuleBase {
constructor() {
super("@azure-tools/typespec-go", "service-dir", new RegExp(/^sdk\/.*$/));
super(
"@azure-tools/typespec-go",
"module",
new RegExp(/^github.com\/Azure\/azure-sdk-for-go\/.*$/),
);
}
protected skip(_: any, folder: string) {
return skipForManagementPlane(folder);
protected validate(config: any): RuleResult {
const module = config?.options?.[this.emitterName]?.["module"];
const containingModule = config?.options?.[this.emitterName]?.["containing-module"];
if (module === undefined && containingModule === undefined) return { success: false };
if (module === undefined) return { success: true };
return super.validate(config);
}
}

export class TspConfigGoContainingModuleMatchPatternSubRule extends TspconfigEmitterOptionsSubRuleBase {
constructor() {
super(
"@azure-tools/typespec-go",
"containing-module",
new RegExp(/^github.com\/Azure\/azure-sdk-for-go\/.*$/),
);
}
protected validate(config: any): RuleResult {
const module = config?.options?.[this.emitterName]?.["module"];
const containingModule = config?.options?.[this.emitterName]?.["containing-module"];
if (module === undefined && containingModule === undefined) return { success: false };
if (containingModule === undefined) return { success: true };
return super.validate(config);
}
}

export class TspConfigGoDpPackageDirectoryMatchPatternSubRule extends TspconfigEmitterOptionsSubRuleBase {
// ----- Go data plane sub rules -----
export class TspConfigGoDpServiceDirMatchPatternSubRule extends TspconfigEmitterOptionsSubRuleBase {
constructor() {
super("@azure-tools/typespec-go", "package-dir", new RegExp(/^az.*$/));
super("@azure-tools/typespec-go", "service-dir", new RegExp(/^(\{output-dir\}\/)?sdk\/.*$/));
}
protected skip(_: any, folder: string) {
return skipForManagementPlane(folder);
}
protected validate(config: any): RuleResult {
let serviceDir = config?.options?.[this.emitterName]?.["service-dir"];
if (serviceDir === undefined) return { success: true };
return super.validate(config);
}
}

export class TspConfigGoDpModuleMatchPatternSubRule extends TspconfigEmitterOptionsSubRuleBase {
export class TspConfigGoDpEmitterOutputDirMatchPatternSubRule extends TspconfigEmitterOptionsSubRuleBase {
constructor() {
super(
"@azure-tools/typespec-go",
"module",
new RegExp(/^github.com\/Azure\/azure-sdk-for-go\/.*$/),
"emitter-output-dir",
new RegExp(/^(\{output-dir\}\/)?(\{service-dir\}|sdk\/).*\/az.*/),
);
}
protected validate(config: any): RuleResult {
let module = config?.options?.[this.emitterName]?.module;
if (module === undefined) return { success: true };
return super.validate(config);
}
protected skip(_: any, folder: string) {
return skipForManagementPlane(folder);
}
}

export class TspConfigGoAzInjectSpansTrueSubRule extends TspconfigEmitterOptionsSubRuleBase {
constructor() {
super("@azure-tools/typespec-go", "inject-spans", true);
}
}

// ----- Go Mgmt plane sub rules -----
export class TspConfigGoMgmtServiceDirMatchPatternSubRule extends TspconfigEmitterOptionsSubRuleBase {
constructor() {
Expand All @@ -389,23 +422,19 @@
protected skip(_: any, folder: string) {
return skipForDataPlane(folder);
}
}

export class TspConfigGoMgmtPackageDirectorySubRule extends TspconfigEmitterOptionsSubRuleBase {
constructor() {
super("@azure-tools/typespec-go", "package-dir", new RegExp(/^arm[^\/]*$/));
}
protected skip(_: any, folder: string) {
return skipForDataPlane(folder);
protected validate(config: any): RuleResult {
let serviceDir = config?.options?.[this.emitterName]?.["service-dir"];
if (serviceDir === undefined) return { success: true };
return super.validate(config);
}
}

export class TspConfigGoMgmtModuleEqualStringSubRule extends TspconfigEmitterOptionsSubRuleBase {
export class TspConfigGoMgmtEmitterOutputDirMatchPatternSubRule extends TspconfigEmitterOptionsSubRuleBase {
constructor() {
super(
"@azure-tools/typespec-go",
"module",
"github.com/Azure/azure-sdk-for-go/{service-dir}/{package-dir}",
"emitter-output-dir",
new RegExp(/^(\{output-dir\}\/)?(\{service-dir\}|sdk\/resourcemanager\/)[^\/]*\/arm.*/),
);
}
protected skip(_: any, folder: string) {
Expand Down Expand Up @@ -440,14 +469,6 @@
}
}

// ----- Go az sub rules -----

export class TspConfigGoAzInjectSpansTrueSubRule extends TspconfigEmitterOptionsSubRuleBase {
constructor() {
super("@azure-tools/typespec-go", "inject-spans", true);
}
}

// ----- Python management plane sub rules -----
export class TspConfigPythonMgmtPackageDirectorySubRule extends TspconfigEmitterOptionsSubRuleBase {
constructor() {
Expand Down Expand Up @@ -529,15 +550,15 @@
new TspConfigTsRlcDpPackageNameMatchPatternSubRule(),
new TspConfigTsMlcDpPackageNameMatchPatternSubRule(),
new TspConfigGoMgmtServiceDirMatchPatternSubRule(),
new TspConfigGoMgmtPackageDirectorySubRule(),
new TspConfigGoMgmtModuleEqualStringSubRule(),
new TspConfigGoMgmtEmitterOutputDirMatchPatternSubRule(),
new TspConfigGoMgmtGenerateSamplesTrueSubRule(),
new TspConfigGoMgmtGenerateFakesTrueSubRule(),
new TspConfigGoMgmtHeadAsBooleanTrueSubRule(),
new TspConfigGoAzInjectSpansTrueSubRule(),
new TspConfigGoDpServiceDirMatchPatternSubRule(),
new TspConfigGoDpPackageDirectoryMatchPatternSubRule(),
new TspConfigGoDpModuleMatchPatternSubRule(),
new TspConfigGoDpEmitterOutputDirMatchPatternSubRule(),
new TspConfigGoModuleMatchPatternSubRule(),
new TspConfigGoContainingModuleMatchPatternSubRule(),
new TspConfigPythonMgmtPackageDirectorySubRule(),
new TspConfigPythonMgmtNamespaceSubRule(),
new TspConfigPythonDpPackageDirectorySubRule(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { afterEach, beforeEach, describe, it, MockInstance, vi } from "vitest";

import { contosoTspConfig } from "@azure-tools/specs-shared/test/examples";
Expand All @@ -11,15 +11,15 @@
TspConfigCsharpAzNamespaceSubRule,
TspConfigCsharpMgmtNamespaceSubRule,
TspConfigGoAzInjectSpansTrueSubRule,
TspConfigGoDpModuleMatchPatternSubRule,
TspConfigGoDpPackageDirectoryMatchPatternSubRule,
TspConfigGoContainingModuleMatchPatternSubRule,
TspConfigGoDpEmitterOutputDirMatchPatternSubRule,
TspConfigGoDpServiceDirMatchPatternSubRule,
TspConfigGoMgmtEmitterOutputDirMatchPatternSubRule,
TspConfigGoMgmtGenerateFakesTrueSubRule,
TspConfigGoMgmtGenerateSamplesTrueSubRule,
TspConfigGoMgmtHeadAsBooleanTrueSubRule,
TspConfigGoMgmtModuleEqualStringSubRule,
TspConfigGoMgmtPackageDirectorySubRule,
TspConfigGoMgmtServiceDirMatchPatternSubRule,
TspConfigGoModuleMatchPatternSubRule,
TspConfigJavaAzEmitterOutputDirMatchPatternSubRule,
TspConfigJavaMgmtEmitterOutputDirMatchPatternSubRule,
TspConfigJavaMgmtNamespaceFormatSubRule,
Expand Down Expand Up @@ -274,24 +274,36 @@
"sdk/resourcemanager/aaa",
"sdk/manager/aaa",
[new TspConfigGoMgmtServiceDirMatchPatternSubRule()],
true,
);

const goManagementPackageDirTestCases = createEmitterOptionTestCases(
const goManagementEmitterOutputDirTestCases = createEmitterOptionTestCases(
"@azure-tools/typespec-go",
managementTspconfigFolder,
"package-dir",
"armaaa",
"aaa",
[new TspConfigGoMgmtPackageDirectorySubRule()],
"emitter-output-dir",
"{output-dir}/sdk/resourcemanager/compute/armcompute",
"{output-dir}/sdk/messaging/eventgrid/azsystemevents",
[new TspConfigGoMgmtEmitterOutputDirMatchPatternSubRule()],
);

const goManagementModuleTestCases = createEmitterOptionTestCases(
"@azure-tools/typespec-go",
managementTspconfigFolder,
"module",
"github.com/Azure/azure-sdk-for-go/{service-dir}/{package-dir}",
"github.com/Azure/azure-sdk-for-java/{service-dir}/{package-dir}",
[new TspConfigGoMgmtModuleEqualStringSubRule()],
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute",
"github.com/Azure/azure-sdk-for-java/sdk/compute/arm-compute",
[new TspConfigGoModuleMatchPatternSubRule()],
false,
);

const goManagementContainingModuleTestCases = createEmitterOptionTestCases(
"@azure-tools/typespec-go",
managementTspconfigFolder,
"containing-module",
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute",
"github.com/Azure/azure-sdk-for-java/sdk/compute/arm-compute",
[new TspConfigGoContainingModuleMatchPatternSubRule()],
false,
);

const goManagementGenerateExamplesTestCases = createEmitterOptionTestCases(
Expand Down Expand Up @@ -343,19 +355,29 @@
"@azure-tools/typespec-go",
"",
"module",
"github.com/Azure/azure-sdk-for-go/aaa",
"github.com/Azure/azure-sdk-for-go/sdk/messaging/aaa",
"github.com/Azure/azure-sdk-for-cpp/bbb",
[new TspConfigGoDpModuleMatchPatternSubRule()],
true,
[new TspConfigGoModuleMatchPatternSubRule()],
false,
);

const goDpPackageDirTestCases = createEmitterOptionTestCases(
const goDpContainingModuleTestCases = createEmitterOptionTestCases(
"@azure-tools/typespec-go",
"",
"package-dir",
"az1/2/3",
"bzasd",
[new TspConfigGoDpPackageDirectoryMatchPatternSubRule()],
"containing-module",
"github.com/Azure/azure-sdk-for-go/sdk/messaging/aaa",
"github.com/Azure/azure-sdk-for-cpp/bbb",
[new TspConfigGoContainingModuleMatchPatternSubRule()],
false,
);

const goDpEmitterOutputDirTestCases = createEmitterOptionTestCases(
"@azure-tools/typespec-go",
"",
"emitter-output-dir",
"{output-dir}/sdk/messaging/eventgrid/azsystemevents",
"{output-dir}/sdk/resourcemanager/compute/armcompute",
[new TspConfigGoDpEmitterOutputDirMatchPatternSubRule()],
);

const goDpServiceDirTestCases = createEmitterOptionTestCases(
Expand All @@ -365,6 +387,7 @@
"sdk/2/3",
"sd/k",
[new TspConfigGoDpServiceDirMatchPatternSubRule()],
true,
);

const javaAzEmitterOutputDirTestCases = createEmitterOptionTestCases(
Expand Down Expand Up @@ -572,15 +595,14 @@
description: "Suppress option with wildcard at the end",
folder: managementTspconfigFolder,
subRules: [
new TspConfigGoMgmtPackageDirectorySubRule(),
new TspConfigGoMgmtModuleEqualStringSubRule(),
new TspConfigGoMgmtEmitterOutputDirMatchPatternSubRule(),
new TspConfigGoModuleMatchPatternSubRule(),
],
tspconfigContent: `
options:
"@azure-tools/typespec-go":
package-dir: "wrong/directory"
module-name: "invalid-module"
generate-consts: false
module: "invalid-module"
`,
success: true,
ignoredKeyPaths: ["options.@azure-tools/typespec-go.*"],
Expand Down Expand Up @@ -614,15 +636,17 @@
...tsDpModularPackageNameTestCases,
// go
...goManagementServiceDirTestCases,
...goManagementPackageDirTestCases,
...goManagementEmitterOutputDirTestCases,
...goManagementModuleTestCases,
...goManagementContainingModuleTestCases,
...goManagementGenerateExamplesTestCases,
...goManagementGenerateFakesTestCases,
...goManagementHeadAsBooleanTestCases,
...goManagementInjectSpansTestCases,
...goDpInjectSpansTestCases,
...goDpModuleTestCases,
...goDpPackageDirTestCases,
...goDpContainingModuleTestCases,
...goDpEmitterOutputDirTestCases,
...goDpServiceDirTestCases,
// java
...javaAzEmitterOutputDirTestCases,
Expand Down
4 changes: 2 additions & 2 deletions specification/advisor/Advisor.Management/tspconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ options:
name: "@azure/arm-advisor"
"@azure-tools/typespec-go":
service-dir: "sdk/resourcemanager/advisor"
package-dir: "armadvisor"
module: "github.com/Azure/azure-sdk-for-go/{service-dir}/{package-dir}"
emitter-output-dir: "{output-dir}/{service-dir}/armadvisor"
module: "github.com/Azure/azure-sdk-for-go/{service-dir}/armadvisor"
fix-const-stuttering: true
flavor: "azure"
generate-samples: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ options:
name: "@azure/arm-agricultureplatform"
"@azure-tools/typespec-go":
service-dir: "sdk/resourcemanager/agricultureplatform"
package-dir: "armagricultureplatform"
module: "github.com/Azure/azure-sdk-for-go/{service-dir}/{package-dir}"
emitter-output-dir: "{output-dir}/{service-dir}/armagricultureplatform"
module: "github.com/Azure/azure-sdk-for-go/{service-dir}/armagricultureplatform"
fix-const-stuttering: true
flavor: "azure"
generate-samples: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ options:
name: "@azure/arm-dependencymap"
"@azure-tools/typespec-go":
service-dir: "sdk/resourcemanager/dependencymap"
package-dir: "armdependencymap"
module: "github.com/Azure/azure-sdk-for-go/{service-dir}/{package-dir}"
emitter-output-dir: "{output-dir}/{service-dir}/armdependencymap"
module: "github.com/Azure/azure-sdk-for-go/{service-dir}/armdependencymap"
examples-directory: "{project-root}/examples"
fix-const-stuttering: true
flavor: "azure"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ options:
flavor: azure
"@azure-tools/typespec-go":
service-dir: "sdk/resourcemanager/computefleet"
package-dir: "armcomputefleet"
module: "github.com/Azure/azure-sdk-for-go/{service-dir}/{package-dir}"
emitter-output-dir: "{output-dir}/{service-dir}/armcomputefleet"
module: "github.com/Azure/azure-sdk-for-go/{service-dir}/armcomputefleet"
fix-const-stuttering: true
flavor: "azure"
generate-samples: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ options:
generate-sample: true
"@azure-tools/typespec-go":
service-dir: "sdk/resourcemanager/azurestackhci"
package-dir: "armazurestackhcivm"
module: "github.com/Azure/azure-sdk-for-go/{service-dir}/{package-dir}"
emitter-output-dir: "{output-dir}/{service-dir}/armazurestackhcivm"
module: "github.com/Azure/azure-sdk-for-go/{service-dir}/armazurestackhcivm"
fix-const-stuttering: true
flavor: "azure"
generate-samples: true
Expand Down
3 changes: 1 addition & 2 deletions specification/batch/Azure.Batch/tspconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ options:
generate-fakes: false
inject-spans: true
module: "github.com/Azure/azure-sdk-for-go/{service-dir}/azbatch"
module-version: "0.1.0"
package-dir: "azbatch"
emitter-output-dir: "{output-dir}/{service-dir}/azbatch"
service-dir: "sdk/batch"
single-client: true
slice-elements-byval: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,6 @@ interface SavingsPlanModels {
@@clientInitialization(Microsoft.BillingBenefits,
{
parameters: ExpandParameter,
}
},
"!go"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a bug for TypeSpec conversion for Go.

);
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ options:
name: "@azure/arm-billingbenefits"
"@azure-tools/typespec-go":
service-dir: "sdk/resourcemanager/billingbenefits"
package-dir: "armbillingbenefits"
module: "github.com/Azure/azure-sdk-for-go/{service-dir}/{package-dir}"
emitter-output-dir: "{output-dir}/{service-dir}/armbillingbenefits"
module: "github.com/Azure/azure-sdk-for-go/{service-dir}/armbillingbenefits"
fix-const-stuttering: true
flavor: "azure"
generate-samples: true
Expand Down
Loading
Loading