@@ -177,6 +177,26 @@ public function getParamExample(array $param): string
177177 return $ output ;
178178 }
179179
180+ public function getReadOnlyProperties (array $ parameter , string $ responseModel , array $ spec = []): array
181+ {
182+ $ properties = [];
183+
184+ if (
185+ !isset ($ spec ['definitions ' ][$ responseModel ]['properties ' ]) ||
186+ !is_array ($ spec ['definitions ' ][$ responseModel ]['properties ' ])
187+ ) {
188+ return $ properties ;
189+ }
190+
191+ foreach ($ spec ['definitions ' ][$ responseModel ]['properties ' ] as $ property ) {
192+ if (isset ($ property ['readOnly ' ]) && $ property ['readOnly ' ]) {
193+ $ properties [] = $ property ['name ' ];
194+ }
195+ }
196+
197+ return $ properties ;
198+ }
199+
180200 public function getTypeName (array $ parameter , array $ method = []): string
181201 {
182202 if (isset ($ parameter ['enumName ' ])) {
@@ -224,7 +244,7 @@ public function getTypeName(array $parameter, array $method = []): string
224244 if ($ method ['method ' ] === 'post ' ) {
225245 return "Document extends Models.DefaultDocument ? Partial<Models.Document> & Record<string, any> : Partial<Models.Document> & Omit<Document, keyof Models.Document> " ;
226246 }
227- if ($ method ['method ' ] === 'patch ' ) {
247+ if ($ method ['method ' ] === 'patch ' || $ method [ ' method ' ] === ' put ' ) {
228248 return "Document extends Models.DefaultDocument ? Partial<Models.Document> & Record<string, any> : Partial<Models.Document> & Partial<Omit<Document, keyof Models.Document>> " ;
229249 }
230250 }
@@ -336,6 +356,9 @@ public function getFilters(): array
336356 new TwigFilter ('getPropertyType ' , function ($ value , $ method = []) {
337357 return $ this ->getTypeName ($ value , $ method );
338358 }),
359+ new TwigFilter ('getReadOnlyProperties ' , function ($ value , $ responseModel , $ spec = []) {
360+ return $ this ->getReadOnlyProperties ($ value , $ responseModel , $ spec );
361+ }),
339362 new TwigFilter ('getSubSchema ' , function (array $ property , array $ spec ) {
340363 return $ this ->getSubSchema ($ property , $ spec );
341364 }),
0 commit comments