Feature: Don't auto generate sample for non-required object properties#123
Feature: Don't auto generate sample for non-required object properties#123aleung wants to merge 1 commit intoRedocly:mainfrom
Conversation
ce6e6ec to
ccab373
Compare
|
@RomanHotsiy I have rebased it on latest commit on upstream. |
|
@aleung how this option is different from |
|
When it('should skip non-required properties without explicit example value', () => {
res = sampleObject({
required: ['e'],
properties: {
a: { type: 'string', enum: ['foo', 'bar'] },
b: { type: 'integer', default: 100 },
c: { type: 'string' },
d: { type: 'string', example: 'Example' },
e: { type: 'string', enum: ['foo', 'bar'] },
f: { type: 'string', const: 'const' },
},
}, { disableNonRequiredAutoGen: true });
expect(res).to.deep.equal({
b: 100,
d: 'Example',
e: 'foo',
f: 'const',
});
});
it('should skip non-required properties', () => {
res = sampleObject({
required: ['e'],
properties: {
a: { type: 'string', enum: ['foo', 'bar'] },
b: { type: 'integer', default: 100 },
c: { type: 'string' },
d: { type: 'string', example: 'Example' },
e: { type: 'string', enum: ['foo', 'bar'] },
f: { type: 'string', const: 'const' },
},
}, { skipNonRequired: true });
expect(res).to.deep.equal({
e: 'foo',
});
});The rationale of adding this option is:
An API request/response body has a lot of optional properties. Sometimes it's too heavy to give example to every properties; but we want to ensure reader understand the usage of some important properties so we give example with "real" value for those properties only to make the whole request/response example reflect to a business use case. It isn't support in current software, so I propose this |
|
I see. I would spend a little more time to think about the name of this option to make it more clear. |
Add an option to disable sample auto generation for non-required object properties when the schema hasn't explicit example nor default value.
This MR is for Redocly/redoc#1490 (comment)