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
- Host: GitHub
- URL: https://github.com/kenshoo/swagger-validator
- Owner: kenshoo
- Created: 2015-01-26T16:02:53.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2025-07-29T08:48:21.000Z (9 months ago)
- Last Synced: 2025-07-29T10:48:42.960Z (9 months ago)
- Topics: managedby-tec-dev, public-repo
- Language: Java
- Homepage:
- Size: 122 KB
- Stars: 11
- Watchers: 181
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Swagger Validator
[](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
```