Comments (4)
@andreafspeziale Sounds good to me! Would you like to create a PR? :)
from terminus.
@BrunnerLivio npm i/build
is broken on my side using node v18.5.0
.
No problems by using node v16.x.x
. Wouldn't be useful to specify engines in the package.json
?
I've also start testing what I was proposing above but unfortunately it is not 100% what I would like to achieve.
Adding title
will add the name to the schema
but it will not possible to smoothly have it listed at the bottom
I'm not sure how to achieve it but my feeling is that the only way would be to have the schemas as classes and import them into the main.ts
of the consumer application as extra schemas.
const swaggerDocument = SwaggerModule.createDocument(app, swaggerConfig, {
extraModels: [Exception],
});
Any suggestion to this brainstorming?
from terminus.
No problems by using node v16.x.x. Wouldn't be useful to specify engines in the package.json?
Yeah that'd be nice! Can you specify the version that is defined within the .nvmrc
file?
I'm not sure how to achieve it but my feeling is that the only way would be to have the schemas as classes and import them into the main.ts of the consumer application as extra schemas.
I haven't looked too deeply into it, but it may be related to this issue.
Have you tried calling ApiExtraModels
within health-check.decorator.ts
(similar how ApiServiceUnavailableResponse
is called)
from terminus.
@BrunnerLivio Oh! I didn't notice the nvm
file. Using that was smooth, so far so good!
I checked the issue u linked above and following your suggestion I did some tests but unfortunately I never saw the schemas rendering at the bottom of the swagger page.
Maybe I'm just misunderstanding your suggestion.
Could you try to be more specific? I will be happy to try it out on my side!
By the way I developed a similar use-case, as you can see from the previous comment screenshot I've an Exception
schema in the schema list at the bottom of the swagger page.
I achieved it by exporting a class and a decorator from one of my monorepo packages named common
.
As mentioned the package exports the class and a decorator to be used in the controllers:
export class Exception extends HttpException {
constructor(response: ExceptionResponse, status: number) {
super(response, status);
}
@ApiProperty()
code!: string;
@ApiProperty()
message!: string;
@ApiPropertyOptional({
oneOf: [
{
type: 'array',
items: {
type: 'string',
},
},
{
type: 'object',
additionalProperties: { type: 'unknown' },
},
],
})
details?: string[] | Record<string, unknown>;
}
export const ApiExceptionResponse = ({
status,
description,
example,
examples,
}: ApiExceptionResponseOptions) =>
applyDecorators(
ApiResponse({
status,
description,
content: {
'application/json': {
schema: { $ref: getSchemaPath(Exception) },
example,
examples,
},
},
}),
);
export class CatsController {
constructor(private readonly catsService: CatsService) {}
@Get(':id')
@ApiOperation({
summary: 'Retrieves a cat by id',
description: 'A Cat is a sample entity. If not found throws a NotFoundException.',
})
@ApiExceptionResponse({
status: 400,
example: httpExceptionExamples.ValidationException.value,
})
@ApiExceptionResponse({
status: 404,
example: httpExceptionExamples.NotFoundException.value,
})
async getConfiguration(@Param() { id }: CatParam): Promise<Cat> {
const { id: _, ...res } = await this.catsService.getCat(id);
return res;
}
}
...
import { Exception } from 'common';
...
const swaggerConfig = new DocumentBuilder()
.setTitle(name)
.setDescription(`${name} RESTful API service.`)
.setVersion(version)
.build();
const swaggerDocument = SwaggerModule.createDocument(app, swaggerConfig, {
extraModels: [Exception],
});
SwaggerModule.setup('swagger', app, swaggerDocument);
Let me know your thoughts!
P.s: I noticed that the package contains some files that I would not include
Do you want me to open an issue and update the [.npmignore](https://github.com/nestjs/terminus/blob/master/.npmignore)
ignoring:
- .nvmrc
- .husky
- docker-compose.yml
Cheers and sorry for the late response I've been working on my first OS nestjs module!
from terminus.
Related Issues (20)
- Ability to run health checks in parallel HOT 3
- After PR #1970 (update from 9.0.0 to 9.1.0) there is an error with TERMINUS_ERROR_LOGGER HOT 2
- NestJS Terminus has an undeclared dependency on Axios HOT 1
- Typescript issues with axios >= 0.27 HOT 1
- Allow custom logger implementation for health check service HOT 10
- Optional peerDependencies are not declared in manifest
- Throwing HealthCheckError in synchronous HealthIndicatorFunction does not work properly HOT 5
- Nest could not find MikroORM element (this provider does not exist in the current context) HOT 1
- MicroserviceHealthIndicator pingCheck() failed when error is undefined HOT 2
- MikroOrmHealthIndicator does not work with the `defineConfig` helper HOT 4
- this library does not support Nestjs 10.0.0 HOT 5
- On shutdown, health request before signal interrupted with ECONNREFUSED
- Cached responses 200 -> 304 HOT 6
- HttpHealthIndicator.responseCheck not handles network errors HOT 1
- Adding a gracefulShutdownTimeout option for 0-downtime deployment on Kubernetes HOT 6
- nest10 health check return Service Unavailable Exception HOT 1
- Mikro ORM check returns healthy although not connected HOT 7
- Schema does not match health-indicator-result interface HOT 7
- DiskHealthIndicator always reports: "Used disk storage exceeded the set threshold" HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from terminus.