Installations
npm install openapi-codegen-typescript
Developer Guide
Typescript
Yes
Module System
CommonJS
Score
70.3
Supply Chain
97.4
Quality
76.6
Maintenance
50
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (98.83%)
JavaScript (0.75%)
Dockerfile (0.42%)
Developer
LandrAudio
Download Statistics
Total Downloads
94,796
Last Day
38
Last Week
121
Last Month
566
Last Year
8,931
GitHub Statistics
87 Commits
14 Watching
10 Branches
39 Contributors
Bundle Size
656.92 kB
Minified
193.72 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.1.29
Package Id
openapi-codegen-typescript@0.1.29
Unpacked Size
137.30 kB
Size
23.00 kB
File Count
106
Publised On
24 Apr 2024
Total Downloads
Cumulative downloads
Total Downloads
94,796
Last day
31%
38
Compared to previous day
Last week
-23.9%
121
Compared to previous week
Last month
15.7%
566
Compared to previous month
Last year
-11.4%
8,931
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
4
OpenApi-codegen-typescript
Installation
yarn add -D openapi-codegen-typescript
npm install openapi-codegen-typescript --save-dev
Description
What is this library for?
- For fetching json file (mostly for "Swagger json")
Example:
1const { fetchSwaggerJsonFile } = require('openapi-codegen-typescript'); 2 3async function doSomething() { 4 const json = await fetchSwaggerJsonFile('https://custom/swagger.json'); 5 console.log('Json Result', json); 6}
- For converting swagger.json file to typescript types
Example:
1const { fetchSwaggerJsonFile, convertToTypes } = require('openapi-codegen-typescript'); 2 3async function doSomething() { 4 const json = await fetchSwaggerJsonFile('https://custom/swagger.json'); 5 convertToTypes({ json, fileName: 'dtoAPI', folderPath: 'src/types/generated' }); 6}
This function ('doSomething()') fetches json file from urls, then converts json to typescript "types" and writes "types" to file ('src/types/generated/dtoAPI')
- For generating mock files that are using converted types
Example:
1const { fetchSwaggerJsonFile, convertToTypes } = require('openapi-codegen-typescript'); 2 3async function doSomething() { 4 const json = await fetchSwaggerJsonFile('https://custom/swagger.json'); 5 convertToMocks({ 6 json, 7 fileName: 'dtoAPI', 8 folderPath: 'src/mocks/generated', 9 typesPath: '../../types/generated/dtoAPI', 10 }); 11}
This function ('doSomething()') fetches json file from urls, then converts json to "mocks" and writes "mocks" to file ('src/mocks/generated/dtoAPI') with imports from typescript types ('src/types/generated/dtoAPI')
Overriding enum schema type
You can override open-api enum types and mocks by specifying overrideSchemas
prop.
Let's imagine that we have this schema enum type in a json file:
1{ 2 "SomeType": { 3 "type": "string", 4 "description": "", 5 "x-enumNames": ["Audio", "Video", "Image", "Text", "Raw"], 6 "enum": ["Audio", "Video", "Image", "Text", "Raw"] 7 } 8}
Overriding example:
1const { fetchSwaggerJsonFile, convertToTypes, convertToMocks } = require('openapi-codegen-typescript'); 2 3const url = 'https://someLinkToSwagger/v2/swagger.json'; 4 5async function main() { 6 const json = await fetchSwaggerJsonFile(url); 7 const overrideSchemas = [ 8 { 9 ServiceOfferKind: { 10 type: 'string', 11 description: 'Warning! This type is overrided', 12 enum: ['masteringAndDistribution', 'video', 'samples', 'mastering', 'distribution', 'sessions'], 13 }, 14 }, 15 ]; 16 17 convertToTypes({ 18 json, 19 fileName: 'typesAPI', 20 folderPath: 'src/types/generated', 21 overrideSchemas, 22 }); 23 convertToMocks({ 24 json, 25 fileName: 'mocksAPI', 26 folderPath: 'src/mocks/generated', 27 typesPath: '../../types/generated/typesAPI', 28 overrideSchemas, 29 }); 30} 31 32main();
AllInOne Example:
1const { fetchSwaggerJsonFile, convertToTypes, convertToMocks } = require('openapi-codegen-typescript'); 2 3const petShopLink = 'https://petstore.swagger.io/v2/swagger.json'; 4 5async function main() { 6 const json = await fetchSwaggerJsonFile(petShopLink); 7 convertToTypes({ json, fileName: 'typesAPI', folderPath: 'src/types/generated' }); 8 convertToMocks({ 9 json, 10 fileName: 'mocksAPI', 11 folderPath: 'src/mocks/generated', 12 typesPath: '../../types/generated/typesAPI', 13 }); 14} 15 16main();
Methods:
fetchSwaggerJsonFile(url)
url
: string
- url to swagger json file
Returns a swagger json object;
convertToTypes({ json, fileName, folderPath })
json
: object
- swagger json data;
fileName
: string
- name of the file, where typescript types data will be saved;
folderPath
: string
- folder path the fileName
, where typescript types data will be saved;
Returns void
;
convertToMocks({ json, fileName, folderPath, typesPath })
json
: object
- swagger json data;
fileName
: string
- name of the file, where mocks data will be saved;
folderPath
: string
- folder path the fileName
, where mocks data will be saved;
typesPath
: string
- folder path to types
, where typescript types data are saved.
Path to types
will be inserted to the type imports in generated mocks (generated -> import {...} from typesPath
;);
Returns void
;
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 5/24 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: containerImage not pinned by hash: .devcontainer/Dockerfile:5
- Info: 0 out of 1 containerImage dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 11 are checked with a SAST tool
Reason
29 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-6chw-6frg-f759
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq
- Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488
- Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-8hfj-j24r-96c4
- Warn: Project is vulnerable to: GHSA-wc69-rhjr-hc9g
- Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g
- Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
2.1
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to openapi-codegen-typescript
openapi-typescript
Convert OpenAPI 3.0 & 3.1 schemas to TypeScript
openapi-typescript-codegen
Library that generates Typescript clients based on the OpenAPI specification.
@openapi-codegen/typescript
OpenAPI Codegen typescript generators
@pakholeung37/openapi-typescript-codegen
Library that generates Typescript clients based on the OpenAPI specification.