News for hackers. Stuff that matters.
Re:Problems with Swagger by gkoberger on Tuesday April 04, 2017 @03:19PM (#14036238)
My problem with Swagger is almost the opposite... it solves the problem (APIs are very complicated to use!) by embracing this complexity with more complexity and more tools. Rather, I believe the solution is a push to just have simpler APIs.

It's crazy to me that it's harder to write a Swagger file than it is to write the API itself. And there's a lot of tooling that benefits from Swagger, but... I've found they all work 80%. Codegen, documentation, etc get 80% of the way there.

(Also, OAS 3 has linking, which is very similar to your hypermedia complaint)

Re:Problems with Swagger by emidln on Tuesday April 04, 2017 @04:20PM (#14036797)
Do people write Swagger files by hand? That sounds awful. I was under the impression everyone used tools like I use in Clojure (compojure-api[0] and ring-swagger[1]).

[0] https://github.com/metosin/compojure-api

[1] https://github.com/metosin/ring-swagger

Re:Problems with Swagger by gkoberger on Tuesday April 04, 2017 @05:10PM (#14037238)
In my experience (we have a product where people upload Swagger files), most people write it by hand. There's two reasons:

1) Many people use Swagger to design (rather than document), meaning the Swagger comes before the code

2) Most people just prefer to write it out, since the tooling otherwise isn't necessarily great (especially for non-developers)

We ran a poll and "by hand" (either on Swagger Hub/Apiary, or locally) won by a landslide.

Re:Problems with Swagger by dwaltrip on Tuesday April 04, 2017 @10:55PM (#14039298)
How does a non-developer know how to document or design an API?
Re:Problems with Swagger by numbsafari on Tuesday April 04, 2017 @11:31PM (#14039459)
Perhaps the first pass of the doc is written by a developer but it is later updated by a tech-writer, or you need to produce a translated version.
Re:Problems with Swagger by eddieroger on Wednesday April 05, 2017 @08:24AM (#14041545)
I do and have, yes. We generally push for design-first specs, which means there's nothing in place to generate the Swagger file yet. If the API is simple, as they should be, then it's not that awful, really.
Re:Problems with Swagger by paulddraper on Tuesday April 04, 2017 @04:45PM (#14037029)
I didn't realize Swagger was meant to be an intermediate format.
Re:Problems with Swagger by emidln on Tuesday April 04, 2017 @04:49PM (#14037059)
It's not an intermediate format necessarily, but it reflects information already encoded in your route definitions. It seems silly to maintain that information twice in two different locations.
Re:Problems with Swagger by darrelmiller on Wednesday April 05, 2017 @01:07AM (#14039816)
Hence the reason for tools like swagger-inflector http://swagger.io/writing-apis-with-the-swagger-inflector/ that allows you to drive routing directly from the OpenAPI definition
Re:Problems with Swagger by metachris on Tuesday April 04, 2017 @04:01PM (#14036628)
I've implemented Swagger with several APIs and agree that it's crazy complex and time-consuming to write Swagger files manually.

I believe the best use-case for Swagger is to develop the API (perhaps just defining the routes with payload and response, but without controllers), and then auto-generating the Swagger files. This way the API consumers always have an up-to-date documentation, and there is only one place which represents the current state of the API.

Re:Problems with Swagger by blazespin on Wednesday April 05, 2017 @12:06AM (#14039567)
Swagger yaml is hard to write? Hmm.. relative to the code that services it or consumes it, I find its pretty trivial.
Re:Problems with Swagger by dvirsky on Tuesday April 04, 2017 @05:04PM (#14037196)
Exactly. I wrote a project (https://github.com/EverythingMe/vertex) where you define the API with a semi declarative syntax in Go, and it just translates to swagger so you can generate documentation and playgrounds effortlessly. It worked very well.
Re:Problems with Swagger by k__ on Tuesday April 04, 2017 @04:00PM (#14036619)
Are there any good alternatives?

I used REST which forced me basically to dig deep into online documentation when I wrote a client, but was rather straight forward to implement a server with.

I used SOAP which forced me to write a giant WSDL file, but was rather nice to work with on the client side.

GraphQL seems to obliterate this problem with its auto discovery mechanisms, but I don't know too much about it.

Re:Problems with Swagger by jwoah12 on Tuesday April 04, 2017 @04:50PM (#14037067)
This is GraphQL's killer feature imo. We describe our schema in easy-to-understand GraphQL Schema Language, use that text file to actually initialize our server, and the included GraphiQL UI automatically provides full documentation and interactive query tool. Our users no longer need nearly as much hand-holding to grok the data model.
Re:Problems with Swagger by mcescalante on Tuesday April 04, 2017 @03:43PM (#14036469)
I had these same issues. It took me considerably more time and effort to write a Swagger spec and get the UI to actually behave than it did to write my entire API and some simple docs in markdown.

I also tried out the "codegen" and a few other projects that generate boilerplate from a spec (for Python) - the code it generated was frustrating, lengthy, and much more complex than the simple endpoints that I quickly wrote from scratch.

Re:Problems with Swagger by eropple on Tuesday April 04, 2017 @04:26PM (#14036842)
> It took me considerably more time and effort to write a Swagger spec and get the UI to actually behave than it did to write my entire API and some simple docs in markdown.

How long did it take to write API consumer libraries in twenty languages and update every one on API change?

If you don't care about that, then Swagger isn't a good idea for you. But I'd think really hard about whether you should care about it if you think you don't.

> the code it generated was frustrating, lengthy, and much more complex than the simple endpoints that I quickly wrote from scratch

Sure--but you didn't have to write it.

Re:Problems with Swagger by pbreit on Tuesday April 04, 2017 @04:42PM (#14036997)
Is whatever value people are getting out of client libraries provided by something generic like http://unirest.io ?

When does it make sense to issue API-specific client libraries for a plain ole RESTful API?

Re:Problems with Swagger by cookiecaper on Tuesday April 04, 2017 @06:26PM (#14037825)
All the time? Most "RESTful" (meaningless term, by the way) APIs have a series of convoluted steps that are annoying and tedious to hand-roll.

Authentication is a good basic example. Different APIs will have different requirements for authentication headers. Successful authentication frequently requires multiple steps, like an initial request to get a session token. Many APIs will also require your request to be signed according to their specifications, and to stuff that signature in a header with a special name.

Every API expects to receive data in its own format. I don't want to have to make a bunch of validators that lay on top of your data model. These can and should be provided, and Swagger makes that automatic.

As eropple states, if something is making me do all of that by hand, I'm already looking for something else that will allow me to just say "import project_lib; project_lib.authenticate(); ..."

If you're just talking about something that is read-only and that only emits a single field I care about, sure, no need for a library. Something like the free version of ipinfo.io would be a good example.

Stuff that's more complicated than that, yes, it needs a client library.

Re:Problems with Swagger by eropple on Tuesday April 04, 2017 @05:38PM (#14037457)
> When does it make sense to issue API-specific client libraries for a plain ole RESTful API?

Any time you have a statically-typed language consuming you. Having to write my own Jackson declarations to pull in your API to a JVM project or my own DataContract barf for a CLR one is a quick way to make me hate you, and me hating you means I'm already looking for an alternative that isn't you that gets out of my way.

Re:Problems with Swagger by pbreit on Tuesday April 04, 2017 @08:38PM (#14038663)
I sort of thought the opposite, that the client libraries are what is getting in the way.
Re:Problems with Swagger by eropple on Wednesday April 05, 2017 @04:18AM (#14040577)
So you enjoy writing a bunch of boilerplate class files that are manual translations of somebody else's doc?
Re:Problems with Swagger by pbreit on Wednesday April 05, 2017 @10:10AM (#14042172)
No, I just like to get started coding API calls.
Re:Problems with Swagger by tomc1985 on Tuesday April 04, 2017 @04:42PM (#14036999)
One could argue that clients can roll their own damn client implementations, and that autogenerating client libraries is the folly. This is just REST, no?
Re:Problems with Swagger by eropple on Tuesday April 04, 2017 @05:36PM (#14037440)
One could argue that, but one would be creating a really sucky developer experience that can be avoided with comparatively little work.

- "Just REST" doesn't actually encapsulate meaningful behaviors by itself. It's by no means complete. Swagger is a partial patch on this by trying to reduce the scope of what your API is supposed to be doing, and it's not perfect, but it's better than "welp, throw Grape at it."

- Most statically-typed languages are a pain in the ass when it comes to HTTP responses because those responses can't be reified without types, and returning JSON blobs that don't have mapping types on the other end super sucks. I can do it myself if I absolutely have to--but making me waste my time doing it is silly.

Re:Problems with Swagger by tomc1985 on Tuesday April 04, 2017 @09:18PM (#14038862)
> "Just REST" doesn't actually encapsulate meaningful behaviors by itself.

Yes it does: open a socket, speak HTTP, get some data back. Yeah you'll have to feed it into a JSON parser or whatever but apparently people consider that a lot of work now?

I do agree on the points with statically-typed languages. Finagling dynamic types in such a system is a PITA. But I do not see the need for autogenerating tooling if you're consuming REST from a dynamic language; all you've automated is the HTTP call and data parsing (which takes very little time to write oneself)

Maybe I've been living under a rock the past 10 years but REST has never required very much effort, either to implement or consume. Then out of nowhere I begin encountering all these weird-ass tools -- Swagger (and who the F named that one, Old Spice?), Grape, whatever. All this crazy software to do all these crazy things when... it's just HTTP and JSON over the wire :/

At some point people need to ask themselves, 'how much abstraction is too much abstraction?'

Swagger's real value-add to me is in a standard documentation format for REST APIs, but the last instance I used of Swagger made my work more difficult :/

Re:Problems with Swagger by int_19h on Tuesday April 04, 2017 @09:56PM (#14039032)
One can argue that, but in practice, this often means that the clients will just take their business and go elsewhere.
Re:Problems with Swagger by wing328hk on Wednesday April 05, 2017 @03:44AM (#14040447)
> I also tried out the "codegen" and a few other projects that generate boilerplate from a spec (for Python) - the code it generated was frustrating, lengthy, and much more complex than the simple endpoints that I quickly wrote from scratch.

For Swagger Codegen, you can also customize the mustache templates in whatever way you want (e.g. replacing 4-space with tab in C# client templates). The auto-generated code may sometimes look lengthy but we usually do it with reasons based on feedback from developers. Please share with us more via https://github.com/swagger-api/swagger-codegen/issues/new so that we can further improve the output.

You may find Swagger Codegen a huge time saver in use cases in which the endpoints are growing (e.g. from 20 endpoints in v1 to 40 endpoints in v2) and you will need to provide API clients in multiple langauges (e.g. Python, Ruby, PHP, C#, etc)

Disclosure: I'm a top contributor to Swagger Codegen

Re:Problems with Swagger by haikuginger on Tuesday April 04, 2017 @05:12PM (#14037257)
> I also tried out the "codegen" and a few other projects that generate boilerplate from a spec (for Python) - the code it generated was frustrating, lengthy, and much more complex than the simple endpoints that I quickly wrote from scratch.

Personally, I don't understand why codegen is even necessary as opposed to a pure object-oriented client that works directly from the Swagger spec. Before I knew Swagger existed, I actually implemented such a client based on my own made-up spec.[0] It's relatively naive, but I attribute that more to my relative youth in development than to the concept itself.

[0]https://github.com/haikuginger/beekeeper

Re:Problems with Swagger by cookiecaper on Tuesday April 04, 2017 @04:00PM (#14036612)
>I had these same issues. It took me considerably more time and effort to write a Swagger spec and get the UI to actually behave than it did to write my entire API and some simple docs in markdown.

It's definitely going to be faster to just write it at first. Swagger, and everything like it, is an investment.

>I also tried out the "codegen" and a few other projects that generate boilerplate from a spec (for Python) - the code it generated was frustrating, lengthy, and much more complex than the simple endpoints that I quickly wrote from scratch.

That's auto-generated code for you. Can't rival humans (yet), but that doesn't automatically mean it's not useful.

Compare hand-rolled ASM with compiler-rolled ASM for an example. Human-written ASM will often be much more compact and readable, sometimes even more performant, but then you have to write ASM instead of letting the compiler do it for you.

Re:Problems with Swagger by Meic on Wednesday April 05, 2017 @03:26AM (#14040392)
At the risk of linking to another tool which will only get you 80% of the way there...

OpenAPI-GUI [1] [2] is a visual editor / creator for OpenAPI / Swagger 2.0 definitions. It runs entirely client side in the browser.

It's certainly useful enough to start an OpenAPI definition by providing all the boilerplate. Later, as the definition increases in complexity you can cut-and-paste in the editor of your choice.

[1] https://mermade.github.io/openapi-gui [2] https://github.com/mermade/openapi-gui

Re:Problems with Swagger by czardoz on Wednesday April 05, 2017 @04:47AM (#14040684)
This is why we developed the Postman Collection format. It's very simple, and expressive. More importantly, it's a way to impose _less_ constraints on the API Designer, while also being richly documented.

Here's an example of a very simple collection: https://github.com/postmanlabs/postman-collection-transforme...

But, you can also go and have something like https://github.com/postmanlabs/postman-collection-transforme..., which is very well documented. The generated documentation for this is available too: https://docs.postman-echo.com

Disclaimer: I work at Postman.

Re:Problems with Swagger by BinaryIdiot on Tuesday April 04, 2017 @03:42PM (#14036457)
> It's crazy to me that it's harder to write a Swagger file than it is to write the API itself. And there's a lot of tooling that benefits from Swagger, but... I've found they all work 80%. Codegen, documentation, etc get 80% of the way there.

Completely agree. This was one of the reasons I liked using hapijs and joi in the past; they combine to validate and setup your HTTP endpoints and the swagger documentation is literarily generated from that code and not some separate thing you have to write. Unfortunately, outside of that very specific space, very little seems to exist.

Hapijs has its own issues and it's rarely my goto node framework anymore but it's hard to beat doing documentation that way.

Re:Problems with Swagger by cobookman on Tuesday April 04, 2017 @05:54PM (#14037581)
Have you looked at the protobuf grpc implementation. I find it way simpler than swagger. It also generates your server code as well.
Re:Problems with Swagger by skyde on Wednesday April 05, 2017 @01:35PM (#14043885)
100% agree, if you can afford to use GRPC. It's much simpler than having to use swagger.
Re:Problems with Swagger by fehguy on Tuesday April 04, 2017 @11:18PM (#14039401)
Isn't it more work to write tests than code? Not sure that's the best argument against a technology.

You can easily hang yourself many different ways. The idea with Swagger includes some rules, which is what makes it useful. If you don't want that, then why use it?

It would be nice if you didn't have to write HTML to write a web page, but that's a constraint that has pretty well known benefits to end users.

Re:Problems with Swagger by Joeri on Tuesday April 04, 2017 @04:09PM (#14036689)
I use swagger annotations to generate a swagger json automatically from my REST services. It is quite effortless once set up.
Re:Problems with Swagger by IncRnd on Tuesday April 04, 2017 @03:47PM (#14036501)
Excellent points that are like a breath of fresh air.
Re:Problems with Swagger by fsargent on Tuesday April 04, 2017 @03:55PM (#14036570)
Check out Stoplight.io for a good tool for managing swagger documentation. It's a lot easier than managing the YAML itself.