Skip to content

Commit

Permalink
adjusting built-in rest api template (#5741)
Browse files Browse the repository at this point in the history
Making adjustment of built-in template sample to better working with
CSharp server codege.

---------

Co-authored-by: Timothee Guerin <[email protected]>
Co-authored-by: Timothee Guerin <[email protected]>
  • Loading branch information
3 people authored Jan 24, 2025
1 parent c788082 commit 249e694
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 69 deletions.
7 changes: 7 additions & 0 deletions .chronus/changes/fix_builtinTemplate-2025-0-24-1-37-7.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: internal
packages:
- "@typespec/compiler"
---

Adjust built-in init template sample
8 changes: 8 additions & 0 deletions .chronus/changes/fix_builtinTemplate-2025-0-24-21-57-49.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: internal
packages:
- typespec-vscode
---

update test framework version
3 changes: 1 addition & 2 deletions eng/tsp-core/pipelines/templates/install-browsers.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Template installing browsers
steps:
- script: npx playwright install --with-deps
- script: pnpm exec playwright install
displayName: Install playwright browsers
workingDirectory: packages/playground-website
4 changes: 2 additions & 2 deletions packages/compiler/.scripts/build-init-templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const builtInTemplates: Record<string, InitTemplate> = {
"emitter-output-dir": "{output-dir}/clients/java",
},
},
"@typespec/http-client-js": {
"@azure-tools/typespec-ts": {
description: "JavaScript Client emitter",
options: {
"emitter-output-dir": "{output-dir}/clients/js",
Expand All @@ -54,7 +54,7 @@ const builtInTemplates: Record<string, InitTemplate> = {
"@typespec/http-server-csharp": {
description: "CSharp server stubs",
options: {
"emitter-output-dir": "{output-dir}/server",
"emitter-output-dir": "{output-dir}/server/generated",
},
},
"@typespec/http-server-js": {
Expand Down
20 changes: 13 additions & 7 deletions packages/compiler/templates/__snapshots__/rest/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,40 @@ using TypeSpec.Http;
namespace DemoService;

model Widget {
@visibility("read", "update")
@path
id: string;

weight: int32;
color: "red" | "blue";
}

model WidgetList {
items: Widget[];
}

@error
model Error {
code: int32;
message: string;
}

model AnalyzeResult {
id: string;
analysis: string;
}

@route("/widgets")
@tag("Widgets")
interface Widgets {
/** List widgets */
@get list(): Widget[] | Error;
@get list(): WidgetList | Error;
/** Read widgets */
@get read(@path id: string): Widget | Error;
/** Create a widget */
@post create(...Widget): Widget | Error;
@post create(@body body: Widget): Widget | Error;
/** Update a widget */
@patch update(...Widget): Widget | Error;
@patch update(@path id: string, @body body: Widget): Widget | Error;
/** Delete a widget */
@delete delete(@path id: string): void | Error;

/** Analyze a widget */
@route("{id}/analyze") @post analyze(@path id: string): string | Error;
@route("{id}/analyze") @post analyze(@path id: string): AnalyzeResult | Error;
}
20 changes: 13 additions & 7 deletions packages/compiler/templates/rest/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,40 @@ using TypeSpec.Http;
namespace DemoService;

model Widget {
@visibility("read", "update")
@path
id: string;

weight: int32;
color: "red" | "blue";
}

model WidgetList {
items: Widget[];
}

@error
model Error {
code: int32;
message: string;
}

model AnalyzeResult {
id: string;
analysis: string;
}

@route("/widgets")
@tag("Widgets")
interface Widgets {
/** List widgets */
@get list(): Widget[] | Error;
@get list(): WidgetList | Error;
/** Read widgets */
@get read(@path id: string): Widget | Error;
/** Create a widget */
@post create(...Widget): Widget | Error;
@post create(@body body: Widget): Widget | Error;
/** Update a widget */
@patch update(...Widget): Widget | Error;
@patch update(@path id: string, @body body: Widget): Widget | Error;
/** Delete a widget */
@delete delete(@path id: string): void | Error;

/** Analyze a widget */
@route("{id}/analyze") @post analyze(@path id: string): string | Error;
@route("{id}/analyze") @post analyze(@path id: string): AnalyzeResult | Error;
}
4 changes: 2 additions & 2 deletions packages/compiler/templates/scaffolding.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"emitter-output-dir": "{output-dir}/clients/java"
}
},
"@typespec/http-client-js": {
"@azure-tools/typespec-ts": {
"description": "JavaScript Client emitter",
"options": {
"emitter-output-dir": "{output-dir}/clients/js"
Expand All @@ -49,7 +49,7 @@
"@typespec/http-server-csharp": {
"description": "CSharp server stubs",
"options": {
"emitter-output-dir": "{output-dir}/server"
"emitter-output-dir": "{output-dir}/server/generated"
}
},
"@typespec/http-server-js": {
Expand Down
2 changes: 1 addition & 1 deletion packages/typespec-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
"@typespec/internal-build-utils": "workspace:~",
"@vitest/coverage-v8": "^3.0.4",
"@vitest/ui": "^3.0.3",
"@vscode/test-web": "^0.0.62",
"@vscode/test-web": "^0.0.65",
"@vscode/vsce": "~3.2.1",
"c8": "^10.1.3",
"mocha": "^11.1.0",
Expand Down
67 changes: 19 additions & 48 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 249e694

Please sign in to comment.