# Swagger, WADL or similar for the REST API?

**URL:** <https://meta.discourse.org/t/swagger-wadl-or-similar-for-the-rest-api/41623>\
**Category:** Development\
**Created:** [Março 27, 2016, 5:15pm UTC](https://meta.discourse.org/t/swagger-wadl-or-similar-for-the-rest-api/41623 "2016-03-27T17:15:54Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![erkist](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/erkist/32/53325_2.png) [@erkist](https://meta.discourse.org/u/erkist)\
**Post date:** [Março 31, 2016, 8:13pm UTC](https://meta.discourse.org/t/swagger-wadl-or-similar-for-the-rest-api/41623/11 "2016-03-31T20:13:45Z")

</div>

> [@blake](#):
>
> I personally am not a huge fan of Swagger, but I know people love it and swear by it. So if that is something that interests you go for it.

Thanks for the encouragement. I have now gotten started with it.

> [@fantasticfears](#):
>
> It will be so nice if we have this specification. But It takes HUGE amount of time. If you insist, focus on topic list, users, category, badges, posts, topics, topic actions endpoints.

I took your advice and focused on what I need short term (categories, topics, posts) and I am now something like 30% of the way there (the rest should go faster since I now have an idea how to do it)

What I’ve done is to create a Swagger Specification, available at [discourse\_swagger/discourse\_swagger.yml at master · erkist/discourse\_swagger · GitHub](https://github.com/erkist/discourse_swagger/blob/master/discourse_swagger.yml) (as of this writing it only supports site.json and categories.json)

This specification can be used to generate a Java API library (or any other supported language), which can then be invoked as below:

```
ApiClient client = new ApiClient();
client.setBasePath("http://192.168.56.2");

DefaultApi api = new DefaultApi(client);

((ApiKeyAuth) client.getAuthentication("api_username")).setApiKey("erki");
((ApiKeyAuth) client.getAuthentication("api_key"))
   .setApiKey("35b1416dda787a137dddca95170a549e0445507fcabcd009c09d3569cdb527b7");

Site site = api.getSiteInformation();
String nameOfFirstGroup = site.getGroups().get(0).getName();

Categories categoriesResponse = api.getCategories();
String nameOfFirstCategory = categoriesResponse.getCategoryList().getCategories().get(0).getName();

```

As you see the generated API is strongly typed, and the name and structure closely reflects the REST API responses.

I aim to continue expanding it a bit, but I’m not sure I’ll ever get to a full implementation. Still, if this helps anyone other than me, that would be awesome. And if someone wants to help, even better! And even if I’m the only user, I’m still satisfied since I’ve gotten the opportunity to learn YAML, Swagger, JSON Schema and parts of the Discourse source code 😃

---

_[View the full topic](https://meta.discourse.org/t/swagger-wadl-or-similar-for-the-rest-api/41623)._
