Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lockewritesdocs
Copy link

@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.

…This information could be useful if people want to create a swagger.json file to serve to a static site generator.
@heldersepu
Copy link
Contributor

heldersepu commented Jun 8, 2017

Why not just create a wiki:
https://github.com/domaindrivendev/Swashbuckle/wiki/6-Tutorials

I don't think we need a PR for this. At the moment wikis are open to all

);

var swaggerString = JsonConvert.SerializeObject(
swaggerDoc,
Copy link

@safv12 safv12 Oct 11, 2017

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!

Copy link
Author

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.

Copy link

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?

Copy link
Contributor

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?

Copy link

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.

Copy link
Contributor

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)

Copy link

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!

Copy link
Contributor

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

Copy link
Author

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

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @lockewritesdocs :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants