swagger-api / swagger-api/swagger-codegen

[CSharp] "Failed to load API definition" when use Description attribute

Open
#8,728 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description
I found the bug when swaggergen can't create json when I use Description attribute for class properties:

public class Locale
{
public Locale()
{
}

    public Locale(string cultureCode, string countryCode)
    {
        CultureCode = cultureCode;
        CountryCode = countryCode;
    }

    [JsonProperty("cultureCode")]
    [Description("Language code")]
    public string CultureCode { get; set; }

    [JsonProperty("countryCode")]
    [Description("Country code")]
    public string CountryCode { get; set; }

    public string Name => $"{CultureCode}-{CountryCode}";

    public static Locale Fr => new Locale("fr", "FR");
}

image

If I delete Description attributes it will work:

public class Locale
{
public Locale()
{
}

    public Locale(string cultureCode, string countryCode)
    {
        CultureCode = cultureCode;
        CountryCode = countryCode;
    }

    [JsonProperty("cultureCode")]
    public string CultureCode { get; set; }

    [JsonProperty("countryCode")]
    public string CountryCode { get; set; }

    public string Name => $"{CultureCode}-{CountryCode}";

    public static Locale Fr => new Locale("fr", "FR");
}

Configuration
image

Suggest a fix/enhancement
I suppose its bound with the existence of a construction like this one: "public static Locale Fr => new Locale("fr", "FR");"

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 reproducing the failure with the Locale class, its Description attributes, and the static Fr property, then trace swaggergen's schema handling for C# properties and fields. Done means the API definition generates successfully for this model and the property descriptions are handled without the load error.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.