Skip to content
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
* text=auto eol=lf
packages/typespec-rust/test/**/src/generated/**/*.rs linguist-generated=true
# Squad: union merge for append-only team state files
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -412,3 +412,5 @@ spec-coverage.json

packages/typespec-rust/**/target/
packages/typespec-rust/pnpm-store/
# Squad: ignore generated logs
.squad/
1 change: 1 addition & 0 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"lro",
"lros",
"msrc",
"noauth",
"pageable",
"reinjectable",
"reinjected",
Expand Down
10 changes: 8 additions & 2 deletions packages/typespec-rust/.scripts/tspcompile.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@ const compiler = pkgRoot + 'node_modules/@typespec/compiler/cmd/tsp.js';
const httpSpecsGroup = {
'spector_apikey': {input: 'authentication/api-key'},
'spector_customauth': {input: 'authentication/http/custom'},
'spector_noauth': {input: 'authentication/noauth/union'},
'spector_oauth2': {input: 'authentication/oauth2'},
'spector_unionauth': {input: 'authentication/union'},
'spector_documentation': {input: 'documentation'},
'spector_bytes': {input: 'encode/bytes'}, // TODO: nested arrays and "raw" request/responses (i.e. the orphan problem)
'spector_datetime': {input: 'encode/datetime'},
'spector_duration': {input: 'encode/duration'},
'spector_encarray': {input: 'encode/array'},
'spector_numeric': {input: 'encode/numeric'},
'spector_bodyoptional': {input: 'parameters/body-optionality'},
'spector_basicparams': {input: 'parameters/basic'},
'spector_collectionfmt': {input: 'parameters/collection-format'},
'spector_path': {input: 'parameters/path'},
'spector_query': {input: 'parameters/query'},
'spector_spread': {input: 'parameters/spread'},
'spector_contentneg': {input: 'payload/content-negotiation'},
'spector_jmergepatch': {input: 'payload/json-merge-patch'},
Expand All @@ -55,7 +59,8 @@ const httpSpecsGroup = {
'spector_empty': {input: 'type/model/empty'},
'spector_enumdisc': {input: 'type/model/inheritance/enum-discriminator'},
'spector_nodisc': {input: 'type/model/inheritance/not-discriminated'},
//'spector_recursive': {input: 'type/model/inheritance/recursive'},
//'spector_nesteddisc': {input: 'type/model/inheritance/nested-discriminator'},
'spector_recursive': {input: 'type/model/inheritance/recursive'},
'spector_singledisc': {input: 'type/model/inheritance/single-discriminator'},
'spector_usage': {input: 'type/model/usage'},
'spector_visibility': {input: 'type/model/visibility'},
Expand All @@ -75,10 +80,11 @@ const httpSpecsGroup = {
};

const azureHttpSpecsGroup = {
//'spector_access': {input: 'azure/client-generator-core/access'},
'spector_access': {input: 'azure/client-generator-core/access'},
'spector_apiverheader': {input: 'azure/client-generator-core/api-version/header/client.tsp'},
'spector_apiverpath': {input: 'azure/client-generator-core/api-version/path/client.tsp'},
'spector_apiverquery': {input: 'azure/client-generator-core/api-version/query/client.tsp'},
'spector_clientdefault': {input: 'azure/client-generator-core/client-default-value'},
'spector_clientinit_default': {input: 'azure/client-generator-core/client-initialization/default'},
'spector_clientinit_individually': {input: 'azure/client-generator-core/client-initialization/individually'},
'spector_clientinit_individually_parent': {input: 'azure/client-generator-core/client-initialization/individuallyParent'},
Expand Down
2 changes: 2 additions & 0 deletions packages/typespec-rust/run_regen.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Set-Location C:\Repos\RickWinter\typespec-rust\packages\typespec-rust
& node .scripts/tspcompile.js
26 changes: 22 additions & 4 deletions packages/typespec-rust/src/codegen/clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,19 +271,37 @@ export function emitClients(module: rust.ModuleContainer): ClientModules | undef

body += '}\n\n'; // end client impl

// emit pub(crate) const declarations for fields with default value constants
// Emit pub(crate) const declarations for fields with default value constants.
//
// These constants are ALWAYS emitted, even when the options type is suppressed.
// In SDK crates with suppressed options, SDK authors need these constants to
// reference TypeSpec-defined default values (e.g., api-version) in their
// hand-authored Default impl. Suppressing them would force hardcoding.
//
// Visibility design:
// - Non-suppressed: constant is referenced by the generated Default impl, so
// it's alive and no dead_code suppression is needed.
// - Suppressed: the generated options type doesn't exist — SDK authors provide
// their own. The constant is a convenience they SHOULD use, but may not.
// #[allow(dead_code)] is appropriate here (parallels std library patterns).
if (client.constructable) {
const isSuppressed = client.constructable.suppressed === 'yes';
for (const field of client.constructable.options.type.fields) {
if (field.defaultValueConstant) {
if (isSuppressed) {
// When the client options type is suppressed, avoid emitting an intra-doc link
// to a type that does not exist in the generated code.
// Plain text doc comment — the options type doesn't exist when suppressed,
// so intra-doc links would be broken.
body += `/// Default value for \`${client.constructable.options.type.name}::${field.name}\`.\n`;
body += `///\n`;
body += `/// This constant is available for SDK authors to use in hand-authored code.\n`;
body += `/// When the options type is suppressed (via \`@access(Access.internal)\`), the\n`;
body += `/// SDK author provides a custom options type and should reference this constant\n`;
body += `/// in their \`Default\` implementation rather than hardcoding the value.\n`;
body += `#[allow(dead_code)]\n`;
} else {
// Intra-doc link — the options type exists and the link resolves.
body += `/// Default value for [\`${client.constructable.options.type.name}::${field.name}\`].\n`;
}
body += `#[allow(dead_code)]\n`;
body += `pub(crate) const ${field.defaultValueConstant.name}: &str = "${field.defaultValueConstant.value}";\n\n`;
}
}
Expand Down
62 changes: 62 additions & 0 deletions packages/typespec-rust/test/Cargo.lock

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

9 changes: 8 additions & 1 deletion packages/typespec-rust/test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ members = [
"sdk/keyvault_secrets",
"spector/authentication/api-key",
"spector/authentication/http/custom",
"spector/authentication/noauth/union",
"spector/authentication/oauth2",
"spector/authentication/union",
"spector/azure/client-generator-core/access",
"spector/azure/client-generator-core/alternate-type",
"spector/azure/client-generator-core/api-version/header",
"spector/azure/client-generator-core/api-version/path",
"spector/azure/client-generator-core/api-version/query",
"spector/azure/client-generator-core/alternate-type",
"spector/azure/client-generator-core/client-default-value",
"spector/azure/client-generator-core/client-initialization/default",
"spector/azure/client-generator-core/client-initialization/individually",
"spector/azure/client-generator-core/client-initialization/individuallyParent",
Expand Down Expand Up @@ -61,6 +64,8 @@ members = [
"spector/client/structure/multi-client",
"spector/client/structure/renamed-operation",
"spector/client/structure/two-operation-group",
"spector/documentation",
"spector/encode/array",
"spector/encode/bytes",
"spector/encode/datetime",
"spector/encode/duration",
Expand All @@ -69,6 +74,7 @@ members = [
"spector/parameters/body-optionality",
"spector/parameters/collection-format",
"spector/parameters/path",
"spector/parameters/query",
"spector/parameters/spread",
"spector/payload/content-negotiation",
"spector/payload/json-merge-patch",
Expand All @@ -93,6 +99,7 @@ members = [
"spector/type/model/empty",
"spector/type/model/inheritance/enum-discriminator",
"spector/type/model/inheritance/not-discriminated",
"spector/type/model/inheritance/recursive",
"spector/type/model/inheritance/single-discriminator",
"spector/type/model/usage",
"spector/type/model/visibility",
Expand Down

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

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

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

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

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

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

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "spector_noauth"
version = "0.1.0"
authors.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
rust-version.workspace = true

[features]
default = ["azure_core/default"]

[dependencies]
azure_core = { workspace = true }

[dev-dependencies]
async-trait = { workspace = true }
tokio = { workspace = true }

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

Loading