-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update rest init template to include emitters and basic code (#5716)
- Loading branch information
1 parent
e654ba1
commit 9517d45
Showing
11 changed files
with
236 additions
and
9 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
.chronus/changes/feature-rest-init-template-2025-0-23-17-13-37.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: feature | ||
packages: | ||
- "@typespec/compiler" | ||
--- | ||
|
||
Updated Rest init template to include additional emitters(client, server) and a basic sample. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,6 @@ coverage.xml | |
.pytest_cache/ | ||
test-results.xml | ||
test-results/ | ||
__snapshots__/ | ||
|
||
# Translations | ||
*.mo | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# MacOS | ||
.DS_Store | ||
|
||
# Default TypeSpec output | ||
tsp-output/ | ||
dist/ | ||
|
||
# Dependency directories | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import "@typespec/http"; | ||
|
||
using TypeSpec.Http; | ||
@service({ | ||
title: "Widget Service", | ||
}) | ||
namespace DemoService; | ||
|
||
model Widget { | ||
@visibility("read", "update") | ||
@path | ||
id: string; | ||
|
||
weight: int32; | ||
color: "red" | "blue"; | ||
} | ||
|
||
@error | ||
model Error { | ||
code: int32; | ||
message: string; | ||
} | ||
|
||
@route("/widgets") | ||
@tag("Widgets") | ||
interface Widgets { | ||
/** List widgets */ | ||
@get list(): Widget[] | Error; | ||
/** Read widgets */ | ||
@get read(@path id: string): Widget | Error; | ||
/** Create a widget */ | ||
@post create(...Widget): Widget | Error; | ||
/** Update a widget */ | ||
@patch update(...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; | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/compiler/templates/__snapshots__/rest/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "rest", | ||
"version": "0.1.0", | ||
"type": "module", | ||
"peerDependencies": { | ||
"@typespec/compiler": "latest", | ||
"@typespec/http": "latest", | ||
"@typespec/rest": "latest", | ||
"@typespec/openapi": "latest", | ||
"@typespec/openapi3": "latest" | ||
}, | ||
"devDependencies": { | ||
"@typespec/compiler": "latest", | ||
"@typespec/http": "latest", | ||
"@typespec/rest": "latest", | ||
"@typespec/openapi": "latest", | ||
"@typespec/openapi3": "latest" | ||
}, | ||
"private": true | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/compiler/templates/__snapshots__/rest/tspconfig.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# extends: ../tspconfig.yaml # Extend another config file | ||
# emit: # Emitter name | ||
# - "<emitter-name" | ||
# options: # Emitter options | ||
# <emitter-name>: | ||
# "<option-name>": "<option-value>" | ||
# environment-variables: # Environment variables which can be used to interpolate emitter options | ||
# <variable-name>: | ||
# default: "<variable-default>" | ||
# parameters: # Parameters which can be used to interpolate emitter options | ||
# <param-name>: | ||
# default: "<param-default>" | ||
# trace: # Trace areas to enable tracing | ||
# - "<trace-name>" | ||
# warn-as-error: true # Treat warnings as errors | ||
# output-dir: "{project-root}/_generated" # Configure the base output directory for all emitters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import "@typespec/http"; | ||
|
||
using TypeSpec.Http; | ||
@service({ | ||
title: "Widget Service", | ||
}) | ||
namespace DemoService; | ||
|
||
model Widget { | ||
@visibility("read", "update") | ||
@path | ||
id: string; | ||
|
||
weight: int32; | ||
color: "red" | "blue"; | ||
} | ||
|
||
@error | ||
model Error { | ||
code: int32; | ||
message: string; | ||
} | ||
|
||
@route("/widgets") | ||
@tag("Widgets") | ||
interface Widgets { | ||
/** List widgets */ | ||
@get list(): Widget[] | Error; | ||
/** Read widgets */ | ||
@get read(@path id: string): Widget | Error; | ||
/** Create a widget */ | ||
@post create(...Widget): Widget | Error; | ||
/** Update a widget */ | ||
@patch update(...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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters