[REQ][Slim4] Getter and setters for the models (or a not private visibility to properties)
See original GitHub issueIs your feature request related to a problem? Please describe.
The php-slim4 generator generate models with private properties so they are not accessible from other classes nor extendable. Every time a models is instantiated the object results in an empty object (with null properties).
Describe the solution you’d like
The php-slim4 generator should generate models with either public properties or getters and setters (and maybe a constructor from associative arrays) like the php-symfony generator.
Describe alternatives you’ve considered
Currently I don’t use models at all… For the response I create associative arrays structured according to the OpenAPI config file.
Additional context
A generated model from the sample directory: https://github.com/OpenAPITools/openapi-generator/blob/3b9cb14025ac4ae90909ad5ba98f316ba5546986/samples/server/petstore/php-slim4/lib/Model/Pet.php The same model generated with php-symfony: https://github.com/OpenAPITools/openapi-generator/blob/3b9cb14025ac4ae90909ad5ba98f316ba5546986/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php
I found a mustache file with the private
directive.
https://github.com/OpenAPITools/openapi-generator/blob/8c6236b341c0e74c4cc18ea409f6fbf3d3dc114d/modules/openapi-generator/src/main/resources/php-slim4-server/model.mustache#L36
Could be the simplest solution change it to public
?
Thank you for this beautiful project!
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
It seems that your 1 to 4 proposals already wait for review in #5930.
Can’t quite follow you here… If I make properties
protected
, then I should disable__get
and__set
methods completely.You mean if I set properties
protected
? My currentBaseModel
handles scalar types and weird properties OK, because of$dataContainer
and generalsetData($data)
,getData(): mixed
methods. It doesn’t validate and doesn’t convert data types yet, but I’m going to add it in next version.I’m pretty satisfied with my
BaseModel
already, it completely covered with unit tests which is more than enough for1.0.0
version. It doesn’t supportallOf/anyOf/oneOf
keywords yet, that’s my next goal.Closed in #5930