Class: Apipie::Generator::Swagger::ResourceDescriptionComposite

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

Instance Method Summary collapse

Constructor Details

#initialize(resource_descriptions, language:) ⇒ ResourceDescriptionComposite

Returns a new instance of ResourceDescriptionComposite.

Parameters:



3
4
5
6
# File 'lib/apipie/generator/swagger/resource_description_composite.rb', line 3

def initialize(resource_descriptions, language:)
  @resource_descriptions = resource_descriptions
  @language = language
end

Instance Method Details

#pathsHash

Returns:

  • (Hash)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/apipie/generator/swagger/resource_description_composite.rb', line 36

def paths
  results = {}

  @resource_descriptions.each do |resource_description|
    resource_description._methods.each_value do |method_description|
      next unless method_description.show

      result = Apipie::Generator::Swagger::MethodDescription::ApiSchemaService
               .new(
                 Apipie::Generator::Swagger::MethodDescription::Decorator.new(method_description),
                 language: @language
               )
               .call

      results.deep_merge!(result)
    end
  end

  results
end

#tagsArray

Returns:

  • (Array)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/apipie/generator/swagger/resource_description_composite.rb', line 17

def tags
  results = []

  @resource_descriptions.each do |resource_description|
    next unless resource_description._full_description

    results << {
      name: resource_description._id,
      description: Apipie.app.translate(
        resource_description._full_description,
        @language
      )
    }
  end

  results
end

#to_swaggerHash{Symbol->Array | Hash

Returns ].

Returns:

  • (Hash{Symbol->Array | Hash)

    ]



9
10
11
12
13
14
# File 'lib/apipie/generator/swagger/resource_description_composite.rb', line 9

def to_swagger
  {
    tags: tags,
    paths: paths
  }
end