Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Crystal API model mapping #6947

Open
straight-shoota opened this issue Oct 16, 2018 · 5 comments
Open

Improved Crystal API model mapping #6947

straight-shoota opened this issue Oct 16, 2018 · 5 comments

Comments

@straight-shoota
Copy link
Member

#4746 added JSON serialization for Crystal API components like types, methods, constants etc.
The implementation uses custom #to_json methods to extract the data from the compiler models.

However, it would be great if there was a way to also deserialize the JSON data into Crystal models. This is necessary for external doc generators to hook in. It also offers possibility for other uses of the generated API model.

This doesn't necessarily need to be part of the stdlib, but given that the serialization part is required for the compiler anyway, I figure it would make sense to also add the deserialization so both can be kept in sync.

The best way to do this would be to implement simple data model types with JSON serialization. The compiler types would just create such a model instead of serializing directly with custom #to_json methods.
A rough draft of the API model can be seen here: https://gist.github.com/straight-shoota/d6b783dd4c973712aa6a2183153fd391

@straight-shoota
Copy link
Member Author

Building on that idea, I'd like to propose refactoring the docs generator, to more effectively separate it into two stages:

  • extracting a documentation model from the parsed program
  • processing that data into display format (HTML)

The interface between both stages would be a structured format which can easily be serialized to JSON and would also serve as an external interface which can be used for customized doc generators and other purposes.

We've discussed about potentially removing the HTML-generation from the compiler entirely. This proposal doesn't go this far, but it would be a preparation for that. But it's a good improvement anyway to refactor and separate concerns.

@jkthorne
Copy link
Contributor

jkthorne commented Dec 3, 2019

would removing the html generation be a step towards removing markdown?

@straight-shoota
Copy link
Member Author

Markdown is only required for generating the HTML, so it would remove that dependency entirely from the compiler.

But that's talk about following steps and out of scope here.

@crysbot
Copy link

crysbot commented May 30, 2024

This issue has been mentioned on Crystal Forum. There might be relevant details there:

https://forum.crystal-lang.org/t/the-weight-of-compiler-tools/6888/1

@devnote-dev
Copy link
Contributor

I have created Redoc which covers most of the docs JSON models and their attributes. I think at some point this could be used for documentation generation, I've already integrated it into Docr to power its info and search commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants