Skip to content

Validator

Steve Hu edited this page Sep 25, 2016 · 2 revisions

The framework encourages design driven implementation so swagger specification should be done before the implementation starts. With the swagger-codegen undertow generator, the server stub can be generated and start running within minutes. However, we cannot rely on generator for validation as specification will be changed along the life cycle of the API. This is why we have provided a validator that works on top of the specification at runtime. In this way, the generator should only be used once and the validator will take the latest spec. and validate according the spec. at runtime.

ValidatorHandler

This is the entry point of the validator and it is injected during server start up if validator.json enableValidator is true. By default, only RequestValidator will be called. However, ResponseValidator can be enabled by setting enableResponseValidator to true in validator.json.

RequestValidator

It will validate the following:

  • uri
  • method
  • header
  • query parameters
  • path parameters
  • body if available

When necessary, schema validator will be called to do json schema validation.

ResponseValidator

It will validate the following: header response code body if available

when necessary, json schema validator will be called.

SchemaValidator

If schema is defined in swagger.json, then the json-schema-validator will be called.

Test

In order to test validator, the test suite starts an undertow server and serves petstore api for testing. It is a demo on how to unit test your API during development.

Clone this wiki locally