GithubHelp home page GithubHelp logo

Comments (12)

abelsilva avatar abelsilva commented on August 26, 2024 1

Hi

Pushed a new version, you customize the interface using one of the following options:

1 - Custom ZIP file - provide a stream of the zip file to SwaggerWcfEndpoint

            Assembly assembly = Assembly.GetAssembly(GetType());
            Stream zipStreamCustom = assembly.GetManifestResourceStream("SwaggerWcf.www.MyCustomSwaggerUI.zip");
            SwaggerWcfEndpoint.SetCustomZip(zipStreamCustom);

2 - Override individual files using a custom deledate function

            SwaggerWcfEndpoint.SetCustomGetFile((string filename, out string contentType, out long length) =>
                                                {
                                                    if (filename == "logo.png")
                                                    {
                                                        using (FileStream file = File.OpenRead("myCompanyLogo.png"))
                                                        {
                                                            contentType = "image/png";
                                                            length = file.Length;
                                                            return file;
                                                        }
                                                    }

                                                    contentType = null;
                                                    length = -1;
                                                    return null;
                                                });

Let me know if this works for you

Thanks
Abel

from swaggerwcf.

abelsilva avatar abelsilva commented on August 26, 2024

Hi

The zip file is the swagger-ui release from some time ago.
When building, it goes bundled inside the dll to be more easy to handle (one less file).

It would be possible to add a check to verify if there is a zip file on the folder (not embedded) and use that instead (giving it more priority).

In this case you would just need to prepare the zip with your contents and place it in the dll folder.
It would also be possible to search for files on both zips. In case you just want to customize a few files, you don't need to add a zip with the full swagger-ui release.

Do you think this would help?

Thanks
Abel

from swaggerwcf.

J4S0Nc avatar J4S0Nc commented on August 26, 2024

Could you do something like swashbuckle and make this configurable? They allow you to embed a file in your own dll then they call the CustomAsset method:

.EnableSwaggerUi("help/ui/{*assetPath}", c =>
{
      c.CustomAsset("index", typeof(SwaggerConfig).Assembly, "MyNamespace.MyCustomDocs.html");
});

In this example I have a file called "MyCustomDocs.html" marked as an embedded resource in my project. This file is modified version of the swaggerUI index file.

from swaggerwcf.

gabrielacosta avatar gabrielacosta commented on August 26, 2024

Thanks for your help. Could you give more information, how to add the check for the zip file. I was looking in adding a resource file. https://msdn.microsoft.com/en-us/library/7k989cfy(VS.80).aspx

However, I not quite sure is the proper approach and if the compiler will look into my file.

I was checking J4S0nc comment, but in this case I don't have a Swagger.config file to modify.
http://www.wmpratt.com/swagger-and-asp-net-web-api-part-1/
So, I'm quite lost going that path.

from swaggerwcf.

J4S0Nc avatar J4S0Nc commented on August 26, 2024

The previous code example is for swashbuckle, not this project. I'm suggesting modified this code base to support some type of custom asset configuration similar to that example.

If you want a quick hack it looks like you could just change the \SwaggerWcf\Support\StaticContent.cs file to look at a file path before looking at the resources, something like this (untested):

        static StaticContent()
        {
            try
            {
                if (File.Exists("MyCustomZip.zip"))
                {
                    using (var s = File.OpenRead("MyCustomZip.zip"))
                    {
                        Archive = new ZipArchive(s);
                        return;
                    }
                }
                Assembly assembly = Assembly.GetAssembly(typeof(StaticContent));
                Stream zipStream = assembly.GetManifestResourceStream(ZipFileName);

                if (zipStream == null)
                    return;

                Archive = new ZipArchive(zipStream);
            }
            catch
            {
            }
        }

from swaggerwcf.

gabrielacosta avatar gabrielacosta commented on August 26, 2024

Hi J4S0Nc,

I just follow your advice, but I modified the code a little bit and it works fine.

public class StaticContent
    {
        private const string ZipFileName = "SwaggerWcf.www.swagger-ui.zip";
        private const string ZipFileNameCustom = "SwaggerWcf.www.MyCustomSwaggerUI.zip";
        private static readonly ZipArchive Archive;

        static StaticContent()
        {
            try
            {
                Assembly assembly = Assembly.GetAssembly(typeof(StaticContent));
                Stream zipStreamCustom = assembly.GetManifestResourceStream(ZipFileNameCustom);

                if (zipStreamCustom == null)
                {
                    Stream zipStream = assembly.GetManifestResourceStream(ZipFileName);
                    if (zipStream == null)
                        return;
                    Archive = new ZipArchive(zipStream);
                }
                else {
                    Archive = new ZipArchive(zipStreamCustom);
                }
                    return;               
            }
            catch
            {
            }
        }

I just need to package again the SwaggerWcf as nuget library and import it in my project. It is that the procedure. Or I have to bring the entire project and added as an existent project.

Which one is the best approach.

By the way abelsilva, how you convert this solution to a nuget package?

Kind regards,

Juan

from swaggerwcf.

J4S0Nc avatar J4S0Nc commented on August 26, 2024

You could just add the output dll as reference to your project, no need to publish a nuget.
(the old fashion way ;)

from swaggerwcf.

abelsilva avatar abelsilva commented on August 26, 2024

Hi Juan

I'll add the feature to SwaggerWcf and push a new version to nuget.org.

In case you want to implement custom changes, you have two options:

  • like J4S0Nc said, just build SwaggerWcf and use the output dll in your project
  • build a new nuget package and put it in a folder on your system (or shared folder for the company) and configure nuget.config with that folder as source

from swaggerwcf.

gabrielacosta avatar gabrielacosta commented on August 26, 2024

Hi Abel,

I was checking the nuget and I think the update is not yet available.

image

Could you please check this again.
Kind regards,
Juan

from swaggerwcf.

abelsilva avatar abelsilva commented on August 26, 2024

yes, you are right, my mistake, it should be online in a few minutes now

from swaggerwcf.

abelsilva avatar abelsilva commented on August 26, 2024

assuming it worked.

reopen the ticket if needed

from swaggerwcf.

orphee avatar orphee commented on August 26, 2024

Thanks for this upgrade, very usefull.
However, after hours of research, I just find out why it did'nt work for me.
I had to remove the "using" syntax, because stream is no more readable after the return statement

using (FileStream file = File.OpenRead("myCompanyLogo.png"))
{
contentType = "image/png";
length = file.Length;
return file;
}

I just made this change and everything forks fine !
In my case ,

if (filename == "images/logo_small.png")
{
FileStream file = File.OpenRead(System.AppDomain.CurrentDomain.BaseDirectory.ToString() + "CustomContent/logo.png");

                   contentType = "image/png";
                   length = file.Length;
                   return file;

          }

from swaggerwcf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.