class OasRails::Builders::ContentBuilder
def build
def build { "application/json": @media_type } end
def from_model_class(klass)
def from_model_class(klass) return self unless klass.ancestors.include? ActiveRecord::Base model_schema = Builders::EsquemaBuilder.send("build_#{@context}_schema", klass:) model_schema["required"] = [] schema = { type: "object", properties: { klass.to_s.downcase => model_schema } } examples = Spec::MediaType.search_for_examples_in_tests(klass, context: @context) @media_type.schema = @specification.components.add_schema(schema) @media_type.examples = @media_type.examples.merge(examples) self end
def initialize(specification, context)
def initialize(specification, context) @context = context || :incoming @specification = specification @media_type = Spec::MediaType.new(specification) end
def with_examples(examples)
def with_examples(examples) @media_type.examples = @specification.components.add_example(examples) self end
def with_examples_from_tags(tags)
def with_examples_from_tags(tags) @media_type.examples = @media_type.examples.merge(tags.each_with_object({}).with_index(1) do |(example, result), _index| key = example.text.downcase.gsub(' ', '_') value = { "summary" => example.text, "value" => example.content } result[key] = @specification.components.add_example(value) end) self end
def with_schema(schema)
def with_schema(schema) @media_type.schema = @specification.components.add_schema(schema) self end