Skip to content

Commit

Permalink
fix(csharp): handle referencing System when a type named System exi…
Browse files Browse the repository at this point in the history
…sts (#6005)
  • Loading branch information
dsinghvi authored Feb 15, 2025
1 parent f3cac44 commit 8e69557
Show file tree
Hide file tree
Showing 310 changed files with 674 additions and 513 deletions.
2 changes: 1 addition & 1 deletion .github/actions/cached-seed/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ runs:
- name: Install protoc-gen-openapi
if: steps.cache.outputs.cache-hit != 'true'
shell: bash
run: go install github.com/google/gnostic/cmd/protoc-gen-openapi@v0.7.0
run: go install github.com/fern-api/protoc-gen-openapi/cmd/protoc-gen-openapi@latest

- name: Seed Test
if: steps.cache.outputs.cache-hit != 'true'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal class CollectionItemSerializer<TDatatype, TConverterType>
/// <returns>Created object.</returns>
public override IEnumerable<TDatatype>? Read(
ref Utf8JsonReader reader,
System.Type typeToConvert,
global::System.Type typeToConvert,
JsonSerializerOptions options
)
{
Expand Down
2 changes: 1 addition & 1 deletion generators/csharp/codegen/src/asIs/DateTimeSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal class DateTimeSerializer : JsonConverter<DateTime>
{
public override DateTime Read(
ref Utf8JsonReader reader,
System.Type typeToConvert,
global::System.Type typeToConvert,
JsonSerializerOptions options
)
{
Expand Down
4 changes: 2 additions & 2 deletions generators/csharp/codegen/src/asIs/EnumSerializer.Template.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace <%= namespace%>;

internal class EnumSerializer<TEnum> : JsonConverter<TEnum>
where TEnum : struct, System.Enum
where TEnum : struct, Enum
{
private readonly Dictionary<TEnum, string> _enumToString = new();
private readonly Dictionary<string, TEnum> _stringToEnum = new();
Expand Down Expand Up @@ -36,7 +36,7 @@ public EnumSerializer()

public override TEnum Read(
ref Utf8JsonReader reader,
System.Type typeToConvert,
global::System.Type typeToConvert,
JsonSerializerOptions options
)
{
Expand Down
4 changes: 2 additions & 2 deletions generators/csharp/codegen/src/asIs/OneOfSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal class OneOfSerializer : JsonConverter<IOneOf>
{
public override IOneOf? Read(
ref Utf8JsonReader reader,
System.Type typeToConvert,
global::System.Type typeToConvert,
JsonSerializerOptions options
)
{
Expand Down Expand Up @@ -38,7 +38,7 @@ public override void Write(Utf8JsonWriter writer, IOneOf value, JsonSerializerOp
JsonSerializer.Serialize(writer, value.Value, options);
}

private static (System.Type type, MethodInfo cast)[] GetOneOfTypes(System.Type typeToConvert)
private static (global::System.Type type, MethodInfo cast)[] GetOneOfTypes(global::System.Type typeToConvert)
{
var type = typeToConvert;
if (Nullable.GetUnderlyingType(type) is { } underlyingType)
Expand Down
9 changes: 9 additions & 0 deletions generators/csharp/sdk/versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
# Set `enable-forward-compatible-enums` to `false` in the configuration to generate the old enums.
# irVersion: 53

- version: 1.9.25
createdAt: "2025-02-14"
irVersion: 53
changelogEntry:
- type: fix
summary: |
Use `global::System.Type` instead of `System.Type` in generated code to avoid potential naming conflicts
when a type named `System` exists in the current namespace.
- version: 1.9.24
createdAt: "2025-02-14"
irVersion: 53
Expand Down
104 changes: 52 additions & 52 deletions packages/seed/src/commands/test/test-runner/TestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,61 +108,61 @@ export abstract class TestRunner {
* Runs the generator.
*/
public async run({ fixture, configuration }: TestRunner.RunArgs): Promise<TestRunner.TestResult> {
if (this.buildInvocation == null) {
this.buildInvocation = this.build();
}
await this.buildInvocation;
try {
if (this.buildInvocation == null) {
this.buildInvocation = this.build();
}
await this.buildInvocation;

const metrics: TestRunner.TestCaseMetrics = {};
const metrics: TestRunner.TestCaseMetrics = {};

const id = configuration != null ? `${fixture}:${configuration.outputFolder}` : `${fixture}`;
const absolutePathToAPIDefinition = AbsoluteFilePath.of(
path.join(__dirname, FERN_DIRECTORY, APIS_DIRECTORY, fixture)
);
const taskContext = this.taskContextFactory.create(`${this.generator.workspaceName}:${id}`);
const outputFolder = configuration?.outputFolder ?? fixture;
const outputDir =
configuration == null
? join(this.generator.absolutePathToWorkspace, RelativeFilePath.of(fixture))
: join(
this.generator.absolutePathToWorkspace,
RelativeFilePath.of(fixture),
RelativeFilePath.of(configuration.outputFolder)
);
const language = this.generator.workspaceConfig.language;
const outputVersion = configuration?.outputVersion ?? "0.0.1";
const customConfig =
this.generator.workspaceConfig.defaultCustomConfig != null || configuration?.customConfig != null
? {
...(this.generator.workspaceConfig.defaultCustomConfig ?? {}),
...((configuration?.customConfig as Record<string, unknown>) ?? {})
}
: undefined;
const publishConfig = configuration?.publishConfig;
const outputMode = configuration?.outputMode ?? this.generator.workspaceConfig.defaultOutputMode;
const irVersion = this.generator.workspaceConfig.irVersion;
const publishMetadata = configuration?.publishMetadata ?? undefined;
const readme = configuration?.readmeConfig ?? undefined;
const fernWorkspace = await (
await convertGeneratorWorkspaceToFernWorkspace({
absolutePathToAPIDefinition,
taskContext,
fixture
})
)?.toFernWorkspace({ context: taskContext });
if (fernWorkspace == null) {
return {
type: "failure",
cause: "invalid-fixture",
message: `Failed to validate fixture ${fixture}`,
id: fixture,
outputFolder,
metrics
};
}
const id = configuration != null ? `${fixture}:${configuration.outputFolder}` : `${fixture}`;
const absolutePathToAPIDefinition = AbsoluteFilePath.of(
path.join(__dirname, FERN_DIRECTORY, APIS_DIRECTORY, fixture)
);
const taskContext = this.taskContextFactory.create(`${this.generator.workspaceName}:${id}`);
const outputFolder = configuration?.outputFolder ?? fixture;
const outputDir =
configuration == null
? join(this.generator.absolutePathToWorkspace, RelativeFilePath.of(fixture))
: join(
this.generator.absolutePathToWorkspace,
RelativeFilePath.of(fixture),
RelativeFilePath.of(configuration.outputFolder)
);
const language = this.generator.workspaceConfig.language;
const outputVersion = configuration?.outputVersion ?? "0.0.1";
const customConfig =
this.generator.workspaceConfig.defaultCustomConfig != null || configuration?.customConfig != null
? {
...(this.generator.workspaceConfig.defaultCustomConfig ?? {}),
...((configuration?.customConfig as Record<string, unknown>) ?? {})
}
: undefined;
const publishConfig = configuration?.publishConfig;
const outputMode = configuration?.outputMode ?? this.generator.workspaceConfig.defaultOutputMode;
const irVersion = this.generator.workspaceConfig.irVersion;
const publishMetadata = configuration?.publishMetadata ?? undefined;
const readme = configuration?.readmeConfig ?? undefined;
const fernWorkspace = await (
await convertGeneratorWorkspaceToFernWorkspace({
absolutePathToAPIDefinition,
taskContext,
fixture
})
)?.toFernWorkspace({ context: taskContext });
if (fernWorkspace == null) {
return {
type: "failure",
cause: "invalid-fixture",
message: `Failed to validate fixture ${fixture}`,
id: fixture,
outputFolder,
metrics
};
}

taskContext.logger.debug("Acquiring lock...");
try {
taskContext.logger.debug("Acquiring lock...");
await this.lock.acquire();
taskContext.logger.info("Running generator...");
try {
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.

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.

4 changes: 2 additions & 2 deletions seed/csharp-sdk/alias/src/SeedAlias/Core/EnumSerializer.cs

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

6 changes: 4 additions & 2 deletions seed/csharp-sdk/alias/src/SeedAlias/Core/OneOfSerializer.cs

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.

Loading

0 comments on commit 8e69557

Please sign in to comment.