Skip to content

Commit 102d2f1

Browse files
authored
fix(csharp): Fallback init to set (#6613)
* fix(csharp): Fallback init to set
1 parent 109be17 commit 102d2f1

File tree

726 files changed

+36375
-2524
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

726 files changed

+36375
-2524
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## 1.15.12
2+
**`(fix):`** Fallback from `init` to `set` on .NET Framework & .NET Standard 2.0 for public and protected properties.
3+
This ensures the properties can be set on older TFMs without compilation errors.
4+
5+

generators/csharp/base/src/asIs/FileParameter.Template.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ public record FileParameter :
1414
/// <summary>
1515
/// The name of the file to be uploaded.
1616
/// </summary>
17-
public string? FileName { get; init; }
17+
public string? FileName { get; set; }
1818

1919
/// <summary>
2020
/// The content type of the file to be uploaded.
2121
/// </summary>
22-
public string? ContentType { get; init; }
22+
public string? ContentType { get; set; }
2323

2424
/// <summary>
2525
/// The content of the file to be uploaded.
2626
/// </summary>
27-
public required Stream Stream { get; init; }
27+
public required Stream Stream { get; set; }
2828

2929
/// <inheritdoc/>
3030
public void Dispose()

generators/csharp/base/src/asIs/GrpcRequestOptions.Template.cs

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,60 @@ public partial class GrpcRequestOptions
88
/// <summary>
99
/// The maximum number of retry attempts.
1010
/// </summary>
11-
public int? MaxRetries { get; init; }
11+
public int? MaxRetries {
12+
get;
13+
#if NET5_0_OR_GREATER
14+
init;
15+
#else
16+
set;
17+
#endif
18+
}
1219

1320
/// <summary>
1421
/// The timeout for the request.
1522
/// </summary>
16-
public TimeSpan? Timeout { get; init; }
23+
public TimeSpan? Timeout {
24+
get;
25+
#if NET5_0_OR_GREATER
26+
init;
27+
#else
28+
set;
29+
#endif
30+
}
1731

1832
/// <summary>
1933
/// Options for write operations.
2034
/// </summary>
21-
public WriteOptions? WriteOptions { get; init; }
35+
public WriteOptions? WriteOptions {
36+
get;
37+
#if NET5_0_OR_GREATER
38+
init;
39+
#else
40+
set;
41+
#endif
42+
}
2243

2344
/// <summary>
2445
/// Client-side call credentials. Provide authorization with per-call granularity.
2546
/// </summary>
26-
public CallCredentials? CallCredentials { get; init; }
47+
public CallCredentials? CallCredentials {
48+
get;
49+
#if NET5_0_OR_GREATER
50+
init;
51+
#else
52+
set;
53+
#endif
54+
}
2755

2856
/// <summary>
2957
/// Headers to be sent with this particular request.
3058
/// </summary>
31-
internal Headers Headers { get; init; } = new();
59+
internal Headers Headers {
60+
get;
61+
#if NET5_0_OR_GREATER
62+
init;
63+
#else
64+
set;
65+
#endif
66+
} = new();
3267
}

generators/csharp/codegen/src/ast/Field.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,27 @@ export class Field extends AstNode {
208208
writer.write("get; ");
209209
}
210210
if (this.init) {
211-
if (!this.hasSameAccess(this.init)) {
212-
writer.write(`${this.init} `);
211+
// if init is accessible to the end user (public, or protected through inheritance),
212+
// we should not expose init to the user on .NET Framework
213+
const needsFallback =
214+
(this.access === Access.Public || this.access === Access.Protected) &&
215+
(this.init === true || this.init === Access.Public || this.init === Access.Protected);
216+
if (needsFallback) {
217+
writer.writeLine();
218+
writer.writeNoIndent("#if NET5_0_OR_GREATER\n");
219+
if (!this.hasSameAccess(this.init)) {
220+
writer.write(`${this.init} `);
221+
}
222+
writer.writeTextStatement("init");
223+
writer.writeNoIndent("#else\n");
224+
writer.writeTextStatement("set");
225+
writer.writeNoIndent("#endif\n");
226+
} else {
227+
if (!this.hasSameAccess(this.init)) {
228+
writer.write(`${this.init} `);
229+
}
230+
writer.write("init; ");
213231
}
214-
writer.write("init; ");
215232
}
216233
if (this.set) {
217234
if (!this.hasSameAccess(this.set)) {

generators/csharp/sdk/src/root-client/RootClientGenerator.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ export class RootClientGenerator extends FileGenerator<CSharpFile, SdkCustomConf
111111
csharp.field({
112112
access: csharp.Access.Public,
113113
get: true,
114-
init: true,
115114
name: subpackage.name.pascalCase.safeName,
116115
type: csharp.Type.reference(this.context.getSubpackageClassReference(subpackage))
117116
})

generators/csharp/sdk/versions.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
# Set `enable-forward-compatible-enums` to `false` in the configuration to generate the old enums.
88
# irVersion: 53
99

10+
- version: 1.15.12
11+
createdAt: "2025-03-31"
12+
irVersion: 57
13+
changelogEntry:
14+
- type: fix
15+
summary: |
16+
Fallback from `init` to `set` on .NET Framework & .NET Standard 2.0 for public and protected properties.
17+
This ensures the properties can be set on older TFMs without compilation errors.
18+
1019
- version: 1.15.11
1120
createdAt: "2025-03-25"
1221
irVersion: 57

packages/cli/cli/versions.yml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,32 @@
2222
- changelogEntry:
2323
- summary: |
2424
Bump undici timeouts to make sure docs sites get published. This addresses an issue where large documentation sites were timing out during the publishing process. By increasing the timeout values for the undici HTTP client, we ensure that even complex documentation sites have enough time to complete the publishing process.
25-
25+
2626
type: fix
2727
irVersion: 57
2828
version: 0.57.8
2929

3030
- changelogEntry:
3131
- summary: |
3232
Add support for `anyOf` in the new OpenAPI parser. This allows for undiscriminated unions in the OpenAPI schema, where a type can be one of several possible types without a discriminator field. The parser now handles both `oneOf` and `anyOf` schemas in the same way, converting them to undiscriminated unions in the IR.
33-
33+
3434
type: fix
3535
irVersion: 57
3636
version: 0.57.7
3737

3838
- changelogEntry:
3939
- summary: |
4040
Reduce CLI output from the legacy OpenAPI parser when using the experimental `openapiParserV3` option. This makes the logs cleaner and more focused on relevant information when using the newer parser.
41-
41+
4242
type: fix
4343
irVersion: 57
4444
version: 0.57.6
4545

4646
- changelogEntry:
4747
- summary: |
4848
Fix an issue where endpoint ids were not globally unique because they didn't take into account namespaces. This only affects
49-
the new OpenAPI -> IR parser.
50-
49+
the new OpenAPI -> IR parser.
50+
5151
type: fix
5252
irVersion: 57
5353
version: 0.57.5
@@ -66,7 +66,7 @@
6666
```
6767
6868
Each namespace creates a separate package in the generated IR, allowing for clear separation between different versions or components of your API.
69-
69+
7070
type: feat
7171
irVersion: 57
7272
version: 0.57.4
@@ -80,9 +80,9 @@
8080

8181
- changelogEntry:
8282
- summary: |
83-
Add support for parsing `type: enum` in OpenAPI schemas. This allows for proper conversion of enum types that use the
83+
Add support for parsing `type: enum` in OpenAPI schemas. This allows for proper conversion of enum types that use the
8484
non-standard `type: enum` format instead of the standard `type: string` with `enum` values.
85-
85+
8686
type: feat
8787
irVersion: 57
8888
version: 0.57.2
@@ -97,7 +97,7 @@
9797
You are an AI assistant.
9898
Only respond to questions using information from the documents.
9999
Include markdown footnotes to the sources of your information.
100-
100+
101101
type: feat
102102
irVersion: 57
103103
version: 0.57.1
@@ -203,8 +203,8 @@
203203

204204
- changelogEntry:
205205
- summary: |
206-
The `fern init --openapi` command now references the OpenAPI file in
207-
place using the new `specs` syntax in generators.yml instead of copying the file into the
206+
The `fern init --openapi` command now references the OpenAPI file in
207+
place using the new `specs` syntax in generators.yml instead of copying the file into the
208208
Fern directory. This makes it easier to maintain the source OpenAPI file separately from the Fern configuration.
209209
type: fix
210210
irVersion: 57
@@ -327,8 +327,8 @@
327327

328328
- changelogEntry:
329329
- summary: |
330-
Updated the CLI to gracefully handle unsupported security schemes (e.g. cookie-based auth) by skipping them
331-
instead of throwing an error. This allows the CLI to continue processing the rest of the API definition even when
330+
Updated the CLI to gracefully handle unsupported security schemes (e.g. cookie-based auth) by skipping them
331+
instead of throwing an error. This allows the CLI to continue processing the rest of the API definition even when
332332
it encounters security schemes it cannot convert.
333333
type: fix
334334
irVersion: 56
@@ -373,14 +373,14 @@
373373
type: fix
374374
irVersion: 56
375375
version: 0.56.0
376-
376+
377377
- changelogEntry:
378378
- summary: |
379-
Hidden sections are now removed from the docs sitemap.
379+
Hidden sections are now removed from the docs sitemap.
380380
type: fix
381381
irVersion: 56
382382
version: 0.56.0-rc6
383-
383+
384384
- changelogEntry:
385385
- summary: |
386386
Fixed duplicate validation messages in docs validation by deduplicating violations

seed/csharp-model/accept-header/src/SeedAccept/Core/Public/FileParameter.cs

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

seed/csharp-model/alias-extends/src/SeedAliasExtends/Core/Public/FileParameter.cs

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

seed/csharp-model/alias/src/SeedAlias/Core/Public/FileParameter.cs

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

seed/csharp-model/any-auth/src/SeedAnyAuth/Core/Public/FileParameter.cs

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

seed/csharp-model/api-wide-base-path/src/SeedApiWideBasePath/Core/Public/FileParameter.cs

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

seed/csharp-model/audiences/src/SeedAudiences/Core/Public/FileParameter.cs

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)