class WarpEngine::Configuration::SchemaDSL
An OpenAPI object schema for one additional resource entry. The names are the attributes’ own; the schema carries them in camelCase, as AdditionalResource#serialize does. null: true lets a property be null, its enum included.
api_schema do string :locale, :title string :og_type, null: true, enum: %w[website article] end
Each JSON type in TYPES is a method taking one or more property names and the null, enum and extra schema options; it raises ArgumentError without a name.
Constants
- TYPES
-
The JSON schema types that get a
DSLmethod.
Public Class Methods
Source
# File lib/warp_engine/configuration/schema_dsl.rb, line 21 def self.build(&block) schema = new schema.instance_eval(&block) schema.to_h end
Evaluates block in a new SchemaDSL and returns the schema Hash.
Source
# File lib/warp_engine/configuration/schema_dsl.rb, line 28 def initialize @properties = {} end
Creates an empty object schema.
Public Instance Methods
# File lib/warp_engine/configuration/schema_dsl.rb, line 43 def property(name, type, null: false, enum: nil, **extra) schema = { type: null ? [ type, "null" ] : type } schema[:enum] = null && !enum.include?(nil) ? [ nil, *enum ] : enum if enum @properties[name.to_s.camelize(:lower).to_sym] = schema.merge(extra) end
Adds the property name (camelCased) of JSON type. With null the type also allows null and nil joins the enum; extra is merged into the property schema.
Source
# File lib/warp_engine/configuration/schema_dsl.rb, line 50 def to_h = { type: "object", properties: @properties }
Returns the schema as { type: "object", properties: {...} }.