Skip to content

Conversation

@sidhartthhhhh
Copy link

@sidhartthhhhh sidhartthhhhh commented Jul 14, 2025

fixes #6758

This PR fixes an issue in the TypeScript writer where properties beginning with double underscores (e.g., __component) used as discriminators in OpenAPI schemas were not properly handled in the generated models, causing TypeScript errors.

Modified TypeScriptConventionService.cs to ensure that properties with names like __component are preserved and correctly handled in composed types and serialization logic.

Specifically ensured that such properties are not renamed or stripped during type generation or access.

@sidhartthhhhh sidhartthhhhh requested a review from a team as a code owner July 14, 2025 13:00
Copy link
Member

@baywet baywet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • changelog entry
  • unit tests


public override string GetPropertyName(string originalName)
{
if (originalName.StartsWith("__"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fix is super specific to this use case, it should most likely be fixed in the generation code instead.

Here is where the switch statement gets written

writer.StartBlock($"switch ({param.Name.ToFirstCharacterLowerCase()}.{discriminatorProperty.Name.ToFirstCharacterLowerCase()}) {{");

(should use the symbol name instead, and avoid normalizing the casing)

Here is where it gets tested

Assert.Contains("switch (parentClass.odataType) {", result);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Properties with leading double underscores (__) not generated properly from OpenAPI

2 participants