krakenjs / swaggerize-express

Design-driven apis with swagger 2.0 and express.
Other
354 stars 81 forks source link

How can I use JOI validation for my endpoints? #124

Open stanislavt opened 7 years ago

stanislavt commented 7 years ago

Could you please explain me, how can I use JOI schemas for custom endpoints? It really doesn't clear id documentation.

tlivings commented 7 years ago

Can you provide some additional detail on what you are trying to do? What are "custom endpoints"? Would that be an endpoint not defined in the API shema?

stanislavt commented 7 years ago

Sure.

I want to create POST /test/

api.yaml has next rows:

/test:
    post:
      summary: Test import
      parameters:
        -
          in: body
          name: body
          schema:
            $ref: '#/definitions/TestBody'
      tags:
        - Test
      responses:
        201:
          schema:
            $ref: '#/definitions/Test'

How can I define body object using joi and include it into swaggerize?

Why do I need it for: I have dependencies in body properties. E.g. email should be unique in DB table. status is depends on date