Gathering detailed insights and metrics for @hckrnews/openapi-model
Gathering detailed insights and metrics for @hckrnews/openapi-model
npm install @hckrnews/openapi-model
Typescript
Module System
Min. Node Version
Node Version
NPM Version
68.3
Supply Chain
97
Quality
78.4
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
1,888
Last Day
3
Last Week
5
Last Month
41
Last Year
410
190 Commits
1 Watching
25 Branches
3 Contributors
Minified
Minified + Gzipped
Latest Version
0.4.1
Package Id
@hckrnews/openapi-model@0.4.1
Unpacked Size
10.42 kB
Size
3.45 kB
File Count
5
NPM Version
10.2.4
Node Version
20.11.0
Publised On
02 Feb 2024
Cumulative downloads
Total Downloads
Last day
0%
3
Compared to previous day
Last week
0%
5
Compared to previous week
Last month
1,266.7%
41
Compared to previous month
Last year
-72.3%
410
Compared to previous year
Create easy a Model from a OpenAPI spec.
npm install @hckrnews/openapi-model
or
yarn add @hckrnews/openapi-model
npm run test
or
yarn test
1const schema = { 2 type: 'object', 3 properties: { 4 foo: { 5 type: 'string', 6 default: 'bar' 7 } 8 }, 9 required: ['foo'], 10 additionalProperties: false 11} 12 13const options = { 14 validate: true, 15 strict: false, 16 extraAjvFormats: ['date-time'] 17} 18 19const ExampleModel = openapiToModel(schema, options) 20 21// Create an empty model, with the default values 22const example = new ExampleModel() 23/* 24{ 25 foo: 'bar' 26} 27*/ 28 29// Create a model with the default values, but overwrite the given properties 30const example2 = new ExampleModel({ 31 foo: 'It works!' 32}) 33/* 34{ 35 foo: 'It works!' 36} 37*/ 38 39// Create a model with the default values, but overwrite the given properties 40const example2 = new ExampleModel({ 41 foo: 3.14 42}) 43/* 44 Throws an Error because the type is wrong 45 46 error.message 47 "Invalid data" 48 49 error.errors 50 [ 51 { 52 instancePath: '/foo', 53 keyword: 'type', 54 message: 'must be string', 55 params: { 56 type: 'string' 57 }, 58 schemaPath: '#/properties/foo/type' 59 } 60 ] 61 62 error.schema 63 { 64 type: 'object', 65 properties: { 66 foo: { 67 type: 'string', 68 default: 'bar' 69 } 70 }, 71 required: ['foo'], 72 additionalProperties: false 73 } 74 75 // The object that is send to the model 76 error.data 77 { 78 foo: 3.14 79 } 80 81 // The object that is send to the model, but also with the default values 82 error.newData 83 { 84 foo: 3.14 85 } 86*/
No vulnerabilities found.
No security vulnerabilities found.