Skip to content

Using RSpec::OpenAPI.path = -> but for different audiences #161

Description

@ipepe

Contextual snippet:

RSpec::OpenAPI.path = -> (example) {
  case example.file_path
  when %r[spec/requests/api/v1/] then 'doc/openapi/v1.yaml'
  when %r[spec/requests/api/v2/] then 'doc/openapi/v2.yaml'
  else 'doc/openapi.yaml'
  end
}

I really like the idea behind generating multiple schemas, but the current configuration causes a caveat that makes this feature challenging to use. (I didn't test this in practice but that is what I assume happens based on documentation)

It's because these different schema files, which might be targeted at different audiences are sharing common values for other configuration options like:

RSpec::OpenAPI.title = 'OpenAPI Documentation'
RSpec::OpenAPI.enable_example = false
RSpec::OpenAPI.application_version = '1.0.0'
RSpec::OpenAPI.info = {
  description: 'My beautiful API',
  license: {
    'name': 'Apache 2.0',
    'url': 'https://www.apache.org/licenses/LICENSE-2.0.html'
  }
}
RSpec::OpenAPI.request_headers = %w[X-Authorization-Token]
RSpec::OpenAPI.response_headers = %w[X-Cursor]
RSpec::OpenAPI.servers = [{ url: 'http://localhost:3000' }]
RSpec::OpenAPI.security_schemes = {
  'MyToken' => {
    description: 'Authenticate API requests via a JWT',
    type: 'http',
    scheme: 'bearer',
    bearerFormat: 'JWT',
  },
}
RSpec::OpenAPI.comment = 'comment'
RSpec::OpenAPI.description_builder = -> (example) { example.description }
RSpec::OpenAPI.summary_builder = ->(example) { example.metadata.dig(:example_group, :openapi, :summary) }
RSpec::OpenAPI.tags_builder = -> (example) { example.metadata.dig(:example_group, :parent_example_group, :openapi, :tags) }
RSpec::OpenAPI.example_types = %i[request]
RSpec::OpenAPI.ignored_path_params = %i[controller action format]

I don't have a suggestion on how this should be changed. But currently, I cannot generate schema for our frontend API team that is internal and second one for external and public API schema for our consumers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions