@@ -13,6 +13,7 @@ export class MediaTypeModel {
13
13
schema ?: SchemaModel ;
14
14
name : string ;
15
15
isRequestType : boolean ;
16
+ onlyRequiredInSamples : boolean ;
16
17
17
18
/**
18
19
* @param isRequestType needed to know if skipe RO/RW fields in objects
@@ -27,6 +28,7 @@ export class MediaTypeModel {
27
28
this . name = name ;
28
29
this . isRequestType = isRequestType ;
29
30
this . schema = info . schema && new SchemaModel ( parser , info . schema , '' , options ) ;
31
+ this . onlyRequiredInSamples = options . onlyRequiredInSamples ;
30
32
if ( info . examples !== undefined ) {
31
33
this . examples = mapValues ( info . examples , example => new ExampleModel ( parser , example ) ) ;
32
34
} else if ( info . example !== undefined ) {
@@ -39,12 +41,17 @@ export class MediaTypeModel {
39
41
}
40
42
41
43
generateExample ( parser : OpenAPIParser , info : OpenAPIMediaType ) {
44
+ const samplerOptions = {
45
+ skipReadOnly : this . isRequestType ,
46
+ skipNonRequired : this . isRequestType && this . onlyRequiredInSamples ,
47
+ skipWriteOnly : ! this . isRequestType ,
48
+ } ;
42
49
if ( this . schema && this . schema . oneOf ) {
43
50
this . examples = { } ;
44
51
for ( const subSchema of this . schema . oneOf ) {
45
52
const sample = Sampler . sample (
46
53
subSchema . rawSchema ,
47
- { skipReadOnly : this . isRequestType , skipWriteOnly : ! this . isRequestType } ,
54
+ samplerOptions ,
48
55
parser . spec ,
49
56
) ;
50
57
@@ -61,7 +68,7 @@ export class MediaTypeModel {
61
68
default : new ExampleModel ( parser , {
62
69
value : Sampler . sample (
63
70
info . schema ,
64
- { skipReadOnly : this . isRequestType , skipWriteOnly : ! this . isRequestType } ,
71
+ samplerOptions ,
65
72
parser . spec ,
66
73
) ,
67
74
} ) ,
0 commit comments