Class: AnotherApi::OpenAPI::SpecRenderer
- Inherits:
-
Object
- Object
- AnotherApi::OpenAPI::SpecRenderer
- Defined in:
- lib/another_api/openapi/spec_renderer.rb
Overview
Renders the full OpenAPI specification and caches the result.
In production the spec is computed once and cached for the lifetime of the process. In development it is recomputed when any file under configuration.watched_dirs changes (mtime-based check).
Class Method Summary collapse
-
.render_hash(configuration: AnotherApi::OpenAPI.configuration) ⇒ Hash
The raw OpenAPI spec hash.
-
.render_json(configuration: AnotherApi::OpenAPI.configuration) ⇒ String
JSON string of the OpenAPI spec.
-
.reset! ⇒ Object
Force a cache reset (useful in tests or after deploy).
Class Method Details
.render_hash(configuration: AnotherApi::OpenAPI.configuration) ⇒ Hash
Returns the raw OpenAPI spec hash.
21 22 23 24 |
# File 'lib/another_api/openapi/spec_renderer.rb', line 21 def render_hash(configuration: AnotherApi::OpenAPI.configuration) refresh_cache(configuration) unless cache_valid?(configuration) @cached_hash end |
.render_json(configuration: AnotherApi::OpenAPI.configuration) ⇒ String
Returns JSON string of the OpenAPI spec.
15 16 17 18 |
# File 'lib/another_api/openapi/spec_renderer.rb', line 15 def render_json(configuration: AnotherApi::OpenAPI.configuration) refresh_cache(configuration) unless cache_valid?(configuration) @cached_json end |
.reset! ⇒ Object
Force a cache reset (useful in tests or after deploy).
27 28 29 30 31 32 |
# File 'lib/another_api/openapi/spec_renderer.rb', line 27 def reset! @cached_json = nil @cached_hash = nil @cached_at = nil @last_mtime = nil end |