Class: OpenApiAnnotator::Config

Inherits:
Struct
  • Object
show all
Defined in:
lib/open_api_annotator/config.rb

Defined Under Namespace

Classes: InvalidError

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#always_required_fieldsObject

Returns the value of attribute always_required_fields

Returns:

  • (Object)

    the current value of always_required_fields



2
3
4
# File 'lib/open_api_annotator/config.rb', line 2

def always_required_fields
  @always_required_fields
end

#application_controller_class_nameObject

Returns the value of attribute application_controller_class_name

Returns:

  • (Object)

    the current value of application_controller_class_name



2
3
4
# File 'lib/open_api_annotator/config.rb', line 2

def application_controller_class_name
  @application_controller_class_name
end

#application_serializer_class_nameObject

Returns the value of attribute application_serializer_class_name

Returns:

  • (Object)

    the current value of application_serializer_class_name



2
3
4
# File 'lib/open_api_annotator/config.rb', line 2

def application_serializer_class_name
  @application_serializer_class_name
end

#destination_pathObject

Returns the value of attribute destination_path

Returns:

  • (Object)

    the current value of destination_path



2
3
4
# File 'lib/open_api_annotator/config.rb', line 2

def destination_path
  @destination_path
end

#infoObject

Returns the value of attribute info

Returns:

  • (Object)

    the current value of info



2
3
4
# File 'lib/open_api_annotator/config.rb', line 2

def info
  @info
end

#path_regexpObject

Returns the value of attribute path_regexp

Returns:

  • (Object)

    the current value of path_regexp



2
3
4
# File 'lib/open_api_annotator/config.rb', line 2

def path_regexp
  @path_regexp
end

Instance Method Details

#application_controller_classObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/open_api_annotator/config.rb', line 29

def application_controller_class
  if application_controller_class_name
    application_controller_class_name.constantize
  else
    unless defined?(ApplicationController)
      raise <<~EOL
        Expected to define ApplicationController or set custom class like:

        ```
        OpenApiAnnotator.configure do |config|
          config.application_controller_class = BaseSerializer
        end
        ```
      EOL
    end
    ApplicationController
  end
end

#application_serializer_classObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/open_api_annotator/config.rb', line 10

def application_serializer_class
  if application_serializer_class_name
    application_serializer_class_name.constantize
  else
    unless defined?(ApplicationSerializer)
      raise <<~EOL
        Expected to define ApplicationSerializer or set custom class like:

        ```
        OpenApiAnnotator.configure do |config|
          config.application_serializer_class = BaseSerializer
        end
        ```
      EOL
    end
    ApplicationSerializer
  end
end

#validate!Object



48
49
50
51
52
53
54
55
# File 'lib/open_api_annotator/config.rb', line 48

def validate!
  validate_info!
  validate_destination_path!
  validate_path_regexp!
  validate_application_controller_class_name!
  validate_application_serializer_class_name!
  validate_always_required_fields!
end

#validate_always_required_fields!Object



100
101
102
# File 'lib/open_api_annotator/config.rb', line 100

def validate_always_required_fields!
  # Do nothing
end

#validate_application_controller_class_name!Object



96
97
98
# File 'lib/open_api_annotator/config.rb', line 96

def validate_application_controller_class_name!
  # Do nothing
end

#validate_application_serializer_class_name!Object



92
93
94
# File 'lib/open_api_annotator/config.rb', line 92

def validate_application_serializer_class_name!
  # Do nothing
end

#validate_destination_path!Object



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/open_api_annotator/config.rb', line 74

def validate_destination_path!
  unless destination_path
    raise InvalidError, <<~EOL
      You have to set `config.destination_path` like:

      ```
      OpenApiAnnotator.configure do |config|
        config.destination_path = Rails.root.join("api_spec.yml")
      end
      ```
    EOL
  end
end

#validate_info!Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/open_api_annotator/config.rb', line 57

def validate_info!
  unless info
    raise InvalidError, <<~EOL
      You have to set `OpenApi::Info` to `config.info` like:

      ```
      OpenApiAnnotator.configure do |config|
        config.info = OpenApi::Info.new(title: "Book API", version: "1")
      end
      ```

      You can see the detail of `OpenApi::Info` in
      https://www.rubydoc.info/gems/open_api/OpenApi/Info
    EOL
  end
end

#validate_path_regexp!Object



88
89
90
# File 'lib/open_api_annotator/config.rb', line 88

def validate_path_regexp!
  # Do nothing
end