ad-on-is / adonis-autoswagger

Auto-Generate swagger docs for AdonisJS
MIT License
116 stars 38 forks source link

responseBody Issue #87

Closed pdipax closed 4 months ago

pdipax commented 4 months ago

Hi, thanks for this work.

I installed the latest version of the package but it doesn't work in responseBody .paginated() because it correctly returns the schema in data and the meta effect but it is still empty, the pagination interface that I had read is missing, it no longer exists necessary. Furthermore, it doesn't work because is always returned with the relations even if .with is not indicated and if I use .with by specifying a relation, all of them are always returned anyway

ad-on-is commented 4 months ago

Sorry I don't clearly understand the issue here. can you be more specific and also provide an example, how you use it and the output.

pdipax commented 4 months ago

sorry, this is my method:

/*
   * @getListaApps
   * @tag Apps
   * @paramQuery page - Pagina da mostrare, se non indicata default sarà 1
   * @paramQuery perPage - Elementi per pagina, se non indicato saranno 999999
   * @responseBody 200 - <App[]>.paginated()
   */
  async getListaApps({ request, params, response }:HttpContext) {

in /docs under responseBody I see this:

data: {
  "codice": "string",
  "nome": "string",
  "descrizione": "string",
  "visibile_agenti": true,
  "permessi": [
    {
      "app": "$ref:/components/schemas/App",
      "ruolo": [...
              ...
       ]
   }, meta: {}

practically it is also inserting all the relations of the model into the response. finally, despite having set the paginated() response, the interface provided for the meta key is not populated but only an empty object.

ad-on-is commented 4 months ago

Oooh... thx, that is indeed an issue. will look into that

pdipax commented 4 months ago

Please help me solve this bug with the promise that later I will help you introduce the parser also for validators as I have read in other threads. It would be practically complete if you could also insert a sample requestbody based on the validator ;-)

I just made a pull request to also allow the model to declare the column name and type on the same line as @column first the parser assumed that the line had to start with "declare" but I replaced it with includes('declare')

ad-on-is commented 4 months ago

Hey... thx for the PRs, I've merged and published them today in addition with the relations fix. Now, relations are not included by default. This used to work, but I messed something up later on.

However, I still cannot explain the missing meta. It works on my end.

* @responseBody 200 - <User[]>.paginated()

image

VSalzano commented 4 months ago

Hi, relations are also included by default in RequestBody. Could you fix this? Thanks

ad-on-is commented 4 months ago

Hi, relations are also included by default in RequestBody. Could you fix this? Thanks

this is already fixed in the newest version

VSalzano commented 4 months ago

I update to last version 3.25.0 but this is not fixed Furthermore the newest feature @props doesn't work with required.

Finally I encounter the same error in the responsebody regarding pagination. Can you tell me that I don't need to create the interface but that it should be generated automatically?

ad-on-is commented 4 months ago

I update to last version 3.25.0 but this is not fixed Furthermore the newest feature @props doesn't work with required.

Finally I encounter the same error in the responsebody regarding pagination. Can you tell me that I don't need to create the interface but that it should be generated automatically?

I just published a new version 3.26. Can you try it with that one. The pagination IF should get generated automatically.

ad-on-is commented 4 months ago

Regarding relations... could you show me an example code and output, please?

VSalzano commented 4 months ago

Ok the last version doesn't work.

last version code: ...example_1.ExampleInterfaces.paginationInterface(), work if fix this line as below; ...example_1.ExampleInterfaces.paginationInterface('PaginationMeta'),

Regarding relations I try this:

* @requestBody <App>

but I receive the full model with relations in scalar ui.

VSalzano commented 4 months ago

In responseBody if I set this

@responseBody 404 - Product could not be found

The description "Product could not be found" doens't appear

ad-on-is commented 4 months ago

oooh... your getting the full model in request body... okey.. will have a look

ad-on-is commented 4 months ago

regarding 404 can you try other ui like rapidoc?

ad-on-is commented 4 months ago

For me everything works as expected

image

 /**
   * @store
   * @requestBody <User>
   * @responseBody 404 - Product not found
   */

async store({}: HttpContext) {
    // ...
  }
VSalzano commented 4 months ago

Ok with other ui. The issue is only in scalar ui.

ad-on-is commented 4 months ago

Oooh and regarding the request and response body... scalar seems to use the model instead, which of course shows the relations, since it's a part of the model.

Scalar should show examples too, instead of models

ad-on-is commented 4 months ago

If the pagination does not work, can you please open the "/swagger" url and see if it appears there

Should look something like this

schemas:
    Any:
      description: "Any JSON object not defined as schema"
    PaginationMeta:
      type: "object"
      properties:
        total:
          type: "number"
          example: 100
          nullable: false
        page:
          type: "number"
          example: 2
          nullable: false
        perPage:
          type: "number"
          example: 10
          nullable: false
        currentPage:
ad-on-is commented 4 months ago

Closing this since it works but scalar doesn't respect the example