-
Notifications
You must be signed in to change notification settings - Fork 677
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
Adding a description of how I integrated Swashbuckle with DapperDox #1107
base: master
Are you sure you want to change the base?
Conversation
…This information could be useful if people want to create a swagger.json file to serve to a static site generator.
Why not just create a wiki: I don't think we need a PR for this. At the moment wikis are open to all |
1b3dcfa
to
0996fa3
Compare
); | ||
|
||
var swaggerString = JsonConvert.SerializeObject( | ||
swaggerDoc, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lockewritesdocs where was the swaggerDoc variable defined?
Regards!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@safv12, honestly, I don't recall. I changed jobs and do not work with Swashbuckle at all anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@domaindrivendev @heldersepu someone knows how to export the swagger.json file?
Or where is this variable defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@safv12
As far as I know there is no such an option, you could create an IDocFilter that could do that...
Why do you want to export the file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@heldersepu thanks for your prompt reply.
I want to export the json file because I have a set of separate microservices in different projects. Each of these projects has its own auto-documentation with Swashbuckle.
I want to put all the files together in a single container with dapperDox every time the project is built in the CI process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not modify the source of DapperDox to retrieve the swagger doc directly from the microservices?
I think that is a better option, and DapperDox is OpenSource, I think that everyone will benefit from that enhancement. (it might be simple to code that change)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because my microservices are into a private VPC and their methods are exposed through an API Gateway of amazon.
But I think I can try something like that. Thank you so much @heldersepu
Regards!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@safv12 no problem if you have any problem implementing that reach out directly on hangouts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@safv12, here is a code sample that I have from my old notes.
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Web.Http;
using Newtonsoft.Json;
using Swashbuckle.Application;
using Swashbuckle.Swagger;
using Swashbuckle.Swagger.Annotations;
using Swashbuckle.Swagger.XmlComments;
namespace MyWebAPI.Swagger
{
public static class GenerateSwaggerFile
{
public static void Generate(HttpConfiguration config)
{
config.EnsureInitialized();
var swaggerProvider = new SwaggerGenerator(
config.Services.GetApiExplorer(),
config.Formatters.JsonFormatter.SerializerSettings,
new Dictionary<string, Info>
{
{
"v1",
new Info
{
version = "v1",
title = "MyWebAPI",
description = "Provides an interface between my service and a
third-party service."
}
}
},
new SwaggerGeneratorOptions(
schemaIdSelector: (type) => type.FriendlyId(true),
modelFilters: new List<IModelFilter>() {
new ApplyXmlTypeComments(typeof(Program).Assembly.GetName().Name + ".XML")
},
conflictingActionsResolver: (apiDescriptions) => apiDescriptions.GetEnumerator().Current,
schemaFilters: new List<ISchemaFilter>() { new ApplySwaggerSchemaFilterAttributes() },
operationFilters: new List<IOperationFilter>() {
new ApplyXmlActionComments(typeof(Program).Assembly.GetName().Name + ".XML"),
new ApplySwaggerResponseAttributes()
}
)
);
var swaggerDoc = swaggerProvider.GetSwagger(ConfigurationManager.AppSettings["BaseAddress"], "v1");
var swaggerString = JsonConvert.SerializeObject(
swaggerDoc,
Formatting.Indented,
new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
Converters = new[] { new VendorExtensionsConverter() }
}
);
var file = new StreamWriter("swagger.json");
file.WriteLine(swaggerString);
file.Close();
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @lockewritesdocs :)
@heldersepu, please review this information, which solves issue #1105.
This information could be useful if people want to create a swagger.json file to serve to a static site generator.