Module: Tina4::Swagger
- Defined in:
- lib/tina4/swagger.rb
Class Method Summary collapse
-
.enabled? ⇒ Boolean
TINA4_SWAGGER_ENABLED — defaults to TINA4_DEBUG.
- .generate(routes = []) ⇒ Object
Class Method Details
.enabled? ⇒ Boolean
TINA4_SWAGGER_ENABLED — defaults to TINA4_DEBUG. Wired into RackApp’s /swagger serving (v3.13.40), so it genuinely gates whether the docs are served — it was dead code before.
32 33 34 35 36 37 38 |
# File 'lib/tina4/swagger.rb', line 32 def enabled? explicit = ENV["TINA4_SWAGGER_ENABLED"] if explicit && !explicit.empty? return %w[true 1 yes on].include?(explicit.to_s.strip.downcase) end %w[true 1 yes on].include?(ENV.fetch("TINA4_DEBUG", "").to_s.strip.downcase) end |
.generate(routes = []) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tina4/swagger.rb', line 7 def generate(routes = []) spec = base_spec route_list = routes.empty? ? Tina4::Router.routes : routes # Accumulators shared across routes: ORM models referenced # (-> components.schemas), tags used (-> top-level tags[]), seen # operationIds (de-dup — OpenAPI requires them unique). ctx = { models: {}, used_tags: [], seen_ids: [] } route_list.each do |route| add_route_to_spec(spec, route, ctx) end unless ctx[:models].empty? spec["components"]["schemas"] = {} ctx[:models].each do |name, klass| spec["components"]["schemas"][name] = model_schema(klass) end end spec["tags"] = ctx[:used_tags].map { |t| { "name" => t } } unless ctx[:used_tags].empty? spec end |