0

I'm using joi-to-swagger and swagger-ui-express and I'm really struggling to find out how to get this schema to show up correctly. It's getting ignored in all scenarios and I can't find the documentation I need to correctly use the schema.

My file:

import j2s from 'joi-to-swagger'
import joi from 'joi'
import swaggerUi from 'swagger-ui-express'

const myJoiSchema = joi
  .object({
    text: joi.string().max(100).required(),
  })
  .required()

const schema = j2s(myJoiSchema).swagger

const swaggerDoc = {
  swagger: '2.0',
  info: {
    title: 'title',
    version: '1.0',
  },
  paths: {
    '/my-url': {
      post: {
        summary: 'my api',
        // consumes: 'application/json',
        // parameters: mySchema, didn't work
        requestBody: {
          required: true,
          schema: {
            $ref: '#/components/schemas/mySchema',
          },
        },
      },
    },
  },
  components: {
    schemas: {
      mySchema: schema,
    },
  },
}

router.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDoc))

the schema that is produced for value schema is:

{
  type: 'object',
  properties: {
    text: { type: 'string', maxLength: 100 },
  },
  required: [ 'text' ],
  additionalProperties: false
}

How is the schema supposed to be properly used in the swagger doc? It might be special with swagger-ui-express but I can't confirm I've tested it correctly.

Kevin Danikowski
  • 4,620
  • 6
  • 41
  • 75

0 Answers0