Uh oh!
There was an error while loading. Please reload this page.
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 into
Conversation
ce6e6ec to
ccab373Comparealeung
commented
Dec 1, 2021
@RomanHotsiy I have rebased it on latest commit on upstream. |
RomanHotsiy
commented
Dec 1, 2021
@aleung how this option is different from |
aleung
commented
Dec 2, 2021
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 |
RomanHotsiy
commented
Dec 3, 2021
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)