Gathering detailed insights and metrics for @spailybot/moleculer-auto-openapi
Gathering detailed insights and metrics for @spailybot/moleculer-auto-openapi
Gathering detailed insights and metrics for @spailybot/moleculer-auto-openapi
Gathering detailed insights and metrics for @spailybot/moleculer-auto-openapi
Generate openapi scheme for moleculer
npm install @spailybot/moleculer-auto-openapi
Typescript
Module System
Min. Node Version
Node Version
NPM Version
66.7
Supply Chain
96
Quality
75.5
Maintenance
100
Vulnerability
97.9
License
TypeScript (98.44%)
JavaScript (1.56%)
Total Downloads
4,783
Last Day
2
Last Week
27
Last Month
268
Last Year
2,527
MIT License
4 Stars
142 Commits
2 Forks
1 Watchers
4 Branches
7 Contributors
Updated on Apr 16, 2025
Minified
Minified + Gzipped
Latest Version
1.3.2
Package Id
@spailybot/moleculer-auto-openapi@1.3.2
Unpacked Size
148.62 kB
Size
45.59 kB
File Count
38
NPM Version
10.8.2
Node Version
20.19.0
Published on
Apr 16, 2025
Cumulative downloads
Total Downloads
Last Day
-71.4%
2
Compared to previous day
Last Week
-69%
27
Compared to previous week
Last Month
3.1%
268
Compared to previous month
Last Year
12%
2,527
Compared to previous year
1
24
1
Why Use OpenAPI:
OpenAPI standardizes and documents RESTful APIs, streamlines development, improves team communication, and automates testing. Moreover, it can be used to generate client SDKs. It allows for a focus on business logic, making it a valuable tool in a microservices environment.
This project is a fork of moleculer-auto-openapi by grinat.
Big thanks to grinat for the original work, and also to everyone who has contributed to it!
Fastest-Validator
support for direct OpenAPI generation from parameters, complete with examplesTo use this library, you must have the Moleculer framework installed along with the Moleculer-Web module. Additionally, the listAliases
action must be available (which is the default setting).
Install the package using your preferred package manager:
npm install @spailybot/moleculer-auto-openapi
If you wish to use a local instance of Swagger UI, install it like this:
npm install swagger-ui-dist@^5
For the full TypeScript autocompletion experience, install the openapi-types
package in addition to the above:
npm install --save-dev openapi-types
Note: The following examples use the ESM syntax.
Depending on your environment and requirements, you may need to adapt these examples, possibly to the CommonJS (CJS) syntax, or to your specific coding standard.
1import { OpenApiMixin, type OpenApiMixinSettings, type MoleculerWebTypes } from '@spailybot/moleculer-auto-openapi'; 2import { Service, type ServiceBroker } from 'moleculer'; 3 4/** 5 * MoleculerWebTypes are typings created from moleculer-web to enhance included typings; their use is totally optional. 6 */ 7 8export default class OpenApiService extends Service<OpenApiMixinSettings & MoleculerWebTypes.RestServiceSettings> { 9 public constructor(public broker: ServiceBroker) { 10 super(broker); 11 12 this.parseServiceSchema({ 13 // Choose your preferred name 14 name: 'openapi', 15 mixins: [mixin], 16 settings: { 17 // Set the path as you prefer 18 rest: '/openapi', 19 20 // will set 21 // - ui at /openapi/ui 22 // - json at /openapi/openapi.json 23 // - assets at /openapi/assets/* 24 // - oauth2redirection at /openapi/oauth2-redirect 25 openApiPaths: "/openapi", 26 // you cal also do it manually 27 /** 28 openApiPaths: { 29 schemaPath: "/openapi/openapi.json" 30 uiPath: "/openapi/ui" 31 oauth2RedirectPath: "/openapi/oauth2-redirect" 32 assetsPath: "/openapi/assets" 33 } 34 */ 35 36 // This will be the root of your document 37 // use it to define some default informations 38 openapi: { 39 info: { 40 title: "My API", 41 version: "0.0.1" 42 } 43 } 44 } 45 }); 46 } 47}
1import { OpenApiMixin, type OpenApiMixinSettings, type MoleculerWebTypes } from '@spailybot/moleculer-auto-openapi'; 2import { Service, type ServiceBroker } from 'moleculer'; 3 4const OpenApiService: ServiceSchema<OpenApiMixinSettings & MoleculerWebTypes.RestServiceSettings> = { 5 // Choose your preferred name 6 name: 'openapi', 7 mixins: [mixin], 8 settings: { 9 // Set the path as you prefer 10 rest: '/openapi', 11 12 // will set 13 // - ui at /openapi/ui 14 // - json at /openapi/openapi.json 15 // - assets at /openapi/assets/* 16 // - oauth2redirection at /openapi/oauth2-redirect 17 openApiPaths: "/openapi", 18 // you cal also do it manually 19 /** 20 openApiPaths: { 21 schemaPath: "/openapi/openapi.json" 22 uiPath: "/openapi/ui" 23 oauth2RedirectPath: "/openapi/oauth2-redirect" 24 assetsPath: "/openapi/assets" 25 } 26 */ 27 28 // This will be the root of your document 29 // use it to define some default informations 30 openapi: { 31 info: { 32 title: "My API", 33 version: "0.0.1" 34 } 35 } 36 } 37}; 38export default OpenApiService;
1import { OpenApiMixin } from '@spailybot/moleculer-auto-openapi'; 2import { Service } from 'moleculer'; 3 4export default class OpenApiService extends Service { 5 public constructor(broker) { 6 super(broker); 7 8 this.parseServiceSchema({ 9 // Choose your preferred name 10 name: 'openapi', 11 mixins: [OpenApiMixin], 12 settings: { 13 // Set the path as you prefer 14 rest: '/openapi', 15 16 // will set 17 // - ui at /openapi/ui 18 // - json at /openapi/openapi.json 19 // - assets at /openapi/assets/* 20 // - oauth2redirection at /openapi/oauth2-redirect 21 openApiPaths: "/openapi", 22 // you cal also do it manually 23 /** 24 openApiPaths: { 25 schemaPath: "/openapi/openapi.json" 26 uiPath: "/openapi/ui" 27 oauth2RedirectPath: "/openapi/oauth2-redirect" 28 assetsPath: "/openapi/assets" 29 } 30 */ 31 32 // This will be the root of your document 33 // use it to define some default informations 34 openapi: { 35 info: { 36 title: "My API", 37 version: "0.0.1" 38 } 39 } 40 } 41 }); 42 } 43}
1import { OpenApiMixin } from '@spailybot/moleculer-auto-openapi'; 2 3const OpenApiService = { 4 // Choose your preferred name 5 name: 'openapi', 6 mixins: [OpenApiMixin], 7 settings: { 8 // Set the path as you prefer 9 rest: '/openapi', 10 11 // will set 12 // - ui at /openapi/ui 13 // - json at /openapi/openapi.json 14 // - assets at /openapi/assets/* 15 // - oauth2redirection at /openapi/oauth2-redirect 16 openApiPaths: "/openapi", 17 // you cal also do it manually 18 /** 19 openApiPaths: { 20 schemaPath: "/openapi/openapi.json" 21 uiPath: "/openapi/ui" 22 oauth2RedirectPath: "/openapi/oauth2-redirect" 23 assetsPath: "/openapi/assets" 24 } 25 */ 26 27 // This will be the root of your document 28 // use it to define some default informations 29 openapi: { 30 info: { 31 title: "My API", 32 version: "0.0.1" 33 } 34 } 35} 36}; 37export default OpenApiService;
1const OpenApiMixin = require('@spailybot/moleculer-auto-openapi'); 2// or 3// const { OpenApiMixin } = require('@spailybot/moleculer-auto-openapi'); 4 5module.exports = { 6 // Choose your preferred name 7 name: "openapi", 8 mixins: [OpenApiMixin], 9 settings: { 10 // Set the path as you prefer 11 rest: '/openapi', 12 13 // will set 14 // - ui at /openapi/ui 15 // - json at /openapi/openapi.json 16 // - assets at /openapi/assets/* 17 // - oauth2redirection at /openapi/oauth2-redirect 18 openApiPaths: "/openapi", 19 // you cal also do it manually 20 /** 21 openApiPaths: { 22 schemaPath: "/openapi/openapi.json" 23 uiPath: "/openapi/ui" 24 oauth2RedirectPath: "/openapi/oauth2-redirect" 25 assetsPath: "/openapi/assets" 26 } 27 */ 28 29 // This will be the root of your document 30 // use it to define some default informations 31 openapi: { 32 info: { 33 title: "My API", 34 version: "0.0.1" 35 } 36 } 37 } 38}; 39
You can find detailed information about all the settings of the mixin in the technical documentation.
1import type { ApiSettingsSchemaOpenApi } from '@spailybot/moleculer-auto-openapi'; 2import ApiGateway from "moleculer-web"; 3import { Service, type ServiceBroker } from 'moleculer'; 4 5/** 6 * Note that ApiSettingsSchemaOpenApi is a re-export of ApiSettingsSchema because moleculer-web doesn't allow to extend it. 7 */ 8 9export default class WebApiService extends Service<ApiSettingsSchemaOpenApi> { 10 public constructor(public broker: ServiceBroker) { 11 super(broker); 12 13 this.parseServiceSchema({ 14 name: "api", 15 mixins: [mixin], 16 settings: { 17 // Place other settings here 18 openapi: { 19 // Define an OpenAPI specification that will be applied to all routes of this api 20 }, 21 routes: [ 22 // Place additional route configurations here 23 { 24 openapi: { 25 // Define an OpenAPI specification that will apply to all aliases within this route 26 }, 27 path: '/openapi', 28 aliases: { 29 'GET /openapi.json': 'openapi.generateDocs', 30 'GET /ui': 'openapi.ui', 31 'GET /assets/:file': 'openapi.assets', 32 'GET /oauth2-redirect': 'openapi.oauth2Redirect', 33 }, 34 }, 35 // To use autoAliases, refer to the following configuration 36 // { 37 // path: '/openapi', 38 // whitelist: ['openapi.*'], 39 // autoAliases: true 40 // } 41 42 ] 43 // Insert other settings here 44 } 45 }); 46 } 47}
1import ApiGateway from "moleculer-web"; 2import { Service } from 'moleculer'; 3 4export default class WebApiService extends Service { 5 public constructor(broker) { 6 super(broker); 7 8 this.parseServiceSchema({ 9 name: "api", 10 mixins: [mixin], 11 settings: { 12 // Place other settings here 13 openapi: { 14 // Define an OpenAPI specification that will be applied to all routes of this api 15 }, 16 routes: [ 17 // Place additional route configurations here 18 { 19 openapi: { 20 // Define an OpenAPI specification that will apply to all aliases within this route 21 }, 22 path: '/openapi', 23 aliases: { 24 'GET /openapi.json': 'openapi.generateDocs', 25 'GET /ui': 'openapi.ui', 26 'GET /assets/:file': 'openapi.assets', 27 'GET /oauth2-redirect': 'openapi.oauth2Redirect', 28 }, 29 }, 30 // To use autoAliases, refer to the following configuration 31 // { 32 // path: '/openapi', 33 // whitelist: ['openapi.*'], 34 // autoAliases: true 35 // } 36 37 ] 38 // Insert other settings here 39 } 40 }); 41 } 42}
Your setup is now complete.
To view your API documentation via Swagger UI, you can navigate to http://127.0.0.1/openapi/ui
in your web browser (adjust the URL according to your configuration).
With your project now up and running, there are several resources available to help you develop further:
Remember, the journey of mastering any tool involves experimentation, learning from examples, reading documentation, and continuous practice. Happy coding!
default
) might not execute reliably or as expected, and will be called without arguments.This project is protected under the MIT License. For more details, refer to the LICENSE file.
No vulnerabilities found.
No security vulnerabilities found.