Class: Praxis::Docs::OpenApiGenerator
- Inherits:
-
Object
- Object
- Praxis::Docs::OpenApiGenerator
- Includes:
- Singleton
- Defined in:
- lib/praxis/docs/open_api_generator.rb
Constant Summary collapse
- API_DOCS_DIRNAME =
'docs/openapi'
- EXCLUDED_TYPES_FROM_OUTPUT =
Set.new([ Attributor::Boolean, Attributor::CSV, Attributor::DateTime, Attributor::Date, Attributor::Float, Attributor::Hash, Attributor::Ids, Attributor::Integer, Attributor::Object, Attributor::String, Attributor::Symbol, Attributor::URI ]).freeze
Instance Attribute Summary collapse
-
#doc_root_dir ⇒ Object
readonly
Returns the value of attribute doc_root_dir.
-
#infos_by_version ⇒ Object
readonly
Returns the value of attribute infos_by_version.
-
#resources_by_version ⇒ Object
readonly
Returns the value of attribute resources_by_version.
Class Method Summary collapse
-
.templatize_url(string) ⇒ Object
substitutes “:params_like_so” for params_like_so.
Instance Method Summary collapse
- #configure_root(root) ⇒ Object
-
#initialize ⇒ OpenApiGenerator
constructor
A new instance of OpenApiGenerator.
- #register_seen_component(type) ⇒ Object
- #save! ⇒ Object
Constructor Details
#initialize ⇒ OpenApiGenerator
Returns a new instance of OpenApiGenerator.
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/praxis/docs/open_api_generator.rb', line 49 def initialize require 'yaml' @resources_by_version = Hash.new do |h, k| h[k] = Set.new end # List of types that we have seen/marked as necessary to list in the components/schemas section # These should contain any mediatype define in the versioned controllers plus any type # for which we've explicitly rendered a $ref schema @seen_components_for_current_version = Set.new @infos = ApiDefinition.instance.infos collect_resources end |
Instance Attribute Details
#doc_root_dir ⇒ Object (readonly)
Returns the value of attribute doc_root_dir.
30 31 32 |
# File 'lib/praxis/docs/open_api_generator.rb', line 30 def doc_root_dir @doc_root_dir end |
#infos_by_version ⇒ Object (readonly)
Returns the value of attribute infos_by_version.
30 31 32 |
# File 'lib/praxis/docs/open_api_generator.rb', line 30 def infos_by_version @infos_by_version end |
#resources_by_version ⇒ Object (readonly)
Returns the value of attribute resources_by_version.
30 31 32 |
# File 'lib/praxis/docs/open_api_generator.rb', line 30 def resources_by_version @resources_by_version end |
Class Method Details
.templatize_url(string) ⇒ Object
substitutes “:params_like_so” for params_like_so
33 34 35 |
# File 'lib/praxis/docs/open_api_generator.rb', line 33 def self.templatize_url(string) Mustermann.new(string).to_templates.first end |
Instance Method Details
#configure_root(root) ⇒ Object
63 64 65 |
# File 'lib/praxis/docs/open_api_generator.rb', line 63 def configure_root(root) @root = root end |
#register_seen_component(type) ⇒ Object
67 68 69 |
# File 'lib/praxis/docs/open_api_generator.rb', line 67 def register_seen_component(type) @seen_components_for_current_version.add(type) end |
#save! ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/praxis/docs/open_api_generator.rb', line 37 def save! raise 'You need to configure the root directory before saving (configure_root(<dir>))' unless @root initialize_directories # Restrict the versions listed in the index file to the ones for which we have at least 1 resource write_index_file(for_versions: resources_by_version.keys) resources_by_version.each_key do |version| @seen_components_for_current_version = Set.new write_version_file(version) end end |