/3scale-validator-policy

3Scale Custom policy that validates requests again an Open API Specification

Primary LanguageJava

3Scale Validator Policy

Overview

demo overview
  1. Get the Open API Specification of the API from the Service Registry

  2. Intercept the incoming request

  3. Do the validation (https://bitbucket.org/atlassian/swagger-request-validator)

  4. Forward the request to the gateway and the target API

Demo Setup

Apicurio Registry

Upload the person-openapi.json file to the Service Registry

registry 01
registry 02

Setup the Policy in 3Sscale

policy configuration
policy configuration 2

Running the policy locally

Run

cd person-api
mvn quarkus:dev

Test

export http_proxy=http://localhost:8000
# Create a user
curl -v "http://localhost:8080/person" -H "Cookie: redhat, apim" -H 'Content-Type: application/json' -d '{"id": "125", "name": "Teste", "phone": "551195423423", "city": "Brasilia", "state": "DF", "age": 30 }'
# Get all users
curl -v "http://localhost:8080/person" -H "Cookie: redhat, apim" -H 'Content-Type: application/json'
# Test the validation (age as String) should raise an error
curl -v "http://localhost:8080/person" -H "Cookie: redhat, apim" -H 'Content-Type: application/json' -d '{"id": "125", "name": "Teste", "phone": "551195423423", "city": "Brasilia", "state": "DF", "age": "30" }'