swagger-api / swagger-api/swagger-codegen
[CSharp] "Failed to load API definition" when use Description attribute
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");
}

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

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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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