Class: Apipie::Generator::Swagger::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/apipie/generator/swagger/schema.rb

Instance Method Summary collapse

Constructor Details

#initialize(resource_descriptions, version:, language:, clear_warnings:) ⇒ Schema

Returns a new instance of Schema.

Parameters:



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/apipie/generator/swagger/schema.rb', line 3

def initialize(resource_descriptions, version:, language:, clear_warnings:)
  @resource_descriptions = resource_descriptions
  @language = language
  @clear_warnings = clear_warnings
  @swagger = {
    swagger: '2.0',
    info: {
      title: Apipie.configuration.app_name.to_s,
      description: "#{Apipie.app_info(version, @language)}#{Apipie.configuration.copyright}",
      version: version.to_s,
      'x-copyright': Apipie.configuration.copyright
    },
    basePath: Apipie.api_base_url(version),
    consumes: [],
    paths: {},
    definitions: {},
    schemes: Apipie.configuration.generator.swagger.schemes,
    tags: [],
    securityDefinitions: Apipie.configuration.generator.swagger.security_definitions,
    security: Apipie.configuration.generator.swagger.global_security
  }
end

Instance Method Details

#generateObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/apipie/generator/swagger/schema.rb', line 26

def generate
  if Apipie.configuration.generator.swagger.api_host.present?
    @swagger[:host] = Apipie.configuration.generator.swagger.api_host
  end

  if Apipie.configuration.generator.swagger.content_type_input == :json
    @swagger[:consumes] = ['application/json']
    @swagger[:info][:title] += ' (params in:body)'
  else
    @swagger[:consumes] = ['application/x-www-form-urlencoded', 'multipart/form-data']
    @swagger[:info][:title] += ' (params in:formData)'
  end

  if @clear_warnings
    Apipie::Generator::Swagger::WarningWriter.instance.clear!
  end

  @swagger.merge!(tags_and_paths)

  if Apipie.configuration.generator.swagger.generate_x_computed_id_field?
    @swagger[:info]['x-computed-id'] =
      Apipie::Generator::Swagger::ComputedInterfaceId.instance.id
  end

  @swagger[:definitions] =
    Apipie::Generator::Swagger::ReferencedDefinitions.instance.definitions

  @swagger
end