Class: Spikard::OpenApiConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/spikard/config.rb

Overview

OpenAPI 3.1.0 documentation configuration.

Spikard can automatically generate OpenAPI documentation from your routes. When enabled, it serves:

  • Swagger UI at /docs (customizable)

  • Redoc at /redoc (customizable)

  • OpenAPI JSON spec at /openapi.json (customizable)

Security schemes are auto-detected from middleware configuration. Schemas are generated from your route type hints and validation.

Examples:

openapi = OpenApiConfig.new(
  enabled: true,
  title: 'My API',
  version: '1.0.0',
  description: 'A great API built with Spikard',
  contact: ContactInfo.new(
    name: 'API Team',
    email: 'api@example.com',
    url: 'https://example.com'
  ),
  license: LicenseInfo.new(
    name: 'MIT',
    url: 'https://opensource.org/licenses/MIT'
  ),
  servers: [
    ServerInfo.new(url: 'https://api.example.com', description: 'Production'),
    ServerInfo.new(url: 'http://localhost:8000', description: 'Development')
  ]
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(enabled: false, title: 'API', version: '1.0.0', description: nil, swagger_ui_path: '/docs', redoc_path: '/redoc', openapi_json_path: '/openapi.json', contact: nil, license: nil, servers: [], security_schemes: {}) ⇒ OpenApiConfig

Returns a new instance of OpenApiConfig.

Parameters:

  • enabled (Boolean) (defaults to: false)

    Enable OpenAPI generation (default: false for zero overhead)

  • title (String) (defaults to: 'API')

    API title (default: “API”)

  • version (String) (defaults to: '1.0.0')

    API version (default: “1.0.0”)

  • description (String, nil) (defaults to: nil)

    API description (supports Markdown)

  • swagger_ui_path (String) (defaults to: '/docs')

    Path to serve Swagger UI (default: “/docs”)

  • redoc_path (String) (defaults to: '/redoc')

    Path to serve Redoc (default: “/redoc”)

  • openapi_json_path (String) (defaults to: '/openapi.json')

    Path to serve OpenAPI JSON spec (default: “/openapi.json”)

  • contact (ContactInfo, nil) (defaults to: nil)

    Contact information for the API

  • license (LicenseInfo, nil) (defaults to: nil)

    License information for the API

  • servers (Array<ServerInfo>) (defaults to: [])

    List of server URLs for different environments (default: [])

  • security_schemes (Hash<String, SecuritySchemeInfo>) (defaults to: {})

    Custom security schemes (auto-detected if not provided)



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/spikard/config.rb', line 292

def initialize(
  enabled: false,
  title: 'API',
  version: '1.0.0',
  description: nil,
  swagger_ui_path: '/docs',
  redoc_path: '/redoc',
  openapi_json_path: '/openapi.json',
  contact: nil,
  license: nil,
  servers: [],
  security_schemes: {}
)
  @enabled = enabled
  @title = title
  @version = version
  @description = description
  @swagger_ui_path = swagger_ui_path
  @redoc_path = redoc_path
  @openapi_json_path = openapi_json_path
  @contact = contact
  @license = license
  @servers = servers
  @security_schemes = security_schemes
end

Instance Attribute Details

#contactObject

Returns the value of attribute contact.



277
278
279
# File 'lib/spikard/config.rb', line 277

def contact
  @contact
end

#descriptionObject

Returns the value of attribute description.



277
278
279
# File 'lib/spikard/config.rb', line 277

def description
  @description
end

#enabledObject

Returns the value of attribute enabled.



277
278
279
# File 'lib/spikard/config.rb', line 277

def enabled
  @enabled
end

#licenseObject

Returns the value of attribute license.



277
278
279
# File 'lib/spikard/config.rb', line 277

def license
  @license
end

#openapi_json_pathObject

Returns the value of attribute openapi_json_path.



277
278
279
# File 'lib/spikard/config.rb', line 277

def openapi_json_path
  @openapi_json_path
end

#redoc_pathObject

Returns the value of attribute redoc_path.



277
278
279
# File 'lib/spikard/config.rb', line 277

def redoc_path
  @redoc_path
end

#security_schemesObject

Returns the value of attribute security_schemes.



277
278
279
# File 'lib/spikard/config.rb', line 277

def security_schemes
  @security_schemes
end

#serversObject

Returns the value of attribute servers.



277
278
279
# File 'lib/spikard/config.rb', line 277

def servers
  @servers
end

#swagger_ui_pathObject

Returns the value of attribute swagger_ui_path.



277
278
279
# File 'lib/spikard/config.rb', line 277

def swagger_ui_path
  @swagger_ui_path
end

#titleObject

Returns the value of attribute title.



277
278
279
# File 'lib/spikard/config.rb', line 277

def title
  @title
end

#versionObject

Returns the value of attribute version.



277
278
279
# File 'lib/spikard/config.rb', line 277

def version
  @version
end