# Generating UML class diagrams

**URL:** <https://discuss.jsonapi.org/t/generating-uml-class-diagrams/882>\
**Category:** Uncategorized\
**Created:** [January 15, 2017, 12:52pm UTC](https://discuss.jsonapi.org/t/generating-uml-class-diagrams/882 "2017-01-15T12:52:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aspiers](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@aspiers](https://discuss.jsonapi.org/u/aspiers)\
**Post date:** [January 15, 2017, 12:52pm UTC](https://discuss.jsonapi.org/t/generating-uml-class-diagrams/882/1 "2017-01-15T12:52:35Z")

</div>

Hi all,

I’m working on a Rails project which conforms to the JSON API via the [`JSONAPI::Resources` Ruby gem](http://jsonapi-resources.com/). It has a non-trival set of data models, and it would be really helpful to obtain a UML class diagram visualising these models and the relationships between them. Does anyone have any suggestions for a way I could auto-generate such a class diagram? Given the way JSON API very nicely standardises everything into a machine-readable form, it would seem to me like a wasted opportunity if there wasn’t a tool to auto-generate helpful class diagrams.

Thanks!

---

<div class="post-metadata">

**Author:** ![A-Helberg](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/a-helberg/32/250_2.png) [@A-Helberg](https://discuss.jsonapi.org/u/A-Helberg)\
**Post date:** [January 20, 2017, 9:01pm UTC](https://discuss.jsonapi.org/t/generating-uml-class-diagrams/882/2 "2017-01-20T21:01:33Z")

</div>

Hi @aspiers,

I don’t know if such a tool exists, but you should be able to write your own without too much effort.

[Rails-erd](https://github.com/voormedia/rails-erd) should give you all the info you need to output an ERD.

You can use `JSONAPI::Resource.descendants` to get all your resources.

(assuming `resource = JSONAPI::Resource.descendants.first`)  
Use `resource._attributes` to get all the attributes.

You can use `resource._relationships` to get all the relationships.  
For a relationship, it’s class will be one of `JSONAPI::Relationship::ToOne` or `JSONAPI::Relationship::ToMany`.

Should be easy to do the rest 🙂 let me know if you can’t figure it out, looks like a fun weekend project to attempt.

---

<div class="post-metadata">

**Author:** ![double.emms](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/double.emms/32/203_2.png) [@double.emms](https://discuss.jsonapi.org/u/double.emms)\
**Post date:** [January 20, 2017, 9:03pm UTC](https://discuss.jsonapi.org/t/generating-uml-class-diagrams/882/3 "2017-01-20T21:03:32Z")

</div>

You might get some inspiration from this gem: [https://github.com/preston/railroady](https://github.com/preston/railroady)

---

<div class="post-metadata">

**Author:** ![aspiers](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@aspiers](https://discuss.jsonapi.org/u/aspiers)\
**Post date:** [January 21, 2017, 12:46pm UTC](https://discuss.jsonapi.org/t/generating-uml-class-diagrams/882/4 "2017-01-21T12:46:03Z")

</div>

Thanks a lot both for your replies - these gems both look great and I’ll try them out!

In the longer term I think it would be cool if it was possible to generate ERDs only with access to the API endpoint, rather than also to the codebase, since then it could be done independently from the underlying JSON API implementation. But maybe the JSON API spec doesn’t require exposure of enough information about the relationships for this to be possible - I don’t know enough about the spec to comment on that.
