rspec-openapi icon indicating copy to clipboard operation
rspec-openapi copied to clipboard

Generate multiple examples

Open AlexeyMatskevich opened this issue 1 year ago • 5 comments
trafficstars

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 avatar Apr 12 '24 18:04 AlexeyMatskevich

@exoego take a look, please

AlexeyMatskevich avatar Apr 17 '24 08:04 AlexeyMatskevich

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?

exoego avatar Apr 24 '24 02:04 exoego

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

rhiroe avatar Jun 08 '25 12:06 rhiroe

@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.

AlexeyMatskevich avatar Jun 08 '25 12:06 AlexeyMatskevich

@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']

rhiroe avatar Jun 08 '25 13:06 rhiroe

@AlexeyMatskevich any more thoughts on progressing with this?

Spence1115 avatar Aug 21 '25 23:08 Spence1115