FoalTS / foal

Full-featured Node.js framework, with no complexity. 🚀 Simple and easy to use, TypeScript-based and well-documented.
https://foalts.org/
MIT License
1.88k stars 137 forks source link

createOpenApiDocument don't accept serviceManager as second parametere #949

Closed kingdun3284 closed 3 years ago

kingdun3284 commented 3 years ago

Version of FoalTS: 2.4.0 Using createOpenApiDocument triggers error below:

Error: No service was found with the identifier "someservice".

someservice is a MIKRO ORM repository that set into service manager manually and being retrived by @Depdency("someservice") in controller. Afterall, I want to create a service manager manually and put into this function and found that the api has changed and different from foalts v1. Any suggestion to overcome this issue in v2?

LoicPoullain commented 3 years ago

If you're inside a controller, you can inject the OpenApi service directly to get the document:

import { dependency, OpenApi } from '@foal/core';

class Service {
  @dependency
  openApi: OpenApi;

  foo() {
    const document = this.openApi.getDocument(ApiController);
  }
}

If you're outside of a controller/service, it's currently not possible. I will add an optional services parameter in the next release.

LoicPoullain commented 3 years ago

Feature has been added to v2.5