OpenAPITools / OpenAPITools/openapi-generator

[BUG][C#] Generated code documentation does not match the JSON

Open
#2,447 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: C-Sharp Issue: Bug Swagger-Parser
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Hi guys,

I've got an issue I didn't have with the swagger-codegen (or even earlier versions of openapi-generator but I can't be sure about the version though), I have models that inherit from an abstract class that contains (among other things) a complex object, here is the corresponding JSON extract (which is valid I believe) :

  "definitions": {
    "Error": {
      "description": "Contains all the information related to an error which has occured.",
      "type": "object",
      "properties": {
        "resultcode": {
          "description": "Specifies the last result status provided by the API.",
          "enum": [
            "OK",            
            ...            
            "InvalidAPIKey"
          ],
          "type": "string",
          "readOnly": true
        },
        "extResultStatus": {
          "description": "Specifies a result code related to an error which occured in an external component.",
          "type": "string",
          "readOnly": true
        },
        "extResultMessage": {
          "description": "Specifies a message which further describes the error.",
          "type": "string",
          "readOnly": true
        },
        "internalErrorId": {
          "description": "Specifies a unique identifier, allowing to easily assess the error.",
          "type": "string",
          "readOnly": true
        }
      }
    },    
    ...
    "ActionResponse": {
      "description": "Represents the response to the action request.",
      "type": "object",
      "properties": {
        "Error": {
          "$ref": "#/definitions/Error",
          "description": "If not null, provides information about an unsuccessful action."
        },
        "RemainingTokens": {
          "format": "int64",
          "description": "Specifies the number of remaining tokens.",
          "type": "integer"
        },
        "Data": {
          "format": "byte",
          "description": "Specifies the data.",
          "type": "string",
          "readOnly": true
        }
      }
    }
  }

And now here is the corresponding generated C# (using the csharp generator with the latest snapshot from today, March 19th, default options). First the ActionResponse class:

/// <summary>
/// Initializes a new instance of the <see cref="ActionResponse" /> class.
/// </summary>
/// <param name="error">error.</param>
/// <param name="remainingTokens">Specifies the number of remaining tokens..</param>
public ActionResponse(Error error = default(Error), long? remainingTokens = default(long?))
{
    this.Error = error;
    this.RemainingTokens = remainingTokens;
}

/// <summary>
/// Gets or Sets Error
/// </summary>
[DataMember(Name="Error", EmitDefaultValue=false)]
public Error Error { get; set; }

/// <summary>
/// Specifies the number of remaining tokens.
/// </summary>
/// <value>Specifies the number of remaining tokens.</value>
[DataMember(Name="RemainingTokens", EmitDefaultValue=false)]
public long? RemainingTokens { get; set; }

/// <summary>
/// Specifies the data of the saved document.
/// </summary>
/// <value>Specifies the data of the saved document.</value>
[DataMember(Name="Data", EmitDefaultValue=false)]
public byte[] Data { get; private set; }       

even though the Error class itself is properly documented in the Error.cs

/// <summary>
/// Contains all the information related to an error which has occurred.
/// </summary>
[DataContract]
public partial class Error : IEquatable<Error>, IValidatableObject
{
}

Previously, the Error member of the ActionResponse would have the same documentation as the Error definition, i.e. <summary>Contains all the information related to an error which has occurred.</summary> instead of summary>Gets or Sets Error</summary>
Of course this is only an example to illustrate the issue, the API is much larger and complex so we find this problem in many other places but hopefully you get the idea.

Any idea what has changed and could have caused this?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing the generated ActionResponse class with Error.cs and the supplied JSON definitions. Trace how the C# generator chooses documentation for the Error member, then check whether generated member documentation preserves the referenced Error description rather than the generic property text. Done means the generated C# documentation matches the schema descriptions consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.