module OpenAPI::Generator::Controller

Overview

This module, when included, will register every instance methods annotated with the OpenAPI annotation.

Example

class Controller
  include OpenAPI::Generator::Controller

  @[OpenAPI(<<-YAML
    tags:
    - tag
    summary: A brief summary of the method.
    requestBody:
      content:
        #{Schema.ref SerializableClass}
        application/x-www-form-urlencoded:
          schema:
            $ref: '#/components/schemas/SerializableClass'
      required: true
    responses:
      "303":
        description: Operation completed successfully, and redirects to /.
      "404":
        description: Data not found.
      #{Schema.error 400}
  YAML
  )]
  def method; end
end

Usage

Including this module will register and mark every instance method annotated with a valid @[OpenAPI] annotation during the compilation phase. These methods will then be taken into account when calling the Generator as long as the method can be mapped to a route.

The Schema module contains various helpers to generate YAML parts.

Defined in:

openapi-generator/controller.cr

Constant Summary

CONTROLLER_OPS = {} of String => YAML::Any

Macro Summary

Macro Detail

macro open_api(yaml_op = "{}") #

This macro is used to register a class as an OpenAPI Operation Object.

The argument must be a valid YAML representation of an OpenAPI operation object.

opan_api <<-YAML
  tags:
  - tag
  summary: A brief summary of the method.
  responses:
    200:
      description: Ok.
YAML