ash-project / ash_json_api

The JSON:API extension for the Ash Framework
https://hexdocs.pm/ash_json_api
MIT License
55 stars 40 forks source link

Generate the OpenApi document of the project into a file #129

Closed gcugnet closed 2 months ago

gcugnet commented 4 months ago

Is your feature request related to a problem? Please describe. It’s always frustrating to need to write documentation. AshJsonApi generates an OpenApi documentation based on the code which is so nice. It could be even nicer if it could serve the doc as a file.json / file.yaml because those files can be useful to integrate API on other platforms.

Describe the solution you'd like A command to auto-generate the OpenApi documentation file would be so great, just as the open_api_spex library allows it:

mix openapi.spec.json --spec MyAppWeb.ApiSpec
mix openapi.spec.yaml --spec MyAppWeb.ApiSpec

Source = https://hexdocs.pm/open_api_spex/readme.html#generating-the-spec

Describe alternatives you've considered An alternative is to copy/paste the to a file what is generated on the route /api/open_api because it’s already the OpenApi documentation written in JSON.

Ash Api Router:

defmodule MyAppWeb.Support.Router do
  use AshJsonApi.Api.Router,
    apis: [MyApp.Support],
    open_api: "/open_api"
end
  forward "/ash/swaggerui",
          OpenApiSpex.Plug.SwaggerUI,
          path: "/api/open_api",
          title: "Myapp's JSON-API - Swagger UI",
          default_model_expand_depth: 4

  forward "/api", MyAppWeb.Support.Router

-> go to /api/open_api -> copy all code -> create a new file (for instance open_api.json) in your project (for instance in /priv/static) and paste all the code into that file.

Express the feature either with a change to resource syntax, or with a change to the resource interface

I don’t know.

Additional context

Nothing more to say.

zachdaniel commented 4 months ago

Great idea! Would be a very useful task.