ad-on-is / adonis-autoswagger

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

Nested or extend interface not working with @responseBody #79

Closed im4aLL closed 5 months ago

im4aLL commented 5 months ago

If we define

@responseBody 200 - <GenericPaginationResponseInterface>

GenericPaginationResponseInterface

export interface GenericPaginationResponseInterface {
  meta: {
    total: number
    perPage: number
    currentPage: number
    lastPage: number
    firstPage: number
    firstPageUrl: string
    lastPageUrl: string
    nextPageUrl: string
    previousPageUrl: string
  }

  data: Array<string>
}

in swagger it shows like this

{
  "meta": {},
  "total": null,
  "per_page": null,
  "current_page": null,
  "last_page": null,
  "first_page": null,
  "first_page_url": null,
  "last_page_url": null,
  "next_page_url": null,
  "previous_page_url": null,
  "data": {}
}

is that an issue or I am doing something wrong? Also, I noticed that, if I extend an interface it doesn't work as well.

ad-on-is commented 5 months ago

Hmmm... There seems to be an issue with nesting I didn't account for. Will see what I can do.

Extended IFs are not supported yet.

ad-on-is commented 5 months ago

I just saw you are returning a paginated response... there is already a helper for that <Model[]>.paginated()

im4aLL commented 5 months ago

<Model[]>.paginated() It doesn't do anything

Yeah, I gave pagination response for example. What I tried to say is, if I extend or if it is a nested interface, it doesn't work

ad-on-is commented 5 months ago

Are you on the newest version? and did you use an existing model like <User[]>.paginated()

im4aLL commented 5 months ago

Yes, new version AdonisJS 6 and new version of adonis-autoswagger. Yes, I am using existing model <ExistingModel[]>.paginated()

ad-on-is commented 5 months ago

Would you post your code with the comment decorators?

im4aLL commented 5 months ago

index method of product controller

  /**
   * @index
   * @description It also accepts filters by "name"
   * @responseBody 200 - <Product[]>.paginated()
   * @paramUse(pagination)
   */
  async index({ request }: HttpContext) {
    const page = request.input(GLOBAL_CONFIG.pagination.param, 1)
    const limit = GLOBAL_CONFIG.pagination.limit

    const model = Product.query()

    // filter
    const filterName = request.input('name')
    if (filterName && filterName.length > 0) {
      model.withScopes((scopes) => scopes.search(filterName))
    }

    const products = await model.orderBy('created_at', 'desc').paginate(page, limit)
    return products.toJSON()
  }

swagger config

import path from 'node:path'
import url from 'node:url'

export default {
  path: path.dirname(url.fileURLToPath(import.meta.url)) + '/../',
  title: 'Rest API',
  version: '1.0.0',
  tagIndex: 3,
  snakeCase: true,
  debug: false, // set to true, to get some useful debug output
  ignore: ['/swagger', '/docs'],
  preferredPutPatch: 'PUT', // if PUT/PATCH are provided for the same route, prefer PUT
  common: {
    parameters: {
      pagination: [
        {
          in: 'query',
          name: 'page',
          schema: { type: 'string', example: '1' },
        },
      ],
    }, // OpenAPI conform parameters that are commonly used
    headers: {}, // OpenAPI conform headers that are commonly used
  },
  persistAuthorization: true, // persist authorization between reloads on the swagger page
  showFullPath: false, // the path displayed after endpoint summary
}
ad-on-is commented 5 months ago

image

This is what it looks like at my end, when using the exact same decorators. and parameters

im4aLL commented 5 months ago

This is what it looks like on my end

image

BTW, which UI is that you posted?

ad-on-is commented 5 months ago

its rapidoc, but shouldn't make a difference

ad-on-is commented 5 months ago

Are you sure, you're on the newest version of autoswagger? what version shows in your package.json.

im4aLL commented 5 months ago

"adonis-autoswagger": "^3.6.0"

ad-on-is commented 5 months ago

"adonis-autoswagger": "^3.6.0"

this is waaaaaay behind... we're on 3.16.0 now

im4aLL commented 5 months ago

alright, pagination seems working now.

However, the extended interface still not working (just checking whether it works for you), but only in the request body, the nested interface is working.

ad-on-is commented 5 months ago

I haven't looked into this one yet. well keep you posted once it's done

ad-on-is commented 5 months ago

Fixed in 3.17.0