ad-on-is / adonis-autoswagger

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

appPath: Not correct on controllers #71

Closed Jakob-Espersen closed 5 months ago

Jakob-Espersen commented 5 months ago

Hello. When i try making a resource controller or use a controller in routes.ts like:

router.resource('test', TestController)

it searches for /app/TestController.ts

when the path is /app/controllers/test_controller.ts. And therefore i get no such file or Directory error.

I have tried setting appPath in swagger.ts but i does not seem to do anything.

I might be overlooking something?

debug AdonisJS AutoSwagger:

{
  snakeCase: true,
  preferredPutPatch: 'PUT',
  debug: true,
  path: '/Users/user/Desktop/repo-dir/monorepo/apps/adonisApp/config/../',
  title: 'Foo',
  version: '1.0.0',
  tagIndex: 1,
  ignore: [ '/swagger', '/docs', '/myswagger' ],
  common: { parameters: {}, headers: {} },
  persistAuthorization: true,
  showFullPath: true,
  appPath: '/Users/user/Desktop/repo-dir/monorepo/apps/adonisApp/config/../app'
}

My swagger.ts:

// for AdonisJS v6
import path from "node:path";
import url from "node:url";
// ---

export default {
  path: path.dirname(url.fileURLToPath(import.meta.url)) + "/../", // for AdonisJS v6
  title: "Test",
  version: "1.0.0",
  tagIndex: 1,
  snakeCase: true,
  debug: true, // set to true, to get some useful debug output
  ignore: ["/swagger", "/docs", "/myswagger"],
  preferredPutPatch: "PUT", // if PUT/PATCH are provided for the same route, prefer PUT
  common: {
    parameters: {}, // 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: true, // the path displayed after endpoint summary
  appPath: 'app/controllers/'
};
ad-on-is commented 5 months ago

How do you import your TestController? Please make sure you're using it this way. This is also the recommended way based on the official adonisjs docs.

const TestController = () => import('#controllers/test_controller')
Jakob-Espersen commented 5 months ago

How do you import your TestController? Please make sure you're using it this way. This is also the recommended way based on the official adonisjs docs.

const TestController = () => import('#controllers/test_controller')

Overlooked the Compatability section, i was importing like

import TestController from '#controllers/test_controller'

It worked changing the import :)

ad-on-is commented 5 months ago

No, you didn't overlook it, I just added it to the readme a few minutes ago 😅

I thought I had it added, but looks like I forgot about it the whole time.