Module: Schemable

Defined in:
lib/schemable.rb,
lib/schemable/version.rb,
lib/schemable/definition.rb,
lib/schemable/configuration.rb,
lib/schemable/schema_modifier.rb,
lib/schemable/request_schema_generator.rb,
lib/schemable/included_schema_generator.rb,
lib/schemable/response_schema_generator.rb,
lib/generators/schemable/model_generator.rb,
lib/schemable/attribute_schema_generator.rb,
lib/generators/schemable/install_generator.rb,
lib/schemable/relationship_schema_generator.rb

Overview

The Schemable module provides a set of classes and methods for generating and modifying schemas in JSONAPI format. It includes classes for generating attribute, relationship, included, response, and request schemas. It also provides a configuration class for setting up the module’s behavior.

The following example shows how to use the Schemable module to generate a schema for a Comment model.

# config/initializers/schemable.rb
Schemable.configure do |config|
  #... chosen configuration options ...
end

 # lib/swagger/definitions/comment.rb
class Swagger::Definitions::Comment < Schemable::Definition; end

 # whenever you need to generate the schema for a Comment model.
 # i.e. in RSwag's swagger_helper.rb

 #  spec/swagger_helper.rb
 # ...
RSpec.configure do |config|

  config.swagger_docs = {
    # ...
    components: {
      # ...
      schemas: Swagger::Definitions::Comment.generate.flatten.reduce({}, :merge)
      # ...
    }
    # ...
  }
  # ...
end

Defined Under Namespace

Classes: AttributeSchemaGenerator, Configuration, Definition, Error, IncludedSchemaGenerator, InstallGenerator, ModelGenerator, RelationshipSchemaGenerator, RequestSchemaGenerator, ResponseSchemaGenerator, SchemaModifier

Constant Summary collapse

VERSION =
'1.0.3'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Accessor for the module’s configuration.



59
60
61
# File 'lib/schemable.rb', line 59

def configuration
  @configuration
end

Class Method Details

.configure {|Configuration| ... } ⇒ Object

Configures the module. If a block is given, it yields the current configuration.

Yields:



64
65
66
67
# File 'lib/schemable.rb', line 64

def configure
  @configuration ||= Configuration.new
  yield(@configuration) if block_given?
end