Class: Api::V3::InfoController

Inherits:
Api::V2::InfoController
  • Object
show all
Defined in:
app/controllers/api/v3/info_controller.rb

Instance Method Summary collapse

Instance Method Details

#openapiObject Also known as: swagger

Override openapi/swagger to generate a v3-accurate spec. All other info actions (version, roles, heartbeat, ntp, translations, schema, dsl, settings) are inherited unchanged — they return plain JSON and are version-agnostic.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/api/v3/info_controller.rb', line 6

def openapi
  uri = URI(request.url)
  spec = {
    "openapi" => "3.0.0",
    "info" => {
      "title" => "#{Settings.ns(:main).app_name} API",
      "description" => Api::OpenApi::V3.new(ApplicationRecord.subclasses, request).description,
      "version" => "v3",
    },
    "servers" => [
      {
        "url" => "#{uri.scheme}://#{uri.host}#{":#{uri.port}" if uri.port.present?}/api/v3",
        "description" => "JSON:API v3 base URL",
      },
    ],
    "components" => {
      "securitySchemes" => {
        "bearerAuth" => {
          "type" => "http",
          "scheme" => "bearer",
          "bearerFormat" => "JWT",
        },
      },
    },
    "security" => [{ "bearerAuth" => [] }],
    "paths" => Api::OpenApi::V3.new(ApplicationRecord.subclasses, request).generate,
  }
  render json: spec.to_json, status: 200
end