abelsilva / swaggerwcf Goto Github PK
View Code? Open in Web Editor NEWSwagger for WCF
License: Apache License 2.0
Swagger for WCF
License: Apache License 2.0
I've completed your getting started steps and I'm getting 404 error when I try to access %address%/api-docs.
What am I doing wrong?
[SwaggerWcfResponse(HttpStatusCode.OK, typeof(ClassA)]
[SwaggerWcfResponse(HttpStatusCode.BadRequest, typeof(ClassB)]
Is something similar possible?
Is it possible to document, for example, the Apikey parameter being passed through in the header:
parameters:
- name: Apikey
in: header
description: API key
required: false
type: string
format: string
default: xxxx
SwaggerWCF v0.1.12 from Nuget fails to generate "swagger.json" file when the case related to data type - data member having Enum with short type
Hi,
I need multiple SwaggerWcfHeader on a method but i´m unable to do so.
Is there a way to do?
Thanks
a datacontract like this does not reflect the items collection:
public class ClientListResponse : ResponseBase<ClientList> { }
public class ResponseBase<T> { [DataMember] public T Body { get; set; } } public class ClientList { [DataMember] public List<ClientSummary> Clients { get; set; } }
The mapping helper adds the definition to the definitionsTypesList, but when these are built any complex type inside is not mapped.
When I have a method like this:
[OperationContract]
[SwaggerWcfPath("Gets a set of translations", "Creates a translation")]
[WebGet(
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = ""
)]
TranslationSet Get();
I see that it is shown in Swagger like this:
/gw/translations/Get
I did expect: /gw/translations to be the path. This is also the path i give to call this functionality.
likewise with Post:
How can I use swagger wcf to get or post on the main svc without sub path
Hi,
the hidefromspeec on the SwaggerWcfTag seem to don't work.
I use it on my public interface like: (vb.net)
<SwaggerWcfTag("Test_Tag", True)>
<SwaggerWcfPath("Function small desc", "function full desc")>
<WebInvoke(Method:="GET", RequestFormat:=WebMessageFormat.Json, ResponseFormat:=WebMessageFormat.Json, UriTemplate:="/test/{id}")>
<OperationContract>
Function Test_function(id As Long) As boolean
the function still appear on my list, but if I put
on my web.config it's disappear.
thank you for all your work! very nice projet
BuildSchema
has line Type t = type.GetElementType();
which results to null when type is generic List. Can be fixed with http://stackoverflow.com/a/7072121/3009578
Hello,
I have a method in my service that returns a long. In the YAML generated there is a definition for this type:
System.Int64:
type: integer
format: int64
But it is unused in the response of the operation:
responses:
'200':
description: Ok
schema:
type: integer
format: int64
This causes a warning. How could I avoid this ?
Thank you
Hi Abel, I'm interested in using SwaggerWcf for a commercial project, where we sign all our assemblies as part of a larger security scheme that we wouldn't wish to remove. At this time I am unable to even try SwaggerWcf out as I cannot build it into the project. Please consider signing the NuGet packaged assemblies (no need to expose your signing keys in the source tree) so people in my position are at least able to test ideas out :)
Many thanks,
Phil.
Nice tool, just one little request:
the following method will expose the Task as the return type, where it should get the type of 'T' and reflect that.
[OperationContract] [WebInvoke(BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "Sample/", Method = "POST")] [SwaggerWcfPath("Sample", "Post a sample")] Task<SampleType> Sample(SampleType sampleMessage);
public class AppSettings
{
public static readonly string SwaggerBaseRestURL;
static AppSettings()
{
SwaggerBaseRestURL = System.Configuration.ConfigurationManager.AppSettings["SwaggerBaseRestUrl"];
}
}
[SwaggerWcf.Attributes.SwaggerWcf(AppSettings.SwaggerBaseRestURL)] // error occurs here
Hi there,
I obtained your Swagger tool via NuGet, and managed to get it producing documentation as expected. However, I require all operations on my API to send a token in the header parameters. In addition to this is the requirement to send OAuth parameters in the headers too, however, I cannot see how to express this to your attributes.
From what I can see, it seems like its not implemented, however if it is, please could you tell me how to do it.
Many Thanks,
Alex
Hi Abel,
I open another issue since it ieasier for me to communicate via github.
Indeed, the generated swagger file does not validate with http://editor.swagger.io
File attached.
swagger.json.txt
BR,
Tomasz
In v0.1.15, calling a method that returns a content type of image/png used to render the image.
It seems to be broken in v0.1.16. As per screenshot, it looks like some broken javascript.
Looks like new swagger-ui.zip was buggy. swagger-api/swagger-ui#2470
Hi, double or decimal value appear in Model of "Data Type" as a "number", but doesn't appear in "Model Schema".
Working with integer
Hello,
I have followed the Readme instructions correctly, I believe, but swagger.json is not being generated. In IIS, our WCF service is set up as an application under Default Web Site, with a virtual path of 'AbcWebService'
In global.asax, I have the following:
RouteTable.Routes.Add(new ServiceRoute("api-docs", new ServiceHostFactory(), typeof(SwaggerWcfEndpoint)));
test quote
When I navigate to 'http://localhost/AbcWebService/api-docs', I get a page containing:
SwaggerWcfEndpoint Service
You have created a service.
To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:
svcutil.exe http://localhost/AbcWebService/api-docs?wsdl
...
Note that the above Route uses ServiceHostFactory
instead of WebServiceHostFactory
as specified in the instructions. But when I use the latter, I get a 404 with a The resource cannot be found.
message when navigating to the api-docs URL listed above.
Can you please provide any assistance in troubleshooting this issue? I can provide the other modified files if desired - just let me know.
Thanks in advance.
Hi Abel
Is there any way to arrange methods in swagger ui using attribute ?
Thanks
I've been trying to create a swagger https endpoint on my wcf service with no success. Chrome allows me to navigate to the URI and enter credentials but shows an empty page. I can create an http endpoint with no issues, but as soon as I attempt to go https I get an empty page. I have a main https endpoint on port 8129 and am trying to get a swagger endpoint on port 8131 - i'm guess my config file isn't quite right. Any suggestions would be appreciated, my app.config is roughly:
<service name="SwaggerWcf.SwaggerWcfEndpoint">
<endpoint address="docs" binding="webHttpBinding" contract="SwaggerWcf.ISwaggerWcfEndpoint"
behaviorConfiguration="swagger" bindingConfiguration="FileManagerBinding"/>
<host>
<baseAddresses>
<add baseAddress="https://mycomputer:8131"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServerServiceBehavior">
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" httpsGetUrl="" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Wti.Enterprise.Server.UserAuthentication,Wti.Enterprise.Server" />
<!-- <clientCertificate>
<authentication certificateValidationMode="PeerOrChainTrust"/>
</clientCertificate>
<serviceCertificate findValue="123" storeLocation="LocalMachine"
storeName="My" x509FindType="FindByThumbprint"/> -->
</serviceCredentials>
<serviceAuthorization principalPermissionMode="Custom">
<authorizationPolicies>
<add policyType="Wti.Enterprise.Server.AuthorizationPolicy,Wti.Enterprise.Server" />
</authorizationPolicies>
</serviceAuthorization>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="MyEndpointBehavior">
<!--
<endpointDiscovery enabled="true">
</endpointDiscovery>
-->
</behavior>
<behavior name="web">
<webHttp />
</behavior>
<behavior name="web2">
<webHttp />
</behavior>
<behavior name="swagger">
<webHttp automaticFormatSelectionEnabled="true" />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
Hi,
thanks for your great job.
Is it possible to have the hability to param the host of api sample.
Replace http://localhost/myapiendpoint by something else.
Or at least have api sample host equal to api doc host
Thanks
Hi, and thanks for this great work !
I was just wondering if there was a way to define the base URL of the project.
For instance, I've deployed my service on http://localhost/API/ but the docs considers it was deployed to http://localhost.
Thank you.
Stéphane S.
Hi there,
I'm not sure why, but if you omit the base path property, the swagger stuff formulates the call with the full URL (I can't see where to stop this from happening.) So when you add the BasePath property, it is being prepended to an already absolute URI (certainly for the test harness which fails when you try to invoke an operation.)
Kind Regards,
Alex
Swagger v0.1.10 from Nuget fails to generate "swagger.json" file in case if an operation contract's parameter is of list type and parameter's name cannot be found in an uri template.
Actually, I am not sure if it is right to check the presence of every parameter name in the uri at all because some request methods can take parameter's contents from body (for example, "POST").
I've created a separate repository with a solution to reproduce the issue: https://github.com/andriibratanin/SwaggerWcfBug
Hey together,
at first of all: Thank you so much for SwaggerWcf! It makes my work with wcf so much easier!
My Question/Issue:
Is it planned, to implement the oauth security definition of swagger 2.0? And if not: Can I help, to implement it? It's very important to me and I am able to help you out
Thank you so much!
René
Hello,
I've implemented SwaggerWcf in my project but I cannot solve a HTTP 404 file not found issue when opening http://localhost:58564/api-docs/index.html?url=http://localhost:58564/api-docs/swagger.json.
Is there a way to debug the issue? Thanks!
Hi Team,
I have implemented SwaggerWcf in my WCF service project via NuGet. It works. I need to send access token for my services in header parameters. But I don't know how to achieve this. Could you please help me on this?
If you can provide any working sample it will be appreciated. Many thanks.
Kind Regards
Senthil
WCF supports defining optional path variables (i.e. path variable with an optional argument), however this appears to be incorrectly interpreted as a 'body' parameter type instead of an optional 'path' parameter type. Also, the generated URL is incorrect.
MSDN refrence.. https://msdn.microsoft.com/en-us/library/bb675245(v=vs.110).aspx
Example..
[WebGet(UriTemplate = "/race/{raceKey}/silks/{acceptorKey=null}?width={width}&height={height}", ResponseFormat = WebMessageFormat.Json)]
Task<Stream> GetRaceSilks(string raceKey, string acceptorKey = null, string width = null, string height = null);
Issues marked in red..
Hi Abel,
I think I've found a bug when using the WebMessageBodyStyle.Wrapped attribute on a WebInvoke method with multiple request parameters - the generated swagger path element contains multiple body parameters (illegal according to the specification) eg a method declared via an interface as:
[WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
bool CheckCredentials(
string AccountName,
string Password);
produces the following swagger declaration:
"/TestService/CheckCredentials": {
"post": {
"operationId": "TestService.CheckCredentials",
"consumes": ["application/json"],
"produces": ["application/json"],
"parameters": [{
"name": "AccountName",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/System.String"
}
},
{
"name": "Password",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/System.String"
}
}],
...
I think (according to the scant information I can find on MSDN / StackOverflow) WCF expects the Wrapped attribute to implicitly generate a new object containing the multiple parameters as named fields: http://stackoverflow.com/questions/20206069/restful-web-service-body-format
Cheers,
Phil.
Hi Abel,
I want to know. If it possible to change the templates and the configuration of Swagger in the package.
I look in the project and the templates for swagger seems to be locked inside the package. There is anyway that I can do this changing a property in the config file?
I want to achieve a more integrated swagger, online documentation using mds. I have a working example in java. But, I need to modify the templates of swagger for achieve that.
Could you give some hints for achieve this.
Kind regards,
I tried doing it the service way using config
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
<serviceActivations>
<add relativeAddress="api.svc" service="SwaggerWcf.SwaggerWcfEndpoint" factory="System.ServiceModel.Activation.ServiceHostFactory"/>
</serviceActivations>
</serviceHostingEnvironment>
But all I get when routing to api.svc is a default Metadata publishing for this service is currently disabled page.
schema.Required is null
Hi Abel,
I need to add manually the model scheme for the response. The project do not have a DataContract associated because it is not necessary. I was checking the implementation and I think the Mapper.cs in Support is the one in charge of the retrospection in the object.
Currently, the schemes definition in the GetResponseCodes is getting null in my case no DataContract associated.
It is possible to add a new tag for Rest to emulate the DataContract and the DataMember or pass the scheme definition as a SwaggerTag?
I think if you guide I can implement that extra tag so, the implementation with REST calls without DataContract can be resolved too.
Thanks for your help.
Kind regards,
Juan
Hello,
When you try swagger.json file with Microsoft Power Apps, it throws validation message for Host missing. I did fixed that in the code but you may want to apply that in the main branch.
Regards,
Kiran Chauhan
Hello, I'm triyng to add Swagger to my wcf service with Ninject, but have problem.
What I did with SwaggerWcf.Test.Service:
Install-Package Ninject.Extensions.Wcf
public class Global : NinjectHttpApplication
{
protected override void OnApplicationStarted()
{
base.OnApplicationStarted();
RegisterRoutes();
}
private void RegisterRoutes()
{
RouteTable.Routes.Add(new ServiceRoute("v1/rest", new NinjectServiceHostFactory(), typeof(BookStore)));
RouteTable.Routes.Add(new ServiceRoute("api-docs", new NinjectServiceHostFactory(), typeof(SwaggerWcfEndpoint)));
}
protected override IKernel CreateKernel()
{
return new StandardKernel(new ServiceModule());
}
}
public class ServiceModule : WcfModule {}
At this point I get "Endpoint does not have a Binding with the None MessageVersion" for both http://localhost:52331/v1/rest and http://localhost:52331/api-docs
I add
<services>
<service name="SwaggerWcf.Test.Service.BookStore">
<endpoint binding="webHttpBinding" contract="SwaggerWcf.Test.Service.IStore" />
</service>
<service name="SwaggerWcf.SwaggerWcfEndpoint">
<endpoint binding="webHttpBinding" contract="SwaggerWcf.ISwaggerWcfEndpoint" />
</service>
</services>
This work with sample, but in my service http://localhost:52331/api-docs/index.html returns 404 because of WCF REST parameters cannot contain periods.
Hi,
suggest to make sure generated swagger can be used as VS "REST API Client" generator installed as add-in with Azure SDK.
https://github.com/Azure/autorest/
preferably the initial version 0.9.6, since this one is still being distributed with Azure SDK although the tool is not Azure dependent/specific.
It looks like there are some compatibility issues, MS "AutoRest Code Generator" does not produce any output based on swagger output from your tool.
Output from MS recommended swagger tools https://github.com/domaindrivendev/Swashbuckle seems to be ok. However, is Web API tool, not WCF.
See: https://azure.microsoft.com/en-us/blog/announcing-the-azure-sdk-2-7-for-net/
"Positive Impacts of Template Swagger Tweaks for Client Developers" section.
Kind regards,
Tomasz
Hey Abel,
I came across your implementation of Swagger for WCF and have managed to get it working on our solution (we have a handrolled solution for documentation at the moment and need to move towards swagger).
The only issue I came across is that the SwaggerWcfEndpoint implementation uses “/swagger.json” as the UriTemplate and I finally realised that this was what was causing the swagger output to be inaccessible in our API.
As soon as I got your code running inside our solution and could debug through it I changed the URL to “/swagger” and it worked perfectly. (we actually can't access the UI component hosted at the other endpoint in ISwaggerWcfEndpoint.cs but don't need to use it so it's not causing an issue).
I believe this is down to how WCF routing can pick up specific urls or ignore others, I did find an article that semi explained it but I seem to have lost it.
So I’m just wondering whether this is something you would consider either changing (/swagger.json) or to allow it to be configurable by the user ( happy to try and solve this and do a PR)?
Consider the following example function:
[OperationContract]
[WebInvoke(UriTemplate = "patients/check", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
Patient ApiCheckPatient(Patient patient);
As you can see "patient" is not a parameter in the Uri, but the text "patient" is partially contained, and, since Mapper.GetInType only checks the parameter name, is wrongly marked as "InType.Path".
Please, consider adding braces "{}" when searching the Uri for parameter placeholders.
The types contained in a collection aren't mapped the same way as property types. For example, when a string property is processed, it's displayed as simply "string" but when a collection of strings is encountered, it's shown as "System.String", and that is unnecessarily listed as an inline type.
Ideally, IMO, this would read "Segments ([string]):" (i.e., JS array notation) or, to be more explicit, "Segments (Array[string]):"
I'm not immediately sure how to improve this, though. I was thinking that DefinitionsBuilder.ProcessProperties
should be calling Helpers.MapSwaggerType
instead of using the type directly (prop.Items.Ref = t.FullName
), but that's going to require passing around the definitions list in several more places. I tinkered with it, but ended up with "Inline Type 1" instead.
Hi Abel,
We wanted to document our WCF RESTFul service with your Swagger WCF, but we encounter the following issue.
When in WebInvoke attribute of operation in our WCF service we set BodyStyle to WebMessageBodyStyle.WrappedRequest (or anything different from Bare), we get Bad Request Error.
We would like to know whether it is possible to make work the SwaggerWCF with this type of body? And how it can be achieved?
Regards,
Aleksander
Hi, is there a way for adding the required authorizations to be included in the Swagger JSON?
Like BasicAuth
Hi, I just tried to use your service component.
Three issues I discovered so far:
Best regards,
Tomasz
Following setup and navigating to http://localhost:58170/api-docs receive below error. Any ideas how to investigate further? i.e server logs location?
The server encountered an error processing the request. The exception message is 'Object reference not set to an instance of an object.'. See server logs for more details. The exception stack trace is:
at SwaggerWcf.Support.Serializer.Process(Service service) at SwaggerWcf.SwaggerWcfEndpoint.GetSwaggerFile() at SyncInvokeGetSwaggerFile(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.