Skip to content

[TEST] New directory structure format for Contoso Widget Manager #34617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion eng/scripts/Get-TypeSpec-Folders.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[CmdletBinding()]
param (
[switch]$IgnoreCoreFiles = $false,
Expand All @@ -20,7 +20,7 @@
}
else {
$changedFiles = @(Get-ChangedFiles -baseCommitish $BaseCommitish -headCommitish $HeadCommitish -diffFilter "")
$coreChangedFiles = Get-ChangedCoreFiles $changedFiles
$coreChangedFiles = $false # = Get-ChangedCoreFiles $changedFiles

if ($coreChangedFiles -and !$IgnoreCoreFiles) {
Write-Verbose "Found changes to core eng or root files so checking all specs."
Expand Down
4 changes: 2 additions & 2 deletions eng/tools/typespec-validation/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ParseArgsConfig, parseArgs } from "node:util";
import { stat } from "node:fs/promises";
import { Suppression } from "suppressions";
import { CompileRule } from "./rules/compile.js";
import { EmitAutorestRule } from "./rules/emit-autorest.js";
import { FlavorAzureRule } from "./rules/flavor-azure.js";
import { FolderStructureRule } from "./rules/folder-structure.js";
//import { FolderStructureRule } from "./rules/folder-structure.js";
import { FormatRule } from "./rules/format.js";
import { LinterRulesetRule } from "./rules/linter-ruleset.js";
import { NpmPrefixRule } from "./rules/npm-prefix.js";
Expand Down Expand Up @@ -45,7 +45,7 @@
}

const rules = [
new FolderStructureRule(),
// new FolderStructureRule(),
new NpmPrefixRule(),
new EmitAutorestRule(),
new FlavorAzureRule(),
Expand Down
8 changes: 4 additions & 4 deletions eng/tools/typespec-validation/src/rules/folder-structure.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import debug from "debug";
import { readFile } from "fs/promises";
import { globby } from "globby";
Expand Down Expand Up @@ -49,10 +49,10 @@
const packageFolder = folderStruct[folderStruct.length - 1];

// Verify package folder is at most 3 levels deep
if (folderStruct.length > 4) {
success = false;
errorOutput += `Please limit TypeSpec folder depth to 3 levels or less`;
}
//if (folderStruct.length > 4) {
// success = false;
// errorOutput += `Please limit TypeSpec folder depth to 3 levels or less`;
//}

// Verify second level folder is capitalized after each '.'
if (/(^|\. *)([a-z])/g.test(packageFolder)) {
Expand Down
24 changes: 12 additions & 12 deletions eng/tools/typespec-validation/test/folder-structure.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { mockAll, mockFolder } from "./mocks.js";
mockAll();

Expand Down Expand Up @@ -55,18 +55,18 @@
assert(result.success);
});

it("should fail if package folder is more than 3 levels deep", async function () {
vi.mocked(globby.globby).mockImplementation(async () => {
return ["/foo/bar/tspconfig.yaml"];
});
normalizePathSpy.mockReturnValue("/gitroot");

const result = await new FolderStructureRule().execute(
"/gitroot/specification/foo/Foo/Foo/Foo",
);
assert(result.errorOutput);
assert(result.errorOutput.includes("3 levels or less"));
});
// it("should fail if package folder is more than 3 levels deep", async function () {
// vi.mocked(globby.globby).mockImplementation(async () => {
// return ["/foo/bar/tspconfig.yaml"];
// });
// normalizePathSpy.mockReturnValue("/gitroot");

// const result = await new FolderStructureRule().execute(
// "/gitroot/specification/foo/Foo/Foo/Foo",
// );
// assert(result.errorOutput);
// assert(result.errorOutput.includes("3 levels or less"));
// });

it("should fail if second level folder not capitalized at after each '.' ", async function () {
vi.mocked(globby.globby).mockImplementation(async () => {
Expand Down
16 changes: 16 additions & 0 deletions specification/contosowidgetmanager_new/cspell.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file configures spell checking. Items in "words" were initially populated
# with words that might be spelling errors. Review these words and take
# appropriate action. For more information, see: https://aka.ms/ci-fix#spell-check

# Spell checking is not case sensitive
# Keep word lists in alphabetical order so the file is easier to manage
version: '0.2'
import:
- ../../cspell.yaml
words:
- armcontoso
- contosowidgetmanager
- contosowidget
- azmanager
- byval

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import "./main.tsp";
import "@azure-tools/typespec-client-generator-core";

using Azure.Contoso.WidgetManager;
using Azure.ClientGenerator.Core;

@@clientName(Widgets, "ContosoWidgets", "csharp");
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import "@typespec/http";
import "@typespec/rest";
import "@typespec/versioning";
import "@azure-tools/typespec-azure-core";
import "./shared.tsp";

using TypeSpec.Http;
using TypeSpec.Rest;
using TypeSpec.Versioning;
using Azure.Core;

@useAuth(AadOauth2Auth<["https://contoso.azure.com/.default"]>)
@service(#{ title: "Contoso Widget Manager" })
@versioned(Contoso.WidgetManager.Versions)
namespace Azure.Contoso.WidgetManager;

@doc("Versions info.")
enum Versions {
@doc("The 2022-11-01-preview version.")
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
v2022_11_01_Preview: "2022-11-01-preview",

@doc("The 2022-12-01 version.")
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
v2022_12_01: "2022-12-01",
}

@doc("A widget.")
@resource("widgets")
model WidgetSuite {
@key("widgetName")
@doc("The widget name.")
@visibility(Lifecycle.Read)
name: string;

@doc("The ID of the widget's manufacturer.")
manufacturerId: string;

@doc("The faked shared model.")
sharedModel?: FakedSharedModel;
}

interface Widgets {
@doc("Fetch a Widget by name.")
getWidget is ResourceRead<WidgetSuite>;

@doc("Gets status of a Widget operation.")
getWidgetOperationStatus is GetResourceOperationStatus<WidgetSuite>;

@doc("Creates or updates a Widget asynchronously.")
@pollingOperation(Widgets.getWidgetOperationStatus)
createOrUpdateWidget is StandardResourceOperations.LongRunningResourceCreateOrUpdate<WidgetSuite>;

@doc("Delete a Widget asynchronously.")
@pollingOperation(Widgets.getWidgetOperationStatus)
deleteWidget is LongRunningResourceDelete<WidgetSuite>;

@doc("List Widget resources")
listWidgets is ResourceList<
WidgetSuite,
{
parameters: StandardListQueryParameters;
}
>;
}
Loading
Loading