Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Expand Up @@ -340,43 +340,57 @@ export class TspConfigTsMlcDpPackageNameMatchPatternSubRule extends TspconfigEmi
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 {
let module = config?.options?.[this.emitterName]?.["module"];
if (module === 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 +403,19 @@ export class TspConfigGoMgmtServiceDirMatchPatternSubRule extends TspconfigEmitt
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 +450,6 @@ export class TspConfigGoMgmtGenerateFakesTrueSubRule extends TspconfigEmitterOpt
}
}

// ----- 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 +531,14 @@ export const defaultRules = [
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 TspConfigPythonMgmtPackageDirectorySubRule(),
new TspConfigPythonMgmtNamespaceSubRule(),
new TspConfigPythonDpPackageDirectorySubRule(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ import {
TspConfigCsharpAzNamespaceSubRule,
TspConfigCsharpMgmtNamespaceSubRule,
TspConfigGoAzInjectSpansTrueSubRule,
TspConfigGoDpModuleMatchPatternSubRule,
TspConfigGoDpPackageDirectoryMatchPatternSubRule,
TspConfigGoDpEmitterOutputDirMatchPatternSubRule,
TspConfigGoDpServiceDirMatchPatternSubRule,
TspConfigGoMgmtEmitterOutputDirMatchPatternSubRule,
TspConfigGoMgmtGenerateFakesTrueSubRule,
TspConfigGoMgmtGenerateSamplesTrueSubRule,
TspConfigGoMgmtHeadAsBooleanTrueSubRule,
TspConfigGoMgmtModuleEqualStringSubRule,
TspConfigGoMgmtPackageDirectorySubRule,
TspConfigGoMgmtServiceDirMatchPatternSubRule,
TspConfigGoModuleMatchPatternSubRule,
TspConfigJavaAzEmitterOutputDirMatchPatternSubRule,
TspConfigJavaMgmtEmitterOutputDirMatchPatternSubRule,
TspConfigJavaMgmtNamespaceFormatSubRule,
Expand Down Expand Up @@ -274,24 +273,26 @@ const goManagementServiceDirTestCases = createEmitterOptionTestCases(
"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()],
true,
);

const goManagementGenerateExamplesTestCases = createEmitterOptionTestCases(
Expand Down Expand Up @@ -343,19 +344,19 @@ const goDpModuleTestCases = createEmitterOptionTestCases(
"@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()],
[new TspConfigGoModuleMatchPatternSubRule()],
true,
);

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

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

const javaAzEmitterOutputDirTestCases = createEmitterOptionTestCases(
Expand Down Expand Up @@ -572,15 +574,14 @@ options:
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 +615,15 @@ describe("tspconfig", function () {
...tsDpModularPackageNameTestCases,
// go
...goManagementServiceDirTestCases,
...goManagementPackageDirTestCases,
...goManagementEmitterOutputDirTestCases,
...goManagementModuleTestCases,
...goManagementGenerateExamplesTestCases,
...goManagementGenerateFakesTestCases,
...goManagementHeadAsBooleanTestCases,
...goManagementInjectSpansTestCases,
...goDpInjectSpansTestCases,
...goDpModuleTestCases,
...goDpPackageDirTestCases,
...goDpEmitterOutputDirTestCases,
...goDpServiceDirTestCases,
// java
...javaAzEmitterOutputDirTestCases,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ options:
package-details:
name: "@azure/arm-contoso"
"@azure-tools/typespec-go":
service-dir: "sdk/resourcemanager/contoso"
package-dir: "armcontoso"
module: "github.com/Azure/azure-sdk-for-go/{service-dir}/{package-dir}"
service-dir: "{output-dir}/sdk/resourcemanager/contoso"
emitter-output-dir: "{service-dir}/armcontoso"
module: "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/contoso/armcontoso"
fix-const-stuttering: true
flavor: "azure"
generate-samples: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ options:
namespace: com.azure.contoso.widgetmanager
flavor: azure
"@azure-tools/typespec-go":
module: "github.com/Azure/azure-sdk-for-go/{service-dir}/{package-dir}"
service-dir: "sdk/contosowidget"
package-dir: "azmanager"
module-version: "0.0.1"
module: "github.com/Azure/azure-sdk-for-go/sdk/contosowidget/azmanager"
service-dir: "{output-dir}/sdk/contosowidget"
emitter-output-dir: "{service-dir}/azmanager"
generate-fakes: true
inject-spans: true
single-client: true
Expand Down