Live data from Hacker News

Problems with Swagger

blog.novatec-gmbh.de

101–110 of 163 posts

Re: Problems with Swagger

#101

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…

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

#102
> To mitigate this problem just stop generating code and doing automatic deserialisation.

No! WTF?! Just use generators that produce code that is resilient to a changing API. Why would you get rid of a huge productivity boost because the generator doesn't produce code you like? That's trading two hours of work to change the generator, for many multiple hours of reproducing the proper API, especially if you have many to support.

I stopped reading right there. My personal biggest issue with swagger is that they threw the baby out with the bath water, reproducing XSD in Yaml, for no good reason. The UI they produced was nice, and that is probably the best feature of swagger. But the data format doesn't solve a new problem IMO, it just created a new standard that we all have to deal with.

What is that now? Corba IDL, XSD, protobuf, thrift, avro, Swagger, Raml... I'm sure because of the flaws in each of those, we really should just use the new OpenAPI.

Or just get rid of them all and go bare metal with Cap'n Proto. Oh but don't use code generators for any of those, because that would make it way too easy to support all of them with a single API .

Re: Problems with Swagger

#103

Earlier quoted context omitted.

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 loca…

How does a non-developer know how to document or design an API?

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

#104

I'm surprised RAML isn't suggested as na alternative. http://raml.org/

Or API Blueprint. Markdown is a really nice format for documenting your interfaces and you don't really need special tools to render the documentation for the web. Just checking the file into GitHub creates a link to human-readable documentation.

Re: Problems with Swagger

#105

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…

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 wh…

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

#106
post #64

Earlier quoted context omitted.

How about urllib, the Python default? def handle_thing(thing): r = urllib.request.Request(url='example.com', data={'stuff': 1}) return urllib.request.urlopen(r) Just one example. I know the tooling has improved somewhat since REST has become extremely common, so this is less of an issue now than it used to be (for example, most people use the Python requests module now, which makes it harder to use the wrong method (…

You're going on about the value of "conventional methods" in a criticism of using HTTP verbs? Understanding the difference between a GET and a POST isn't some new-fangled idea, it's decades old. Like Tim Berners Lee old. I didn't even know what Thrift was until I Googled it, and found out it was developed at Facebook. Okay. I'm stunned. Do you write code that runs on the internet? How did you even get employed?

Uncivil comments aren't allowed here, and especially not personal attacks, which we ban users for. Please don't post like this again.

https://news.ycombinator.com/newsguidelines.html

https://news.ycombinator.com/newswelcome.html

Re: Problems with Swagger

#107
Oh, man. There is so much wrong with this article. Here we go:

> The documents are written in YAML, which I call XML for lazy people

No. That's ridiculous. XML (and JSON, for that matter) is designed to be read and written by machines, not humans. (If the design goal was actually primarily for humans to read and write it, the designers failed. Miserably.) YAML is a nice middle ground, in that it can be unambiguously parsed by a machine, but is also fairly pleasant and forgiving for humans to write.

> The enum thing

This is a problem with the code generators, not with Swagger as a spec. Any API definition format that allows enums (and IMO, all should) will have this "problem".

Language-native enums are way better to deal with than stringly-typed things. An alternative might be to generate the enum with an extra "UNKNOWN" value that can be used in the case that a new value is added on the server but the client doesn't know about it.

However, I would consider adding a value to an enum to be a breaking API change, regardless of how you look at it. What is client code expected to do with an unknown value? In some cases it might be benign, and just ignoring the unknown value is ok, but I'd think there are quite a few cases where not handling a case would be bad.

I agree with the author that "adding a new element to the structure of the payload should NEVER break your code", but that's not what adding an enum value is. Adding a new element to the structure is like adding a brand-new property on the response object that gives you more information. The client should of course ignore properties it doesn't recognize, and a properly-written codegen for a Swagger definition should do just that.

> Nobody reads the documentation anymore.

The author admits this issue isn't specific to Swagger, and yet harps on it anyway. What?

> No Hypermedia support ... Which means, you can change that business logic whenever you want without having to change the clients... Swagger is URI Centric

Oh god. I don't care what Roy Fielding says. No one has embraced hypermedia. It's irrelevant. Move on.

Being able to change biz logic has nothing to do with hypermedia. That's just called "good design". That's the entire point of an API: to abstract business logic and the implementation thereof from the client.

Regardless, the entire idea of being able to change your API without changing the clients is just silly. If you're changing the API purely for cosmetic reasons, just stop, and learn how to be a professional. If you're changing the API's actual functionality or behavior, the code that calls the client needs to know what the new functionality or behavior is before it can make use of it, or if it's even safe to make use of it. I imagine there are some small number of cases where doing this "automatically" is actually safe, but the incidences of it are so vanishingly small that it's not worth all the extra complexity and overhead in designing and building a hypermedia API.

APIs are not consumed by "smart" clients that know how to recurse a directory tree. They are consumed by humans who need to intelligently decide what API endpoints they need to use to accomplish their goals. Being able to write a dumb recursing client that is able to spit out a list of API endpoints (perhaps with documentation) is a cute trick, but... why bother when you can just post API docs on the web somwehere?

This section is irrelevant given my objections to the last section.

> YAML generation (default Java codegen uses annotations, codegen via this way will leak implementation details)

Well, duh, don't do it that way. Do API-first design, or at least write out your YAML definition by hand after the fact. If nothing else, it's a good exercise for you to validate that the API you've designed is sane and consistent.

> Swagger makes a very good first impression

Yes, and for me, that impression has mostly remained intact as I continue to work with it.

> What are the alternatives?

Having worked with both Spring and JAX-RS, I find it hard to take someone seriously if they're strongly recommending it as a better alternative to something as fantastic as Swagger. Also note that the author previously railed on the reference impl Java tool for its reliance on annotations... which... same deal with Spring and JAX-RS.

Re: Problems with Swagger

#108
post #55

Earlier quoted context omitted.

I am not sure I get your example. But yes the client still has to know what to do in advance.

>But yes the client still has to know what to do in advance. According to Roy Fielding[1] (who came up with the concepts of ReST and HATEOAS: "A REST API should be entered with no prior knowledge beyond the initial URI (bookmark) and set of standardized media types that are appropriate for the intended audience" So if an application doesn't rely on "standardized media types", and "the client still has to know what to…

I don't think you and your parent mean the same thing. The client "has to know what to do in advance" in the sense that the human building the application needs to know what user interface they want to build, and know how the API works (in advance) in order to use it to populate the interface.

If you have an extremely dumb interface that just displays fields in API responses, then ok... but that's a very trivial UI that accounts for... basically no useful products ever.

Re: Problems with Swagger

#109
post #52

Earlier quoted context omitted.

I didn't realize Swagger was meant to be an intermediate format.

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.

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

#110

Earlier quoted context omitted.

RPC is not fundamentally different from REST. REST is a form of RPC. (/me ducks tomatoes thrown among boos and hisses from the crowd) The difference is that the processes behind REST speak with HTTP. You're still doing a "remote procedure call"; you're asking for a remote process to execute some function on your behalf and return the result. RPCs facilitate the same exact thing. How is this a "fundamental" difference…

RPC doesn't have an Uniform Interface. Say you have a user profile, which has a Gravatar associated. Sure you can have a getUserProfile() procedure that fetches the user information, but what about the image? You can write a getUserAvatar() procedure that proxies it, but that's wasteful. In a RESTful system, you have a Resource Identifier (URL) that you can indicate as an hypermedia reference (link), with which the c…

There is absolutely no reason why you can't implement the same REST concepts on top of another RPC mechanism.
Post reply on HN