-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
[BUG][csharp] Incorrect property name Varlock
for lock
in generated code
#17552
Comments
ideally that should be the case but Lock seems to be a reserved word that cannot be used in other places (e.g. method name). as a workaround, can you use the name mapping option to map the property name "lock to "Lock" instead for the time being? |
The suggested workaround unfortunately does not solve the problem. |
i think it's due to the use of camelcase_param which is set to true to handle reserved word:
(in abstract csharp codegen) personally I prefer to remove {{#lambda.camelcase_param}} from the template and replace it with x-csharp-name-camelcase instead (created in postProcessModels) |
Actually, the aspnetcore generator has the same problem. This template tweak does not fix it. diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java
index 576a254cc3f..ff27be9d471 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java
@@ -1297,10 +1297,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
@Override
public String escapeReservedWord(String name) {
- if (reservedWords().contains(name) ||
- reservedWords().contains(name.toLowerCase(Locale.ROOT)) ||
- reservedWords().contains(camelize(sanitizeName(name))) ||
- isReservedWord(name) ||
+ if (isReservedWord(name) ||
name.matches("^\\d.*")) {
name = this.invalidNamePrefix + camelize(name);
} |
I'm curious why we're doing case insensitive matching? Is there a desire to maintain a case insensitive list of reserved words? |
I don't think there is any justification for implementing case-insensitive matching. |
@fujieda It was something to do how CamelCaseLambda calls the escapeReservedWord method. Sadly my PR does not go into detail about it, but I think the reason was so that the model constructor parameters can be named the same as the property casing aside. |
The issue I was fixing is specific to System.Text.Json. The parameter and related constructor parameter have to be named the same or else STJ throws an error. Newtonsoft can handle it. Instead of prefixing var on keywords like lock, I can use the @ symbol to escape the reserved word. That will allow us to revert the case insensitive matching on reserved words. |
Bug Report Checklist
Description
The csharp generator currently generates the property name
VarLock
for the propertylock
in the following definition since version 7.0.0:Generated C# code:
However, the property name
Lock
is not reserved word and should not be changed. The correct property name should beLock
.openapi-generator version
version 7.0.0 and later versions, including the latest master.
OpenAPI declaration file content or url
Generation Details
java -jar openapi-generator-cli-7.2.0.jar generate -g csharp -i simple.yaml
Related issues/PRs
#13681
The text was updated successfully, but these errors were encountered: