dweber019 / backstage-plugins

A collection of Backstage plugins
MIT License
20 stars 7 forks source link

feat: format API definition for readability #27

Closed jeffersongirao closed 2 months ago

jeffersongirao commented 2 months ago

Hello again @dweber019!

This is more to trigger a discussion if you would like to support this use case. The code probably deserves some improvement but I would love to get your feedback in the general direction. 🙂 👍

The context:

When using $text placeholders for API entities targeting autogenerated OpenAPI specs, like the ones generated by spring-boot-open-api default behaviour, the output is not very readable (and breaks the layout).

Backstage

The change proposed in the PR checks if the definition is a one-liner, if so then will assume it is not formatted and will pretty print it before processing.

Thanks in advance 🙏

dweber019 commented 2 months ago

Generally I think it's valid. I think I can review it in the next days. Please consider that not only JSON is a valid format for openapi and asyncapi. At least yaml is one too.

jeffersongirao commented 2 months ago

Please consider that not only JSON is a valid format for openapi and asyncapi. At least yaml is one too.

That is true 👍. As it is implemented though I'm making an assumption that is JSON based on the line count given that new lines have semantic value in YAML. As it is it currently it would only break with a single line YAML definition and that would be an invalid API definition anyway I think.

dweber019 commented 2 months ago

Please consider that not only JSON is a valid format for openapi and asyncapi. At least yaml is one too.

That is true 👍. As it is implemented though I'm making an assumption that is JSON based on the line count given that new lines have semantic value in YAML. As it is it currently it would only break with a single line YAML definition and that would be an invalid API definition anyway I think.

Totally, true. We can leave it like this.

dweber019 commented 2 months ago

@jeffersongirao new version should be available in a few mintes.