Generating UML class diagrams


Hi all,

I’m working on a Rails project which conforms to the JSON API via the JSONAPI::Resources Ruby gem. 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.



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 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 :slight_smile: let me know if you can’t figure it out, looks like a fun weekend project to attempt.


You might get some inspiration from this gem:


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.