Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluate proc for RSpec::OpenAPI.title #171

Open
alexpapworth opened this issue Jan 31, 2024 · 4 comments
Open

Evaluate proc for RSpec::OpenAPI.title #171

alexpapworth opened this issue Jan 31, 2024 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@alexpapworth
Copy link

My use case is generating different openapi files from different RSpec request files. The RSpec::OpenAPI.path proc is great to export YAML to different files, but I was surprised to see I couldn't do the same with RSpec::OpenAPI.title

Unfortunately the following snippet generates: title: !ruby/object:Proc {}

RSpec::OpenAPI.title = -> (example) {
  return "Customer API" if example.file_path == "./spec/requests/customer_api_spec.rb"
  return "Reseller API" if example.file_path == "./spec/requests/resellers_api_spec.rb"

  "API"
}
@exoego
Copy link
Owner

exoego commented Jan 31, 2024

How about #162

@alexpapworth
Copy link
Author

alexpapworth commented Feb 1, 2024

Ah interesting. My usecase is slightly different. I would favour a proc on RSpec::OpenAPI.title in a single config file rather than creating the multiple config files.

@exoego exoego added enhancement New feature or request good first issue Good for newcomers labels Feb 14, 2024
@josefggx
Copy link

@exoego @alexpapworth, Would it be ideal to assign the title based on the path of the example, or on the file path of the resulting schema? Because if the example is used, I think there could be more titles than schema files, and titles would end up being overwritten if not managed properly. I can provide a solution for both, let me know which would be the preferred configuration:

# Option A - Resulting schema file path:
RSpec::OpenAPI.title = -> (path) {
  case path
  when %r[doc/openapi/v1.yaml] then 'API v1 Documentation'
  when %r[doc/openapi/v2.yaml] then 'API v2 Documentation'
  else 'OpenAPI Documentation'
  end
}

# Option B - Example file path:
RSpec::OpenAPI.title = -> (example) {
  case example.file_path
  when %r[spec/requests/api/v1/] then 'API v1 Documentation'
  when %r[spec/requests/api/v2/] then 'API v2 Documentation'
  else 'OpenAPI Documentation'
  end
}

@alexpapworth
Copy link
Author

Ooh interesting. I'm leaning towards Option B, because then the lambda will take the same parameters as RSpec::OpenAPI.path = currently does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants