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

Customizations via metadata #36

Merged
merged 1 commit into from
Mar 17, 2022
Merged

Customizations via metadata #36

merged 1 commit into from
Mar 17, 2022

Conversation

blocknotes
Copy link
Contributor

@blocknotes blocknotes commented Mar 15, 2022

Nice gem!

Can I propose you a small PR to allow more customizations via RSpec metadata?

Combined with the configuration:
RSpec::OpenAPI.description_builder = -> (example) { example.metadata[:openapi_description] || example.description }

A usage example could be:

  describe 'GET /api/v1/posts', {
    openapi_summary: 'list all posts',
    openapi_description: 'list all posts ordered by pub_date',
    openapi_tags: %w[v1 posts],
  } do
    # ...
  end

If you like the idea, I could update the specs and the README.

@blocknotes blocknotes marked this pull request as draft March 15, 2022 07:24
@k0kubun
Copy link
Collaborator

k0kubun commented Mar 16, 2022

Using metadata for the purpose sensible to me. Please do update the specs and update README to document it.

How about overloading openapi: option and nesting keys under that though? i.e.

  describe 'GET /api/v1/posts', openapi: {
    summary: 'list all posts',
    description: 'list all posts ordered by pub_date',
    tags: %w[v1 posts],
  } do
    # ...
  end

When the option is taking a Hash, it's clear that it doesn't need to be openapi: false, so I think it doesn't conflict.

@blocknotes
Copy link
Contributor Author

How about overloading openapi: option and nesting keys under that though? i.e.

Sounds good to me.
I was thinking the same at the beginning but I didn't want to replace your current behaviour.

About description - do you think that I could also add a customization there? Or it's better to avoid overriding the RSpec::OpenAPI.description_builder configuration method?

So this line: https://github.com/k0kubun/rspec-openapi/blob/master/lib/rspec/openapi/record_builder.rb#L53
Could become:

description: example.metadata.dig(:openapi, :description) || RSpec::OpenAPI.description_builder.call(example),

@blocknotes
Copy link
Contributor Author

On second thought, I think that it could be good to let override also the description.
So I proceeded in that way.

@blocknotes blocknotes marked this pull request as ready for review March 16, 2022 17:23
Copy link
Collaborator

@k0kubun k0kubun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@k0kubun k0kubun merged commit 366657f into exoego:master Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants