Repository navigation
Description
Situation
I'm trying to implement the ignore formatting documentation for the following code:
[HttpDelete("{id:int:min(1)}/something")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[SwaggerResponse(StatusCodes.Status400BadRequest, typeof(ProblemDetails), Description = "Will be returned validation fails in this API")]
[SwaggerResponse(StatusCodes.Status400BadRequest, typeof(HttpValidationProblemDetails), Description = "Will be returned validation fails in a downstream API")]
[ProducesDefaultResponseType]
public async Task<ActionResult> SomeMethodNameGoesHere(
int id,
ALongModelNameThatIsReallyLong requestModel
)
{
await Task.CompletedTask;
return NoContent();
}Problem
I would like to forbid csharpier from formatting the SwaggerResponse attributes because it ends up being very unreadable in the context of an API action:
[HttpDelete("{id:int:min(1)}/something")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[SwaggerResponse(
StatusCodes.Status400BadRequest,
typeof(ProblemDetails),
Description = "Will be returned validation fails in this API"
)]
[SwaggerResponse(
StatusCodes.Status400BadRequest,
typeof(HttpValidationProblemDetails),
Description = "Will be returned validation fails in a downstream API"
)]
[ProducesDefaultResponseType]
public async Task<ActionResult> SomeMethodNameGoesHere(
int id,
ALongModelNameThatIsReallyLong requestModel
)
{
await Task.CompletedTask;
return NoContent();
}It's just way too many lines of metadata until you get to the meat and potatoes of the API action. My thoughts are that if someone wants to read the SwaggerResponseType description, they can simply scroll a bit.
Current solution
It is already possible to ignore the formatting by doing this:
// csharpier-ignore - Csharpier ends up formatting this into multiple lines which causes too much noise
[SwaggerResponse(StatusCodes.Status400BadRequest, typeof(ProblemDetails), Description = "Will be returned validation fails in this API")]
// csharpier-ignore - Csharpier ends up formatting this into multiple lines which causes too much noise
[SwaggerResponse(StatusCodes.Status400BadRequest, typeof(HttpValidationProblemDetails), Description = "Will be returned validation fails in a downstream API")]However, I am not satisfied with having to copy multiple lines:
// csharpier-ignore - Csharpier ends up formatting this into multiple lines which causes too much noisebecause it still causes too much noise.
Ideal solution
The docs mention that you can use // csharpier-ignore-start and //csharpier-ignore-end.
I would love to be able to do this:
// csharpier-ignore-start - Csharpier ends up formatting this into multiple lines which causes too much noise
[SwaggerResponse(StatusCodes.Status400BadRequest, typeof(ProblemDetails), Description = "Will be returned validation fails in this API")]
[SwaggerResponse(StatusCodes.Status400BadRequest, typeof(HttpValidationProblemDetails), Description = "Will be returned validation fails in a downstream API")]
// csharpier-ignore-endI would like to be able to place the // csharpier-ignore-start at the start or 2nd/3rd/etc.. attribute, and // csharpier-ignore-end after the next (few) attributes or the final one, like the way my example works.
I'd like to submit this proposal and know your thoughts! :)
Activity
belav commentedon Nov 9, 2023
@sander1095 I'll have to dig into to see how feasible this is. The ranged ignore can be problematic sometimes. In this case I believe the
// csharpier-ignore-startis leading trivia on an attribute, and the corresponding// csharpier-ignore-endcould be leading trivia on the modifiers, or on another attribute.