Comments (12)
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.
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.
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.
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.
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.
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.
You could just add the output dll as reference to your project, no need to publish a nuget.
(the old fashion way ;)
from swaggerwcf.
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.
Hi Abel,
I was checking the nuget and I think the update is not yet available.
Could you please check this again.
Kind regards,
Juan
from swaggerwcf.
yes, you are right, my mistake, it should be online in a few minutes now
from swaggerwcf.
assuming it worked.
reopen the ticket if needed
from swaggerwcf.
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)
- ServiceContract Attribute
- swagger.json file loses details over time HOT 1
- swaggerwcf CPU 100%
- Models NameSpaces.Class but I want just CLass HOT 3
- Request Error while access external models as parameters
- Swaggerwcf doesn't support ServiceContracts with the same methodsname.
- SwaggerWCF issue with routes and yaml HOT 1
- Adding Basic Authentication
- Adding project as a reference - failed to parse JSON/YAML response
- Unclear instuction WebServiceHost / Self Host HOT 3
- returning multiple types
- Generate multiple-files based on different WCF classes or tags HOT 2
- Request URL HOT 1
- URL issue
- In IIS , response body as "no centent" for swaggerWCF HOT 1
- NullReferenceException on GetEnumDescription
- Enum return value not included in definitions
- How to get Swagger json inside my API ?
- Setting an example value when there's an object on GET method
- ProcessProperty() of TypePropertiesProcessor.cs not handling IList type, Solution here.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swaggerwcf.