DavidSpot Blog

Developer, super curious, a dog lover, sports fan and techie guy

Swagger CodeGen Tooling - the WSDL and Proxy Generator for REST API

I'm developing REST services for some time for at my job and the most difficult part it's when I have to make a some changes to structure of the request/response objects and this is the result of the very nature of a REST service, a call made through an HTTP Request with a meaning full URL path like http://api.uber.com/products?localtion=lisbon where you normally receive a JSON result.

Usually a use a Swagger to generate a nice documentation so that clients can easily check the service details and test if needed, here an image with an example from a generate web API description from the swagger website:

The problem with JSON, despite of being so dynamic, we lose type and with this we lose tooling and compile time errors witch are handy to catch errors earlier than in runtime.

In the traditional way, where we use SOAP services (for instance WCF from Microsoft), you can use the WSDL file to generate the client proxy witch has all the methods available in the server and with the advantage of getting strongly typed classes witch it's awesome for tooling and intellisense.

But... there's hope, the team behind the Swagger tool created a nice "WSDL and Proxy Generator" for REST API's that generate code for all this languages

And this is so cool that this even allow us to generate the Server side code as well.

You can see in the demo editor page how this works, just select one of the dropdowns (Generate Server or Generate Client), select the language/framework and that's it, you will download a complete Server API or Proxy Client in the language of your choice. You can also edit the contents of your REST Service directly in the browser

Because I'm .NET developer, I use a :NET tool called Swashbuckle that it's a development by the .net community that uses All the Swagger features for .NET.

To see a complete list of Swagger Community integrations go here

Fixing "The located assembly's manifest definition does not match the assembly reference" error with assembly binding in web.config

When developing c# apps sometimes we import and use external dll's that may have dependencies from another dll's
When you do that you might encounter an error of type "The located assembly's manifest definition does not match the assembly reference". 

For instance, In a project I'm working for I had this error:

What this means is that the framework was looking for an assembly called WebGrease with a version, but the version I have on my solution was

To fix this I added an assembly binding in web.config by forcing an old version to look for a new version (in my case the version for the WebGrease dll) as you can see in the pic below:

Doing this fixed my problem:

Hope this helps someone :)

Browsing .NET Framework Source code powered by Roslyn

If you're like me you and like to learn from the best in our fields in high hopes that one day you to can be a guru in your field, Microsoft released some time ago the source code for all .NET Framework in cool site witch is powered by the new compiler Roslyn and where you can see how the c# gurus program.

It's very useful when you trying to understand what's happening behind the scenes and learn how to code well and follow great standards, all you have to do is navigate in your browser to http://referencesource.microsoft.com/, type a class name or any .net component and explore.

For instance in the image below, I typed "String" in the search box and the string class that every .net developer utilizes shows up and it's a enormous the amount of code in a "simple" class that we use in our day-to-day dev work.

You can check a short video on how to use this tool provided by Microsoft and their team.

Kudos for the .NET team and Microsoft's change of thinking on how to deliver tools and frameworks to the dev community and embrace the open source and cross-platform world.