Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid class name generated #224

Closed
Remo opened this issue Jul 7, 2021 · 2 comments · Fixed by #333
Closed

Invalid class name generated #224

Remo opened this issue Jul 7, 2021 · 2 comments · Fixed by #333
Assignees

Comments

@Remo
Copy link

Remo commented Jul 7, 2021

Describe the bug

When generating the C# classes, I get a few invalid names like MxnConfValCopyValues$ . The $ isn't a valid character for a class name.

Version of the Project affected

ODataConnectedService v0.12.1
VisualStudio Version v16.8.4
Microsoft.Odata.Client v7.9.0

To Reproduce

Create an odata service with a $ in the name of a type

<ComplexType Name="MxnConfValCopyValues$">
   <Property Name="ModifiedSource" Type="IfsApp.MxnCar.MxnConfVal"/>
</ComplexType>

and then a function like this:

<Function Name="MxnConfVal.DefaultCopy" IsBound="true">
   <Parameter Name="MxnConfVal" Type="IfsApp.MxnCar.MxnConfVal" Nullable="false"/>
   <Parameter Name="CopyValues" Type="IfsApp.MxnCar.MxnConfValCopyValues$"/>
   <ReturnType Type="IfsApp.MxnCar.MxnConfVal"/>
</Function>

Expected behavior

A working class

Actual behavior

An invalid class and code that doesn't compile.

Screenshots

image

Additional context

@SomeTroglodyte
Copy link

Or try a "-" in a field name - fails.

@SomeTroglodyte
Copy link

SomeTroglodyte commented May 4, 2022

The code does not do any sanitizing on Edm metadata before writing it into generated identifiers, specifically IEdmNamedElement.Name is only "fixed" if it matches a target language reserved word verbatim, unless it is massaged anyway (e.g. prefixing "_" for a backing field name). Except if this.context.EnableNamingAlias is on, in which case it's passed through Customization.CustomizeNaming.

I have no idea how to turn on EnableNamingAlias or provide a CustomizeNaming implementation to sanitize Edm names to valid identifier names in the GUI, I suspect that's not what it's for.

So I suggest creating a sanitizing function that reduces an arbitrary string to a valid target language identifier and call it in the vicinity of all ~40 references to CustomizeNaming, even on the output of CustomizeNaming. Might get tricky if the Name in question does not contain any character valid in identifiers and the language does not offer identifer escaping... (like [arbitrary field name] in SQL or `...funny name 😂...` in kotlin or...).

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

Successfully merging a pull request may close this issue.

4 participants