0% found this document useful (0 votes)
11 views3 pages

Swaggercustom

Download as txt, pdf, or txt
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 3

public class CustomGlobalTagsExtension : IDocumentFilter

{
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.Summary = "Get Jira Proxy";


operation.Description = "Get Jira Proxy";
operation.OperationId = "GetJiraProxy";
}
else if (context.ApiDescription.HttpMethod == "POST")
{
operation.Summary = "Post Jira Proxy";
operation.Description = "Post Jira Proxy";
operation.OperationId = "PostJiraProxy";
}
else if (context.ApiDescription.HttpMethod == "PUT")
{
operation.Summary = "Put Jira Proxy";
operation.Description = "Put Jira Proxy";
operation.OperationId = "PutJiraProxy";
}
else if (context.ApiDescription.HttpMethod == "DELETE")
{
operation.Summary = "Delete Jira Proxy";
operation.Description = "Delete Jira Proxy";
operation.OperationId = "DeleteJiraProxy";
}

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>();
});

}
}

foreach (var path in swaggerDoc.Paths.Values)


{
foreach (var operation in path.Operations.Values)
{
operation.Tags = new List<OpenApiTag> { globalTag };
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy