jsonschema-oai-parameters
v0.0.6
Published
* type allow in: query,path,body,formData,header * schema standard or convenient jsonschema
Downloads
28
Readme
Simple Useage
jsonSchemaToParameters(type, schema)
- type allow in: query,path,body,formData,header
- schema standard or convenient jsonschema
Standard JsonSchema to OpenApi parameters
const standard = {
required: [
'name',
],
properties: {
name: {
type: 'string',
description: 'xxx',
},
age: {
type: 'integer',
format: 'int32',
max: 100,
min: 1,
}
}
};
jsonSchemaToParameters('query', standard)
[
{
"name": "name",
"in": "query",
"required": true,
"type": "string",
"description": "xxx"
},
{
"name": "age",
"in": "query",
"required": false,
"type": "integer",
"format": "int32",
"max": 100,
"min": 1
}
]
Convenient JsonSchema to OpenApi parameters
const convenient = {
name: {
type: 'string',
required: true,
description: 'xxx',
},
age: {
type: 'integer',
format: 'int32',
max: 100,
min: 1,
},
};
jsonSchemaToParameters('query', convenient)
[
{
"name": "name",
"in": "query",
"required": true,
"type": "string"
},
{
"name": "age",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
}
]
parametersToJsonSchema(parameters, options)
result
{object}
header
{object}
header JSON-Schemaquery
{object}
query JSON-Schemabody
{object}
body JSON-Schemapath
{object}
path JSON-Schemaformdata
{object}
formdata JSON-Schema
options
{object}
lowercaseHeader
{boolean}
defaultfalse