@@ -177,6 +177,20 @@ public function getParamExample(array $param): string
177
177
return $ output ;
178
178
}
179
179
180
+ public function getReadOnlyProperties (array $ parameter , string $ responseModel , array $ spec = []): array
181
+ {
182
+ // fwrite(STDOUT, json_encode($parameter) . "\n");
183
+ // fwrite(STDOUT, json_encode($spec['definitions'][$responseModel]) . "\n");
184
+ $ properties = [];
185
+ foreach ($ spec ['definitions ' ][$ responseModel ]['properties ' ] as $ property ) {
186
+ if (isset ($ property ['readOnly ' ]) && $ property ['readOnly ' ]) {
187
+ $ properties [] = $ property ['name ' ];
188
+ }
189
+ }
190
+
191
+ return $ properties ;
192
+ }
193
+
180
194
public function getTypeName (array $ parameter , array $ method = []): string
181
195
{
182
196
if (isset ($ parameter ['enumName ' ])) {
@@ -224,7 +238,7 @@ public function getTypeName(array $parameter, array $method = []): string
224
238
if ($ method ['method ' ] === 'post ' ) {
225
239
return "Document extends Models.DefaultDocument ? Partial<Models.Document> & Record<string, any> : Partial<Models.Document> & Omit<Document, keyof Models.Document> " ;
226
240
}
227
- if ($ method ['method ' ] === 'patch ' ) {
241
+ if ($ method ['method ' ] === 'patch ' || $ method [ ' method ' ] === ' put ' ) {
228
242
return "Document extends Models.DefaultDocument ? Partial<Models.Document> & Record<string, any> : Partial<Models.Document> & Partial<Omit<Document, keyof Models.Document>> " ;
229
243
}
230
244
}
@@ -336,6 +350,9 @@ public function getFilters(): array
336
350
new TwigFilter ('getPropertyType ' , function ($ value , $ method = []) {
337
351
return $ this ->getTypeName ($ value , $ method );
338
352
}),
353
+ new TwigFilter ('getReadOnlyProperties ' , function ($ value , $ responseModel , $ spec = []) {
354
+ return $ this ->getReadOnlyProperties ($ value , $ responseModel , $ spec );
355
+ }),
339
356
new TwigFilter ('getSubSchema ' , function (array $ property , array $ spec ) {
340
357
return $ this ->getSubSchema ($ property , $ spec );
341
358
}),
0 commit comments