21
21
use Vural \OpenAPIFaker \SchemaFaker \SchemaFaker ;
22
22
23
23
use function array_key_exists ;
24
+ use function method_exists ;
24
25
use function strtolower ;
25
26
26
27
final class OpenAPIFaker
27
28
{
28
29
private OpenApi $ openAPISchema ;
30
+ private Options $ options ;
29
31
30
32
/** @codeCoverageIgnore */
31
33
private function __construct ()
32
34
{
35
+ $ this ->options = new Options ();
33
36
}
34
37
35
38
/**
@@ -81,7 +84,7 @@ public function mockRequest(
81
84
throw NoRequest::forPathAndMethodAndContentType ($ path , $ method , $ contentType );
82
85
}
83
86
84
- return (new SchemaFaker ($ contents [$ contentType ]->schema ))->generate ();
87
+ return (new SchemaFaker ($ contents [$ contentType ]->schema , $ this -> options ))->generate ();
85
88
}
86
89
87
90
/**
@@ -117,7 +120,7 @@ public function mockResponse(
117
120
/** @var MediaType $content */
118
121
$ content = $ contents [$ contentType ];
119
122
120
- return (new SchemaFaker ($ content ->schema ))->generate ();
123
+ return (new SchemaFaker ($ content ->schema , $ this -> options ))->generate ();
121
124
}
122
125
123
126
/**
@@ -138,7 +141,23 @@ public function mockComponentSchema(string $schemaName)
138
141
/** @var Schema $schema */
139
142
$ schema = $ this ->openAPISchema ->components ->schemas [$ schemaName ];
140
143
141
- return (new SchemaFaker ($ schema ))->generate ();
144
+ return (new SchemaFaker ($ schema , $ this ->options ))->generate ();
145
+ }
146
+
147
+ /**
148
+ * @param array{minItems?:?int, maxItems?:?int} $options
149
+ */
150
+ public function setOptions (array $ options ): self
151
+ {
152
+ foreach ($ options as $ key => $ value ) {
153
+ if (! method_exists ($ this ->options , 'set ' . $ key )) {
154
+ continue ;
155
+ }
156
+
157
+ $ this ->options ->{'set ' . $ key }($ value );
158
+ }
159
+
160
+ return $ this ;
142
161
}
143
162
144
163
/**
0 commit comments