francis
September 27, 2025, 9:00pm
1
Hi,
I use ServiceStack & ServiceStack.AspNetCore.OpenApi 8.8.0 and Swashbuckle.AspNetCore 9.04 in a NetCore 9 app.
I have the following ConfigureOpenApi : IHostingStartup setup (simplified):
public void Configure(IWebHostBuilder builder)
{
builder.ConfigureServices((context, services) =>
{
services.AddSwaggerGen(options =>
{
options.EnableAnnotations(enableAnnotationsForInheritance: true, enableAnnotationsForPolymorphism: false);
}
services.AddServiceStackSwagger();
}
}
The issue I am having is I am unable to hide specific properties of a request class in swagger.json. I need the class to be visible in swagger, just not all properties (but they do need to be serialized).
The request class has [Api], [Tag] and [Route] attributes.
I tried [SwaggerIgnore], [ServiceStack.DataAnnotations.ExcludeMetadata], removing [APIMember], and various SchemaFilter attempts to no avail. I spent hours on this. This shouldn’t be complicated. Maybe I’m too dumb.
Any recommendations?
Thanks.
mythz
September 28, 2025, 1:30am
2
When using Swagger v3 you’re using Swashbuckle instead of ServiceStack Swagger UIs, so any customization and configuration needs to be done on Swashbuckle.
A quick search of google brought up this thread:
opened 07:06AM - 29 Mar 18 UTC
closed 08:55AM - 08 Feb 20 UTC
I have a property that I want to serialize but dont want it visible in Swagger.
…
Example.
public long Id { get; set; }
Things I tried
1. Internal - doesnt work because i need to access the property somewhere.
2. These decorator [IgnoreDataMember], [JsonIgnore], [XmlIgnore] - doesnt work. I need the property to be serializable.
Any help?
Thanks.
Which suggests you can use [JsonIgnore] or [Obsolete], I’ve had a quick test and appears both work.
francis
September 28, 2025, 10:15pm
3
mythz:
[JsonIgnore]
Thanks, but none of that works. I see that people have complained on github but nothing was deno. Swashbuckle sucks.
mythz
September 29, 2025, 2:02am
4
Weird, when I tried both worked for me, i.e. the annotated properties were removed from the Schema in Swagger UI.
I created a repo that shows it is not working as expected.
Test solution to debug Swashbuckle.AspNetCore
mythz
October 3, 2025, 2:18am
6
I’ve just added a change in the latest v8.8.1 pre-release packages which should now ignore properties annotated with [SwaggerIgnore].
That worked–thanks!
I believe the same issue exists for the Restrict() decorator. I am unable to hide PerformanceBase class from swagger.
I tried:
[Restrict(VisibilityTo = RequestAttributes.None)]
[SwaggerSchema(ReadOnly = true)]
[Swashbuckle.AspNetCore.Annotations.SwaggerSchema(ReadOnly = true)]
mythz
October 3, 2025, 4:26pm
8
You should be able to exclude APIs from metadata APIs and pages with [Exclude(Feature.Metadata)].
The problem with that attribute is it also hides the top class.
class TopClass: InheritedClass{}
[Exclude(Feature.Metadata)]
public class InheritedClass{}
Result is TopClass is also hidden from swagger (not the desired result–I only want to hide InheritedClass)
mythz
October 3, 2025, 5:07pm
10
This should only be annotated on API Request DTOs and Request DTOs should not inherit other Request DTOs.