ad-on-is / adonis-autoswagger

Auto-Generate swagger docs for AdonisJS
MIT License
128 stars 41 forks source link

🚫 Readonly properties of the models are not considered in the @requestBody. #126

Open abdel7517 opened 2 months ago

abdel7517 commented 2 months ago

Hello, is it possible to include readonly properties for models? I have a class that I'm using as a requestBody, specified with the @requestBody decorator, but the readonly properties do not appear in Swagger-UI. Thank you!

ad-on-is commented 2 months ago

Can you please post some code for a better understanding?

abdel7517 commented 2 months ago

This is the class i try to import : export default class CreateUserDto { constructor( readonly name: string, readonly firstName: string, readonly email: string, readonly companyId: UUID, readonly password: string, readonly phone: string ) {} }

And I try to use with @requestBody, in this controller :

`export default class AuthUserController { constructor(private authUserUseCase: AuthUserUseCase) {} /**

ad-on-is commented 2 months ago

May I ask, why not use a model or validator instead, since this is the adonisJS-way of doing these things?

abdel7517 commented 2 months ago

Thank you for your response. I am using a hexagonal architecture, so I handle all business constraints, including payload validation, in the domain layer of the application (where all my business logic resides). I could manage this in the controller, but it would be redundant work. However, I have already analyzed your package and modified it locally to include the readonly properties. Is it possible to make a PR?

abdel7517 commented 1 month ago

I assume that the add-on is very busy, so while waiting for a response, for those who have the same need as I do, here is a modified version of the package that accepts both readonly props and props with a default value (e.g., size: number = 30). This is because these types of variables are not handled in the current version. https://www.npmjs.com/package/auto-swagger-adonis-abd