Class: AsyncapiCable::SchemasController

Inherits:
ActionController::API
  • Object
show all
Defined in:
app/controllers/asyncapi_cable/schemas_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



5
6
7
8
# File 'app/controllers/asyncapi_cable/schemas_controller.rb', line 5

def index
  schemas = AsyncapiCable.configuration.schemas.keys.map(&:to_s)
  render json: {schemas: schemas}
end

#showObject



10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/asyncapi_cable/schemas_controller.rb', line 10

def show
  schema_name = params[:id]
  return head :not_found unless AsyncapiCable.configuration.schemas.key?(schema_name.to_sym)

  file_path = schema_file_path(schema_name)
  return head :not_found unless File.exist?(file_path)

  content_type = file_path.end_with?(".json") ? "application/json" : "application/x-yaml"
  render plain: File.read(file_path), content_type: content_type
end