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

feat: write OpenAPI spec in json or yaml format #819

Closed
wants to merge 3 commits into from

Conversation

nathanaelhoun
Copy link
Contributor

From https://swagger.io/specification/,

An OpenAPI document that conforms to the OpenAPI Specification is itself a JSON object, which may be represented either in JSON or YAML format.

This PR adds a configuration toggle to output the OpenAPI document in the JSON format, which is useful to use it with the package nextapps-be/laravel-swagger-ui without the yaml PECL extension.

@shalvah
Copy link
Contributor

shalvah commented Mar 4, 2024

I'm not in favour of this (I think JSON is a terrible format for this), but I'll accept this. However, you need to add it to the config reference and remove it from the default config file (there are too many options; only the most common and important stuff should be there).

@nathanaelhoun
Copy link
Contributor Author

nathanaelhoun commented Mar 5, 2024

Thanks for your understanding. I agree that Yaml format is more readable, but allowing to publish as JSON would be a great enhancement for our deploiement setup.

I replaced the configuration for a more simple toggle scribe.openapi.json (as it can only be JSON or Yaml according to the OpenAPI spec), and removed it from the default config.


Having put more thought to it, I wonder if it wouldn't be simpler for both of us to add a composer script to my side to convert the yaml to json after building. This would avoid merging this new "niche" feature into Scribe. What do you think?

 "scripts": {
        "build-docs": [
            "@php artisan scribe:generate",
            "@php -r \"require 'vendor/autoload.php'; $spec = Symfony\\Component\\Yaml\\Yaml::parseFile('resources/swagger/openapi.yaml'); $json = json_encode($spec, JSON_PRETTY_PRINT); file_put_contents('resources/swagger/openapi.json', $json);\""
        ]
    },

mikeah2011

This comment was marked as resolved.

@nathanaelhoun
Copy link
Contributor Author

After some time and some thoughts about our usage of Scribe, we have decided to go with the composer script solution. Less software can be better software.

I'll let someone else re-submit this code if they are still interested in it.

Thanks again for making Scribe, it's a real gamechanger.

@nathanaelhoun nathanaelhoun deleted the openapi-json branch March 20, 2024 16:45
@shalvah
Copy link
Contributor

shalvah commented Mar 26, 2024

Alright then! I'm still fine with adding it if it's hidden away.👍

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

Successfully merging this pull request may close these issues.

3 participants