Skip to content
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

XML example comment does not show if has quotation mark, escaping nor unicode substitute does not solve #2088

Closed
bunda3d opened this issue Apr 13, 2021 · 1 comment · Fixed by #2727
Milestone

Comments

@bunda3d
Copy link

bunda3d commented Apr 13, 2021

Q&A

  • OS: Windows10
  • Browser: Chrome
  • Version: 89.0.4389.114 (Official Build) (64-bit) (cohort: Stable)
  • Method of installation: ASP.NET Core API Project with Swashbuckle Nuget pkg install
  • Swagger-UI version: Swashbuckle.AspNetCore.SwaggerUI (6.1.2)
  • Swagger/OpenAPI version: OpenAPI 3.0

Content & configuration

  1. Install ASP.NET Core (.net 5.0) API project template, install this swashbuckle nuget pkg.
  2. Enable XML comments for documenting the API with Swagger. (this works for everything except this quotation marks issue, so I believe it's done correctly)
  3. Add xml example tags to a data model class' string-type property that contains a quotation mark (I'm trying to use it as the annotation for "inches").
  4. optional: Add other xml example tags to other model properties that don't have the problematic quotation marks, as a control.
  5. run the project and check the swagger page's examples; while other parameters may have an example from your xml tags, the parameter with a quotation mark will just show the default "string" for text.
namespace Catalog.API.Entities
{
	public class Product
	{
		/// <example>602d2149e773f2a3990b47f5</example>
		[BsonId]
		[BsonRepresentation(BsonType.ObjectId)]
		public string Id { get; set; }

		/// <example>Tablets</example>
		public string Category { get; set; }

/** here comes the problematic tag, with the quotes after '10.5' */
		/// <example>10.5" touchscreen tablet with keyboard and stylus</example>
		public string Summary { get; set; }

		/// <example>Lorem ipsum ...</example>
		public string Description { get; set; }
/** more stuff */
	}
}

and here's what the "Example Value" looks like in the Swagger page:

{
  "id": "602d2149e773f2a3990b47f5",
  "name": "Surface Go",
  "category": "Tablets",
  "summary": "string", // not the text from the example tag
  "description": "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ut, tenetur natus doloremque laborum quos iste ipsum rerum obcaecati impedit odit illo dolorum ab tempora nihil dicta earum fugiat. Temporibus, voluptatibus. Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
  "imageFile": "product-1.png",
  "price": 490.99
}

Solution attempts

I tried escaping the quote using:

  1. &quot;
  2. U+0022
  3. and others listed here: https://unicode-table.com/en/0022/

None of those worked. I eventually settled for representing "inches" as "in" instead of using quotation mark.

Screenshots

Here's how it looks when using "in" instead of a quotation mark to indicate "inches"

image

Here's how it looks when I use a quotation mark to indicate "inches"

image

@wbaldoumas
Copy link

I am also running into this issue, specifically when trying to provide stringified JSON, for example this doesn't work at all and leads to an empty input value in the Swagger page:

<example>{"someKey": "someValue"}</example>

dldl-cmd pushed a commit to dldl-cmd/Swashbuckle.AspNetCore that referenced this issue Oct 13, 2023
Havunen added a commit to Havunen/DotSwashbuckle that referenced this issue Feb 18, 2024
@martincostello martincostello added the help-wanted A change up for grabs for contributions from the community label May 4, 2024
@martincostello martincostello added this to the v6.6.0 milestone May 6, 2024
@martincostello martincostello removed the help-wanted A change up for grabs for contributions from the community label May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants