|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +if ENV["OPENAPI"] |
| 4 | + require "rspec/openapi" |
| 5 | + |
| 6 | + RSpec::OpenAPI.path = File.expand_path("../../docs/openapi.yml", __dir__) |
| 7 | + RSpec::OpenAPI.title = "Alchemy CMS JSON API" |
| 8 | + RSpec::OpenAPI.application_version = Alchemy::JsonApi::VERSION |
| 9 | + RSpec::OpenAPI.info = { |
| 10 | + description: <<~DESC.strip, |
| 11 | + A JSON:API compliant API for AlchemyCMS. |
| 12 | +
|
| 13 | + All responses follow the JSON:API specification. Use the `include` query parameter to |
| 14 | + sideload related resources, `filter` for Ransack-based filtering, and `page` for pagination. |
| 15 | + DESC |
| 16 | + license: { |
| 17 | + name: "BSD-3-Clause", |
| 18 | + url: "https://opensource.org/licenses/BSD-3-Clause" |
| 19 | + }, |
| 20 | + contact: { |
| 21 | + name: "AlchemyCMS", |
| 22 | + url: "https://www.alchemy-cms.com/" |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + RSpec::OpenAPI.comment = <<~COMMENT |
| 27 | + This file is auto-generated by rspec-openapi. |
| 28 | + Run `OPENAPI=1 bundle exec rspec` to regenerate. |
| 29 | + COMMENT |
| 30 | + |
| 31 | + RSpec::OpenAPI.servers = [{url: "/jsonapi", description: "Mounted engine path (default)"}] |
| 32 | + RSpec::OpenAPI.response_headers = %w[ETag Cache-Control Last-Modified] |
| 33 | + RSpec::OpenAPI.example_types = %i[request] |
| 34 | + |
| 35 | + # Exclude the openapi endpoint itself from generation |
| 36 | + RSpec::OpenAPI.ignored_paths = [/openapi/] |
| 37 | + |
| 38 | + # Tag endpoints by controller name |
| 39 | + RSpec::OpenAPI.tags_builder = ->(example) { |
| 40 | + controller = example.metadata.dig(:request, :controller) || |
| 41 | + example.metadata[:described_class].to_s |
| 42 | + case controller |
| 43 | + when /Admin::LayoutPages/ then ["Admin Layout Pages"] |
| 44 | + when /Admin::Pages/ then ["Admin Pages"] |
| 45 | + when /LayoutPages/ then ["Layout Pages"] |
| 46 | + when /Nodes/ then ["Nodes"] |
| 47 | + when /Pages/ then ["Pages"] |
| 48 | + else [] |
| 49 | + end |
| 50 | + } |
| 51 | +end |
0 commit comments