Function validateWithSwagger

  • Creates a new middleware, which checks the request data with a Swagger documentation for an endpoint.

    Parameters

    Returns UniqueHttpMiddleware

    The new middleware.

    Example

    import createServer, { query, validateWithSwagger } from '@egomobile/http-server'
    import type { OpenAPIV3.OperationObject } from 'openapi-types'

    const swaggerDocumentOfGetRequest: OpenAPIV3.OperationObject = {
    "parameters": [
    {
    in: 'query',
    name: 'foo',
    required: true
    },
    "responses": {}
    ]
    }

    const app = createServer()

    app.get(
    '/',
    [
    query(),
    validateWithSwagger(swaggerDocumentOfGetRequest)
    ],
    async (request, response) => {
    assert.strictEqual(typeof request.query!.get('foo'), 'string')
    }
    )

    // ...

Generated using TypeDoc