Twipped / joi-to-swagger

A library to convert Joi schema objects into Swagger schema definitions
Other
164 stars 63 forks source link

Usage of joi.ref() in min()/max() generated invalid schemas #100

Closed Mairu closed 1 year ago

Mairu commented 1 year ago

Originally reported through PR https://github.com/Twipped/joi-to-swagger/pull/98


Commonly this library ignores Joi.ref() what is fine, but in this case it generates invalid .json which can't be compiled

Joi implementation example

Joi.object({
  durationFrom: Joi.number().integer().min(0).max(999).optional().allow(null).example(10),
  durationTo: Joi.number().integer().min(Joi.ref('/body.durationFrom')).max(999).optional().allow(null).example(10)
})

will generate

{
  "durationFrom": {
    "type": "integer",
    "minimum": 0,
    "maximum": 999,
    "nullable": true,
    "example": 10
  },
  "durationTo": {
    "type": "integer",
    "minimum": {
      "adjust": null,
      "in": false,
      "iterables": null,
      "map": null,
      "separator": ".",
      "type": "value",
      "ancestor": "root",
      "path": [
        "body",
        "durationFrom"
      ],
      "depth": 2,
      "key": "body.durationFrom",
      "root": "body",
      "display": "ref:root:body.durationFrom"
    },
    "maximum": 999,
    "nullable": true,
    "example": 10
  }
}