Gathering detailed insights and metrics for ts-openapi
Gathering detailed insights and metrics for ts-openapi
Gathering detailed insights and metrics for ts-openapi
Gathering detailed insights and metrics for ts-openapi
npm install ts-openapi
Typescript
Module System
Min. Node Version
Node Version
NPM Version
76.9
Supply Chain
99.2
Quality
84
Maintenance
100
Vulnerability
99.3
License
TypeScript (94.94%)
JavaScript (5.06%)
Total Downloads
226,329
Last Day
17
Last Week
1,883
Last Month
6,279
Last Year
48,416
MIT License
16 Stars
121 Commits
3 Forks
3 Watchers
9 Branches
4 Contributors
Updated on Jul 28, 2025
Latest Version
1.1.9
Package Id
ts-openapi@1.1.9
Unpacked Size
188.00 kB
Size
37.69 kB
File Count
47
NPM Version
10.8.2
Node Version
20.18.2
Published on
Jul 28, 2025
Cumulative downloads
Total Downloads
Last Day
6.3%
17
Compared to previous day
Last Week
-6.8%
1,883
Compared to previous week
Last Month
35%
6,279
Compared to previous month
Last Year
27.9%
48,416
Compared to previous year
An openapi json generator using joi API schemas that will help you to maintain your API documentation up to date. Joi is the is one of the most used components to validate data schemas, this can be used to generate and maintain API information up to date, without the need to update manually documentation.
This software has some code extracted from joi-to-swagger to interface with Joi schemas.
Using npm:
npm i --save ts-openapi
Type | Query | Path (1)(5) | Header | Cookie | Body |
---|---|---|---|---|---|
String, String Enum, Email, Password, Uuid, Uri, Hostname, Ipv4, Ipv6 | YES | YES | YES | YES | NO (4) |
Integer, Integer Enum, Number, Number Enum | YES | YES | YES | YES | NO (4) |
Date-time, Date | YES | YES | YES | YES | NO (4) |
Byte(3), Binary (string) | YES | YES | YES | YES | NO (4) |
Array[] | YES (3) | NO | NO | NO | YES (4) |
Object | NO | NO | NO | NO | YES (6) |
String Types
Numeric Types
Date-Time Types
Binary Types
Array Type
Object Type
1 const openApi = new OpenApi( 2 "1.0.0", // API version 3 "Server API", // API title 4 "Some test api", // API description 5 "maintainer@domain.com" // API maintainer email 6 );
In the event your API is based on docker instances you should call setServers when OpenApi class is called to get the json, to update the IPs and port numbers. You can even specify different servers depending if the call is internal or external. Up to you.
1 openApi.setServers([ 2 { url: "https://api.domain.com:443" }, 3 { url: "https://192.168.1.23:80" } 4 ]);
This is used to document the API license type, url of the license and terms of service.
1 openApi.setLicense(
2 "Apache 2.0", // license name
3 "http://www.apache.org/licenses/LICENSE-2.0.html", // url for the api license
4 "http://swagger.io/terms/" // terms of service
5 );
1 openApi.addPath( 2 "/hello", 3 { 4 get: { 5 summary: "Server Healthcheck", // Method title 6 description: "Hello world endpoint", // Method description 7 operationId: "hello-op", // unique operation id 8 responses: { // response codes and description 9 200: textPlain("Successful operation."), 10/* // or if you prefer: 11 200: { 12 description: "Successful operation.", 13 content: { "text-plain": {} }, // mimetype with empty schema 14 },*/ 15 }, 16 tags: ["Test Operations"], // One or more tags, this will allow API grouping 17 }, 18 }, 19 true // visible ? If not it gets skipped from declaration 20 );
Note that the paths just need to be added one time, during server init, after this the openApi is basically static.
1 openApi.generateJson();
1 2 const errorSchema = Types.Object({ 3 description: "Error description", 4 properties: { 5 message: Types.String({ description: "Error message" }), 6 code: Types.Integer({ description: "Error code" }), 7 }, 8 example: { message: "Bad request": code: 400 } 9 }); 10 11 // body response schema 12 const responseSchema = Types.Object({ 13 description: "Customer details", 14 properties: { 15 id: Types.Uuid({ description: "Customer ID" }), 16 name: Types.String({ 17 description: "Customer name", 18 maxLength: 100, 19 required: true, 20 }), 21 type: Types.StringEnum({ 22 values: Object.values(CustomerType), 23 description: "Customer Type", 24 }), 25 birthdate: Types.Date({ description: "Birthdate" }), 26 }, 27 example: { id: "96efe677-f752-426f-a9b8-b9f33b286cc9", name: "customer model", type: "gold", birthdate: "11-11-1911" }, 28 }); 29 30 openApi.addPath( 31 "/customer/:id", // path parameter 32 { 33 get: { 34 summary: "Get a customer data", 35 description: "This operation retrieves customer information", 36 operationId: "get-customer-op", 37 requestSchema: { 38 params: { // path parameter 39 id: Types.Uuid({ 40 description: "Customer ID", 41 required: true, // param values MUST be required 42 example: "37237d6a-bb7e-459a-b75d-d1733210ad5c", 43 }), 44 }, 45 }, 46 tags: ["Customer Operations"], 47 responses: { 48 200: openApi.declareSchema("Get customer success", responseSchema), 49 400: openApi.declareSchema("Bad Request", errorSchema), 50 }, 51 }, 52 }, 53 true 54 );
You can declare:
When you declare your request you can use as inputs:
Maintaining REST API Documentation with Node.js — Part I about documenting a single service
Maintaining REST API Documentation with Node.js — Part II about combining multiple services documentation
No vulnerabilities found.
openapi-typescript
Convert OpenAPI 3.0 & 3.1 schemas to TypeScript
openapi3-ts
TS Model & utils for OpenAPI 3.x specification.
openapi-ts-request
Swagger2/OpenAPI3/Apifox to TypeScript/JavaScript, request client(support any client), request mock service, enum and enum translation, react-query/vue-query, type field label, JSON Schemas
@hey-api/openapi-ts
🚀 The OpenAPI to TypeScript codegen. Generate clients, SDKs, validators, and more.