Skip to content
Permalink
Browse files

document open api disable validation

  • Loading branch information...
MykolaGolubyev committed May 13, 2019
1 parent d203c84 commit 771cea4eadd0c5c8caafca574f5bd3ee5f12d04e
@@ -4,14 +4,14 @@ Webtau supports validation of responses against an [OpenAPI specification](https
be enabled by specifying the `openApiSpecUrl` configuration option. This should be the URL to the specification against
which to validate.

:include-file: scenarios/rest/webtau-with-spec.cfg {title: "Configuration"}
:include-file: scenarios/rest/springboot/webtau-with-spec.cfg {title: "Configuration"}

# Current limitations

OpenAPI specification support is still in its early stage. It is fully functional but there are a few limitations to be
aware of:
* webtau currently only supports OpenAPI specification v2
* specification matching is currently done purely based on the path
* specification matching is currently done based on the path and method
* any HTTP requests which do not match any operation in the specification will not fail tests but will produce a warning
on the console

@@ -55,3 +55,11 @@ They are also available in the HTML report:

To ignore additional properties in responses set `openApiIgnoreAdditionalProperties` to `true`.
As any other config value it can be done via command line, config file or system properties.

# Disable Validation

Use `com.twosigma.webtau.openapi.OpenApi` to locally disable OpenAPI validation.

:include-groovy: doc-artifacts/snippets/openapi/disableAll.groovy {title: "Disable request and response validation"}
:include-groovy: doc-artifacts/snippets/openapi/disableRequest.groovy {title: "Disable request validation"}
:include-groovy: doc-artifacts/snippets/openapi/disableResponse.groovy {title: "Disable response validation"}
@@ -0,0 +1,77 @@
{
"swagger": "2.0",
"info": {
"version": "0.0.1",
"title": "Fake endpoints definition"
},
"paths": {
"/employee": {
"get": {
"summary": "retrieve employee",
"operationId": "getEmployee",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "existing employee",
"schema": {
"$ref": "#/definitions/Employee"
}
}
}
},
"post": {
"summary": "Create new employee",
"operationId": "createEmployee",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"parameters": [
{
"in": "body",
"name": "body",
"required": true,
"schema": {
"$ref": "#/definitions/Employee"
}
}
],
"responses": {
"200": {
"description": "customer already exists",
"schema": {
"$ref": "#/definitions/Employee"
}
},
"201": {
"description": "customer created successfully",
"schema": {
"$ref": "#/definitions/Employee"
}
}
}
}
}
},
"definitions": {
"Employee": {
"type": "object",
"required": [
"firstName",
"lastName"
],
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
}
}
}
}
}
@@ -0,0 +1,28 @@
package scenarios.rest.openapi

import com.twosigma.webtau.openapi.OpenApi
import static com.twosigma.webtau.WebTauGroovyDsl.*

scenario("disable all validation") {
OpenApi.withoutValidation {
http.post("/employee", [firstName: 'First']) {
// ...
}
}
}

scenario("disable request validation") {
OpenApi.responseOnlyValidation() {
http.post("/employee", [firstName: 'First']) {
// ...
}
}
}

scenario("disable response validation") {
OpenApi.requestOnlyValidation() {
http.post("/employee", [firstName: 'First', lastName: 'Second']) {
// ...
}
}
}
@@ -0,0 +1,2 @@
url = "http://localhost:8180"
openApiSpecUrl = "scenarios/rest/openapi/api-spec.json"
@@ -1,4 +1,4 @@
url = "http://localhost:8080"

docPath = "doc-artifacts"
openApiSpecUrl = "scenarios/rest/api-spec.json"
openApiSpecUrl = "scenarios/rest/springboot/api-spec.json"
@@ -44,7 +44,7 @@ class FeaturesDocArtifactsExtractor {
static String extractScenarioBody(String script, String scenario) {
def scenarioIdx = script.indexOf(scenario)
if (scenarioIdx == -1) {
throw new RuntimeException("can't find scenario >${scenario}>")
throw new RuntimeException("can't find scenario <${scenario}>")
}

def scopeStartIdx = script.indexOf("{", scenarioIdx)
@@ -70,6 +70,17 @@ class WebTauRestFeaturesTest {
runCli('jsonSchema/validateSchema.groovy', 'jsonSchema/webtau.cfg', "--url=${testRunner.testServer.uri}")
}

@Test
void "schema validation extract snippets"() {
def root = 'doc-artifacts/snippets/json-schema'

extractCodeSnippets(
root, 'examples/scenarios/rest/jsonSchema/validateSchema.groovy', [
'validateBody.groovy': 'valid schema',
'validateField.groovy': 'validate specific field',
])
}

@Test
void "redirect"() {
runCli('redirect/redirectOn.groovy', 'urlOnly.cfg', "--url=${testRunner.testServer.uri}")
@@ -81,13 +92,19 @@ class WebTauRestFeaturesTest {
}

@Test
void "schema validation extract snippets"() {
def root = 'doc-artifacts/snippets/json-schema'
void "open api disable"() {
runCli('openapi/disableOpenApiValidation.groovy', 'openapi/webtau.cfg', "--url=${testRunner.testServer.uri}")
}

@Test
void "open api extract snippets"() {
def root = 'doc-artifacts/snippets/openapi'

extractCodeSnippets(
root, 'examples/scenarios/rest/jsonSchema/validateSchema.groovy', [
'validateBody.groovy': 'valid schema',
'validateField.groovy': 'validate specific field',
root, 'examples/scenarios/rest/openapi/disableOpenApiValidation.groovy', [
'disableAll.groovy': 'disable all validation',
'disableRequest.groovy': 'disable request validation',
'disableResponse.groovy': 'disable response validation',
])
}

@@ -0,0 +1,19 @@
{
"scenarioDetails" : [ {
"scenario" : "disable all validation",
"stepsSummary" : {
"numberOfSuccessful" : 2
}
}, {
"scenario" : "disable request validation",
"stepsSummary" : {
"numberOfFailed" : 2
}
}, {
"scenario" : "disable response validation",
"stepsSummary" : {
"numberOfSuccessful" : 3
}
} ],
"exitCode" : 1
}

0 comments on commit 771cea4

Please sign in to comment.
You can’t perform that action at this time.