module OpenAPI::Generator::Controller::Schema

Overview

This module contains various OpenAPI yaml syntax shortcuts.

Extended Modules

Defined in:

openapi-generator/controller.cr

Instance Method Summary

Instance Method Detail

def error(code, message = nil) #

Generate an error response as a response object.

# message is optional and defaults to a [standard error description](https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml) based on the code.
Schema.error 400, message: "Bad Request"

# Produces:

<<-YAML
400:
  description: Bad Request
YAML

def header(name, description, type = "string") #

Generate a header object.

Schema.header "X-Header", "A custom header", type: "string"

# Produces:

<<-YAML
"X-Header":
  schema:
    type: string
  description: A custom header
YAML

def header_param(name, description, *, required = false, type = "string") #

Generate a header parameter object.

Schema.header_param "X-Header", "A custom header", required: true, type: "integer"

# Produces

<<-YAML
- in: header
  name: "X-Header"
  description: A custom header
  required: true
  schema:
    type: integer
YAML

def qp(name, description, *, required = false, type = "string") #

Generate a query parameter as a parameter object.

Schema.qp "id", "Filter by id", required: true, type: "integer"

# Produces:

<<-YAML
- in: query
  name: id
  description: Filter by id
  required: true
  schema:
    type: integer
YAML

def ref(schema, *, content_type = "application/json") #

Generates a schema reference as a media type object.

Useful when dealing with objects including the Serializable module.

Schema.ref SerializableClass, content_type: "application/x-www-form-urlencoded"

# Produces:

<<-YAML
application/x-www-form-urlencoded:
  schema:
    $ref: '#/components/schemas/SerializableClass'
YAML

def ref_array(schema, *, content_type = "application/json") #

Generates an array of schema references as a media type object.

Useful when dealing with objects including the Serializable module.

Schema.ref_array SerializableClass, content_type: "application/x-www-form-urlencoded"

# Produces:

<<-YAML
application/x-www-form-urlencoded:
  schema:
    type: array,
    items:
      $ref: '#/components/schemas/SerializableClass'
YAML

def string_array(*, content_type = "application/json") #

Generates an array of string as a media type object.

Schema.string_array content_type: "application/x-www-form-urlencoded"

# Produces:

<<-YAML
application/x-www-form-urlencoded:
  schema:
    type: array,
    items:
      type: string
YAML