Skip to content

Generate multiple examples #210

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AlexeyMatskevich
Copy link
Contributor

I tried to do the generation of a few examples as described here. I would like to get a review of my approach before I continue working on this feature.

The very design of this feature is also questionable, perhaps it makes sense to use the feature in roughly this way for simpler cases:

describe '#index', openapi: { enable_examples: true } do
    context 'when foo', openapi: { example_name: :foo }
    context 'when bar', openapi: { example_name: :bar }
end

In other cases I am concerned about the definition of unique examples, do I need to remove non-unique examples, or should I keep all examples? Maybe both options are needed for flexibility 🤔

@AlexeyMatskevich AlexeyMatskevich marked this pull request as draft April 12, 2024 18:13
@@ -0,0 +1,21 @@
# frozen_string_literal: true

class SharedExtractor

Check notice

Code scanning / Rubocop

Document classes and non-namespace modules.

Style/Documentation: Missing top-level documentation comment for `class SharedExtractor`.
@AlexeyMatskevich
Copy link
Contributor Author

@exoego take a look, please

@exoego
Copy link
Owner

exoego commented Apr 24, 2024

I am fine with the example_name approach.

How does this handle when some test cases have example_name but other cases don't for an endpoint?

In other cases I am concerned about the definition of unique examples, do I need to remove non-unique examples, or should I keep all examples? Maybe both options are needed for flexibility 🤔

I don't get the concern.
When do users specify same example_name to multiple test cases?

@rhiroe
Copy link
Contributor

rhiroe commented Jun 8, 2025

@AlexeyMatskevich
Hello, I am hoping this PR will resolve the related issue. Do you plan to continue working on it?

@AlexeyMatskevich
Copy link
Contributor Author

AlexeyMatskevich commented Jun 8, 2025

@rhiroe Hi, this is a conceptual question for me so far. We realize what we want to solve is to provide some sample examples so that the reader of the documentation can see some cases, which is some hack of OpenAPI limitations. However, how to achieve this is a complex issue where we need to think about design.
Then it's a flexibility issue where we want to throw all sample responses into examles or just certain ones, and we usually use factory_bot and from run to run the data is different and that's a problem.

Maybe the author (@exoego ) will have an opinion (sorry I ignored your question before)

p.s. I may have already forgotten my context on this issue.

@rhiroe
Copy link
Contributor

rhiroe commented Jun 8, 2025

@AlexeyMatskevich In my personal opinion,

Then it's a flexibility issue where we want to throw all sample responses into examles or just certain ones

For the ones we don't want to include, I think adding openapi: false metadata would be a good approach.

and we usually use factory_bot and from run to run the data is different and that's a problem.

Our team solves this by setting a fixed seed value when the OPENAPI environment variable is present.

RSpec.configure do |config|
  config.seed = 1 if ENV['OPENAPI']

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.

3 participants