Description
Consider the following api model:
ErrorMessage:
type: object
required:
- error_id
- error_message
properties:
error_id:
type: string
error_message:
type: string
The C# codegen renames error_message to ErrorMessage to be consistent with codestyle.
Due to this rename, the member now conflicts with the class name, so it again renames it to _ErrorMessage.
So far so good.
The problem is then that this rename is not properly applied to all the relevant names.
Newtonsoft.Json uses the constructor argument name to match the parameter to the property.
But in the generated code, the parameter is still named errorMessage (not _errorMessage), so the parameter is left as the default value null and not deserialized:
[DataContract]
internal partial class ErrorMessage : IEquatable<ErrorMessage>
{
public ErrorMessage(string errorId = default(string), string errorMessage = default(string), string additionalDetails = default(string))
{
// Removed for brevity
}
[DataMember(Name="error_id", EmitDefaultValue=false)]
public string ErrorId { get; set; }
[DataMember(Name="error_message", EmitDefaultValue=false)]
public string _ErrorMessage { get; set; }
Swagger Codegen Version
3.0.81
Language / Generator
csharp
OpenAPI/Swagger Spec
components:
schemas:
ErrorMessage:
type: object
required:
- error_id
- error_message
properties:
error_id:
type: string
error_message:
type: string
Command Line Used
docker run --rm -v ./local:/local swaggerapi/swagger-codegen-cli-v3 generate `
-i /local/swagger.json `
-l csharp `
-o /local/out `
--additional-properties `
"targetFramework=v5.0" `
useDateTimeOffset=true `
nonPublicApi=true `
optionalAssemblyInfo=false `
optionalProjectFile=false
Steps to Reproduce
Expected Behavior
Object should deserialize
Actual Behavior
Property is empty, so constructor throws an exception (since it is marked as required).
Related Issues / Repos
Environment
- OS:
- Java Version:
- Build Tool:
- Swagger Codegen CLI version:
Additional Context
Checklist
Description
Consider the following api model:
The C# codegen renames
error_messagetoErrorMessageto be consistent with codestyle.Due to this rename, the member now conflicts with the class name, so it again renames it to
_ErrorMessage.So far so good.
The problem is then that this rename is not properly applied to all the relevant names.
Newtonsoft.Json uses the constructor argument name to match the parameter to the property.
But in the generated code, the parameter is still named
errorMessage(not_errorMessage), so the parameter is left as the default valuenulland not deserialized:Swagger Codegen Version
3.0.81
Language / Generator
csharp
OpenAPI/Swagger Spec
Command Line Used
Steps to Reproduce
Expected Behavior
Object should deserialize
Actual Behavior
Property is empty, so constructor throws an exception (since it is marked as required).
Related Issues / Repos
Environment
Additional Context
Checklist