A Visual Guide to What's New in Swagger 3.0
blog.readme.io
blog.readme.io
Swagger 2 (current version) got really popular the past few months as a way to document your API. Now, Swagger 3 (er, Open API Spec 3 as it's now known) is about to launch. I had a hard time finding what was new, so we made an example-filled guide that will help with your migrations.
tl;dr: Swagger 3 isn't ready for use yet, and is way more complex but solves a lot of problems with 2.
I do believe that Swagger 3 (and the rename) will splinter the community, however I think fixing some of the fundamental issues with Swagger (many of which are enumerated in the blog post) is very important.
I believe at this time the majority of the azure sdks are using it, so quite an investment has been made.
- API clients: ActionScript, Bash, C# (.net 2.0, 4.0 or later), C++ (cpprest, Qt5, Tizen), Clojure, Dart, Elixir, Go, Groovy, Haskell, Java (Jersey1.x, Jersey2.x, OkHttp, Retrofit1.x, Retrofit2.x, Feign), Node.js (ES5, ES6, AngularJS with Google Closure Compiler annotations) Objective-C, Perl, PHP, Python, Ruby, Scala, Swift (2.x, 3.x), Typescript (Angular1.x, Angular2.x, Fetch, jQuery, Node)
- Server stubs: C# (ASP.NET Core, NancyFx), Erlang, Go, Haskell, Java (MSF4J, Spring, Undertow, JAX-RS: CDI, CXF, Inflector, RestEasy), PHP (Lumen, Slim, Silex, Zend Expressive), Python (Flask), NodeJS, Ruby (Sinatra, Rails5), Scala (Finch, Scalatra)
- API documentation generators: HTML, Confluence Wiki
Lots of companies are using it in production and the project is very active with 500+ contributors.
Swagger Codegen leverages another open source project "Swagger Parser" [2] to parse the Swagger specification (JSON/YAML) and the parser will later support OpenAPI 3.0 so eventually Swagger Codegen will support Swagger 1.2, 2.0 and OpenAPI 3.0.
Likely a change that won't affect anyone; it's just a clarification.
I think there is a little error in the article. In the "Request Format" example the request method should be PUT.
http://www.omg.org/spec/CORBA/ https://www.w3.org/TR/2007/REC-soap12-part0-20070427/
JSON gives most of the stuff SOAP was actually used for (except for bureaucratic spec-driven edge cases), for 20% of the complexity -- so the JSON generation did something right.
(I'm old enough to have been through CORBA and SOAP).
Rediscovered S-expressions and reimplemented them in a mix of square and curly braces ;).
In my experience, there is nothing inherently wrong with this type of IDL. Like all architectural decisions, it comes with its own tradeoffs, but there's no reason the tradeoff profile is inherently wrong.
Now maybe it's easier on clients when you can just curl -XDELETE something but I'm not sure it's that big of a difference in the end. Especially if you have auto-gen'd client code.
Headers: Use the SOAP ones, you're just tunneling SOAP messages.
Idempotentcy requires the app to implement it that way. HTTP doesn't really help there.
I can trivially set an HTTP load balancer and log status codes. Can't say the same for SOAP.
CORBA is of course more complex, in ways that are less useful today. One particular feature was that the server always returned "live" objects that transparently proxied the calls back to the server. So you do something like getUser(123).delete(), and it would cause the User object's delete method to be called remotely. It turns out this generates a rather tight coupling between client and server; in particular, the client and server both have to use reference counting to keep objects alive as long as they are in use by a client. Things tend to get out of hand that way. While it is certainly magical to use a remote server exactly like a local one (locality transparency), it's also a performance trap.
But of course Swagger/OpenAPI has nothing to do with this.
Much of that was independent of CORBA, you just needed to release different versions of the API, this is identical in SOAP and REST today, and many client libraries are generated from specs.
I get that part about the DELETE, but no response for GET sounds odd. As I couldn't find anything in the spec RC: Is there further information available regarding that?
However, I'm not sure there is a definitive answer on if that's true from an HTTP perspective. I also couldn't find it in a skimming of the OpenAPI 3.0 spec.
In the end, REST [1] itself does not prescribe either condition and the HTTP 1.1 [2] spec doesn't either.
> A payload within a GET request message has no defined semantics; sending a payload body on a GET request might cause some existing implementations to reject the request.
[1] https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arc... [2] https://tools.ietf.org/html/rfc7231#section-4.3.1
Imo, a flaw in the earlier spec. It's clearly the case that people have uses for requesting data via JSON, and GET is the only thing that fits expected semantics ATM. Elasticsearch takes json over GET bodies because it just makes sense.
A payload within a GET request message has no defined semantics; sending a payload body on a GET request might cause some existing implementations to reject the request.
The other line I would guess is there because in the past the RFC was worded a bit differently, such that there's tech (webservers or whatever) out there that ignores request bodies on GET, so using it may lead to issues using those pieces of tech.
You can really do whatever you want. I'm not a fan of restrictive/pedantic intepretations of the spec, because HTTP is necessarily something that is really up to the developer in every way. Your database sure doesn't care if it's doing a non-idempotent write as a result of a web request that was a PUT.
Spec or not, it makes sense to be able to support a richer query language through the only HTTP verb specified for retrieving data. Just accepting that as something we can't do because some RFCs say this or that is a bit silly, because most apps out there can support it just fine. Elasticsearch is a much better piece of software because it ignored that bit of advice. (And I've had no problems running Elasticsearch through various different proxy layers, so software like nginx /haproxy also don't seem to care if you use a GET request body).
But how would you, say, bulk delete 5 different resources? I typically send those payloads in the request body of a DELETE request.
From the RFC: The DELETE method requests that the origin server delete the resource identified by the Request-URI.
https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
If the ids are in the body, you are not deleting the resource at the URI. I think that for this kind of operation you are better off with a POST.
I ask because this is something the UK Government is looking at - https://github.com/alphagov/tech-and-data-standards/issues/3...
When designing an API the hard part is getting it right(tm) and hopefully guarantee some kind of backwards compatibility and providing a clear path for its consumers, in particular documentation. It is possible to auto-generate some parts of the documentation, but such documentation is probably as helpful as auto-generated javadoc without notes provided by humans.
One alternative I find super interesting lately is defining APIs with grpc and then exposing them with the gateway proxy: https://github.com/grpc-ecosystem/grpc-gateway
In this way, you get strongly-typed interfaces and Swagger is autogenned for you.
Do you mean GitHub Flavoured Markdown? It concerns me that people writing software somehow mix up Git and GitHub as being the same thing.
Swagger does have $ref, but it's a much weaker abstraction than RAML traits and resourceTypes.
(AFAICT RAML is actually a much nicer spec, both simpler in some ways and more powerful in others, but as I say I was never actually able to use it due to the licensing issues on implementations -- only read it.)
Googling finds this: http://swag.delphidabbler.com/
I don't see how proliferation of ad-hoc syntax contributes to interoperability, which surely should be the goal of an API spec?
My take is that JSON has "won" over XML as RPC or REST serialization format because browsers support it OOTB and there's no schema needed. It simply is the way of least resistance. And since a browser front end is traditionally tied to a web backend anyway, there's no need for a formal "API" (protocol spec, actually) spec as an external artifact most of the time.
Once you try and impose typing on JSON, this very benefit turns against you, and is getting absurd IMHO. Every JSON typing regime needs to work around the fact that JavaScript isn't statically typed. Consider JSON Schema: it is reminiscent of a markup schema of sorts, when a more rational approach would IMO be to represent JSON payloads as an RPC/IDL function signature-style schema.
I'm particularly frustrated with the lack of good documentation generators. That's more important, in my opinion, than using it to generate clients and servers.
If you're not a fan, please feel free to open a ticket to give us some feedback.
Disclosure: I was contracted to build Swagger-Editor 3.0.
[1] https://github.com/swagger-api/swagger-ui [2] http://petstore.swagger.io/
Some things I dislike:
* It's just a flat list of endpoints. You have to click on each to get a description, and it has this sluggish animation that opens up. I want to browse.
* Way too much wasted screen real estate. The huge, wide table that shows when an endpoint is "open" is ridiculous.
* For any given type, have to switch between "Example Value" and "Model", which is awkward. There's a missed opportunity there, too: Consider the "PUT /user/{username}". Why is the "type" of the body not User? Why couldn't it be a link to the model? I.e. "PUT" takes a User and returns a User. Swagger-UI uses so much empty space to represent this very simple protocol.
* Whatever is being used to display the model is hard to use and read. You have to click on the little arrow to expand each level, and the font sizes are very inconsistent.
etc.
I do wish I had something vastly superior to give as an example, but I can find a lot of faults with every single API documentation site out there that I can think of. I do know some decent ones, though:
https://stripe.com/docs/api/curl
https://www.twilio.com/docs/api/rest/sending-messages
This is the level of quality you at least have to reach before my interest is piqued.
I like that these include runnable client examples in multiple languages, and includes more than just dry reference documentation; there are descriptions of actual semantics. Moreover, the documentation is presented in an organized way, by topic, and let's the user consume the information linearly without lots of clicks.
As a simpler example, years ago a colleague of mine made a simple autogenerated documentation browser with built-in request running (screenshot [2]), which turned out pretty good. It's simple, but still miles ahead of Swagger-UI in terms of usability. I sometimes wish I'd spent some effort working it into something reusable.
Also it supports union types for request/resp. Which means that you can template a URI and have multiple response schemas to go with different values of the template. Unlike swagger which forces you to enumerate every endpoint if you want them to have different response schemas, which is very ugly for logically grouped sets of resources which aren't explicitly part of a collection.
I particularly like its approach to presenting hierarchical data structures.
I only have experience with hyperschema (from an API design perspective). Would love to hear a current perspective from someone who had experience with both.
Source: I maintain Swagger-Editor. Check it out, we just finished a rewrite last week!
(Swagger = trademark owned by SmartBear, OpenAPI = new name, run by Linux Foundation)