ad-on-is/adonis-autoswagger

Feat: Nesting Model Ref on Response

Closed this issue ยท 10 comments

First of all, AutoSwagger is the most active 3rd party package of AdonisJs I have ever seen! It saved my lot of time :).

AutoSwagger has the feature to reference model on @responsebody
But some time we may need to put model deeper.

My usecase is to ref model inside data key

/**
  @responseBody 201 - { "message": "Verification email sent", "data": <User> }
*/

Thanks in advance!

Thank you, I really appreciate it ๐Ÿ˜…

I could've sworn, that this used to work some time ago. Will have a look into it.

Fixed in 3.3.0

Still not working. Its giving unexpected output

Here is my method

  /**
   * @register
   * @summary Register a new user
   * @requestFormDataBody { "email": { "type": "string" }, "username": { "type": "string" }, "password": { "type": "string" }, "avatar": { "type": "string", "format": "binary" }, "recaptchaResponse": { "type": "string" } }
   * @responseBody 201 - { "message": "Verification email sent", "data": <User> }
   * @responseHeader 201 - Location - URL of the registered user's profile
   */
  async register({ request, response }: HttpContext) {
 

And here is the generated body

{
  "id": 939,
  "email": "johndoe@example.com"
}

Can you try requestBody instead of requestformdatabody

I just removed @requestformdatabody but still same result

image

@inject()
export default class TestController {
  /**
   * @index
   * @operationId getProducts
   * @description Returns array of producs and it's relations
   * @responseBody 200 - {"GETTER": "<User>"}
   * @responseBody 400 - {"GETTER": "error"}
   */
  async index() {
    return {
      hello: 'world',
    }
  }
  /**
   * @store
   * @operationId getProducts
   * @description Returns array of producs and it's relations
   * @requestBody { "email": { "type": "string" }, "username": { "type": "string" }, "password": { "type": "string" }, "avatar": { "type": "string", "format": "binary" }, "recaptchaResponse": { "type": "string" } }
   * @responseBody 200 - {"POSTER": {"data": "<User>.only(email)"}}
   * @responseBody 400 - Some error occured
   */
  async store() {}
}

Oh and it also works with requestformdatabody

image

 /**
   * @store
   * @operationId getProducts
   * @description Returns array of producs and it's relations
   * @requestFormDataBody { "email": { "type": "string" }, "username": { "type": "string" }, "password": { "type": "string" }, "avatar": { "type": "string", "format": "binary" }, "recaptchaResponse": { "type": "string" } }
   * @responseBody 200 - {"POSTER": {"data": "<User>.only(email)"}}
   * @responseBody 400 - Some error occured
   */
  async store() {}

Oh, sorry I forgot to add quote on .
Now its working properly

Oh, sorry I forgot to add quote on . Now its working properly

Oh man, and I thought you were talking about the requestformdatabody ๐Ÿคฆ๐Ÿป๐Ÿ˜…

๐Ÿ˜… thanks for your time