An open API service indexing awesome lists of open source software.

https://github.com/kenshoo/swagger-validator

Jax-Rs validator for swagger
https://github.com/kenshoo/swagger-validator

managedby-tec-dev public-repo

Last synced: 7 months ago
JSON representation

Jax-Rs validator for swagger

Awesome Lists containing this project

README

          

# Swagger Validator
[![Build Status](https://travis-ci.org/kenshoo/swagger-validator.svg?branch=master)](https://travis-ci.org/kenshoo/swagger-validator)

## Overview
Validates swagger.yaml file.
Validation are done assuming JAX-RS resources and Jackson POJOs.

The default validations include:
- Resources validations:
- The resource class exists (See x-javaClass)
- The resource class annotated with @Path and that the value matches.
- For each operation validate that:
- Exists method in a resource annotated with the proper annotation (e.g. GET, POST, etc.)
- Operation is tagged.
- Definitions validations:
- The POJO exists (See x-javaClass)
- Property from definition matches a property in POJO (By default property in Swagger equals to field in POJO)
- POJO doesn't use forbidden types (e.g. using primitive types is forbidden)
- Warning is printed if unrecommended type is used.

## Validator Elements
The Swagger Validator expects additional elements to be present in the swagger.yaml to perform the validations.
#### x-javaClass
**x-javaClass** defines the fully qualified name of the desired class. This is used to validate that the relevant class really exists in the classpath and it's a starting point for addition validations.

## Download
The Swagger Validator is distributed using Maven Central.

### Maven Dependency
```

com.kenshoo
swagger-validator
${swagger-validator-version}

```

## Running
The SwaggerValidator is a simple Java class. It must be run in the classpath containing all the resources and definitions.

#### Example
```
SwaggerValidator swaggerValidator = new SwaggerValidator(getClass().getResourceAsStream("/swagger.yaml"));
swaggerValidator.validateDefinitions();
swaggerValidator.validateResources();
```
See unit tests for more examples.

#### Customization
```
SwaggerValidatorConf conf = new SwaggerValidatorConf() {
@Override
public Set> getForbiddenClasses() {
return Collections.emptySet();
}
};
SwaggerValidator swaggerValidator = new SwaggerValidator(getClass().getResourceAsStream("/swagger.yaml"), conf);
swaggerValidator.validateDefinitions(); // forbidden types won't be validated
```