1.2.7 • Published 2 years ago
swagger-to-joi v1.2.7
swagger-to-joi
Swagger to Joi converter
Generates text for Joi definitions. Definitions could be stored to a file or run using eval
.
Example usage:
const swaggerToJoi = require('swagger-to-joi');
const joiTextObject = swaggerToJoi(swaggerRouteParametersInJson, components, version, options);
// process joiTextObject or store joi definitions to a file
// returning object contain separate definitions for path, query and body
Example:
const swaggerToJoi = require('swagger-to-joi');
const swagger = {
swagger: '2.0',
schema: {
body: {
type: "object",
required: ["apiVersion", "data"],
properties: {
apiVersion: { type: "string", enum: ["1.0"], example: "1.0" },
data: {
type: "object",
required: ["projectId", "organization", "value", "currencyCode"],
properties: {
projectId: { type: "string", example: "1234567" },
organization: { type: "string", example: "My Org" },
currencyCode: { type: "string", example: "EUR" },
value: { type: "number", example: 50000 },
},
},
},
}
}
const joiTextObject = swaggerToJoi(swaggerRouteParametersInJson);
console.log(joiTextObject);
/*
Outputs:
Joi.object({
apiVersion: Joi.valid("1.0").required(),
data: Joi.object({
projectId: Joi.string().required(),
organization: Joi.string().required(),
currencyCode: Joi.string().required(),
value: Joi.number().required(),
}),
})
*/
Parameters
Components
Used for openAPI 3.0.0. Components used in schema.
Version
2.0
or 3.0.0
. default 3.0.0
.
Options
singleQuote
- boolean - determines if you want to user ' or " quotes. Default: true.overrideKeys
- key-value object. E.g.{ projectId: 'Project.id' }
. Will override all keys in any swagger definition where key in swagger will match keyname from the overide object.
1.2.7
2 years ago
1.2.6
3 years ago
1.2.4
3 years ago
1.2.3
3 years ago
1.2.0
3 years ago
1.2.2
3 years ago
1.2.1
3 years ago
1.1.12
3 years ago
1.1.11
3 years ago
1.1.10
3 years ago
1.1.9
3 years ago
1.1.8
3 years ago
1.1.7
4 years ago
1.1.6
4 years ago
1.1.5
4 years ago
1.1.4
4 years ago
1.1.3
4 years ago
1.1.1
4 years ago
1.1.0
4 years ago
1.1.2
4 years ago
1.0.1
4 years ago
1.0.0
4 years ago