Swaggercustom
Swaggercustom
Swaggercustom
{
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
{
var customTags = new List<OpenApiTag>
{
new OpenApiTag
{
Name = "$tag-name",
Description = "$tag-description"
},
};
swaggerDoc.Tags = customTags;
}
}
public class CustomOperationFilter : IOperationFilter
{
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
// Set the operation summary, description, and response
if (context.ApiDescription.HttpMethod == "GET")
{
operation.Responses.Clear();
operation.Responses.Add("200", new OpenApiResponse
{
Description = "OK",
Content = new Dictionary<string, OpenApiMediaType>
{
{
"application/json", new OpenApiMediaType
{
Schema = new OpenApiSchema
{
Type = "object"
}
}
}
}
});
operation.Parameters.Clear();
operation.RequestBody = null;
operation.Tags = new List<OpenApiTag>();
}
}
public static class SwaggerConfig
{
public static void AddSwagger(IServiceCollection services)
{
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Version = "1.0",
Title = "$title",
Description = "$description",
Contact = new OpenApiContact
{
Name = "$name",
Email = "$email",
Url = new Uri("https://api.scm.maersk.com/${url}"),
},
License = new OpenApiLicense
{
Name = "Maersk",
Url = new Uri("https://www.api.maersk.com/licenses/LICENSE-
1.0.html"),
},
Extensions = new Dictionary<string, IOpenApiExtension>
{
["x-visibility"] = new OpenApiString("Internal"),
["x-technical-owner-email"] = new
OpenApiString("$technicalOwnerEmail"),
["x-published-for"] = new OpenApiString("Internal"),
["x-release-notes"] = new OpenApiString(""),
["x-support-l1"] = new OpenApiString(""),
["x-support-l2"] = new OpenApiString(""),
["x-support-l3"] = new OpenApiString(""),
["x-supply-chain-area"] = new OpenApiArray
{
new OpenApiString("Supply Chain Management")
},
["x-proxy-name"] = new OpenApiString("api-
preprod.scm.maersk.co"),
["x-product-owner-email"] = new
OpenApiString("$productOwnerEmail"),
["x-platform"] = new OpenApiString("Supply Chain"),
["x-oas-href"] = new OpenApiString("$href"),
["x-layer"] = new OpenApiString("System"),
["x-docs-href"] = new OpenApiString(""),
["x-deprecated-by"] = new OpenApiString("NA"),
["x-category"] = new OpenApiString("Operational"),
["x-business-owner-email"] = new
OpenApiString("$businessOwnerEmail"),
["x-brand"] = new OpenApiString(""),
["x-back-end-systems"] = new OpenApiArray
{
new OpenApiString("$backEndSystems")
},
["x-avg-data-currency-mins"] = new OpenApiInteger(0),
["x-availability-status"] = new OpenApiString("General
Availability"),
["x-api-platform"] = new OpenApiString(""),
["x-api-consumers"] = new OpenApiArray
{
new OpenApiString("CsHub")
}
}
});
c.AddServer(new OpenApiServer
{
Url = "$url-server1",
Description = "Development"
});
c.AddServer(new OpenApiServer
{
Url = "$url-server2",
Description = "Test"
});
c.DocumentFilter<CustomGlobalTagsExtension>();
c.OperationFilter<CustomOperationFilter>();
});
}
}