Class: Apipie::SwaggerGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/apipie/swagger_generator.rb

Class Method Summary collapse

Class Method Details

.generate_from_resources(resources, version:, language:, clear_warnings: false) ⇒ Object

Parameters:



4
5
6
7
8
9
10
11
# File 'lib/apipie/swagger_generator.rb', line 4

def self.generate_from_resources(resources, version:, language:, clear_warnings: false)
  Apipie::Generator::Swagger::Schema.new(
    resources,
    version: version,
    language: language,
    clear_warnings: clear_warnings
  ).generate
end

.json_schema_for_method_response(method, return_code, allow_nulls) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/apipie/swagger_generator.rb', line 13

def self.json_schema_for_method_response(method, return_code, allow_nulls)
  response = method.returns.find { |response| response.code.to_s == return_code.to_s }

  return if response.blank?

  http_method = method.apis.first.http_method

  schema = Apipie::Generator::Swagger::MethodDescription::ResponseSchemaService.new(
    response,
    allow_null: allow_nulls,
    http_method: http_method,
    controller_method: method
  ).to_swagger

  definitions = Apipie::Generator::Swagger::ReferencedDefinitions.instance.definitions

  if definitions.present?
    schema[:definitions] = definitions
  end

  schema
end

.json_schema_for_self_describing_class(cls, allow_nulls) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/apipie/swagger_generator.rb', line 36

def self.json_schema_for_self_describing_class(cls, allow_nulls)
  Apipie::Generator::Swagger::MethodDescription::ResponseSchemaService.new(
    ResponseDescriptionAdapter.from_self_describing_class(cls),
    allow_null: allow_nulls,
    http_method: nil,
    controller_method: nil
  ).to_swagger
end