Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ buildscript {

plugins {
java
kotlin("jvm") version "1.3.21"
kotlin("jvm") version "1.4.10"
`maven-publish`
jacoco
id("com.github.kt3k.coveralls") version "2.10.1"
id("org.jmailen.kotlinter") version "1.22.0"
id("com.github.kt3k.coveralls") version "2.10.2"
id("org.jmailen.kotlinter") version "3.2.0"
}

group = "com.github.moia-dev"
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
51 changes: 31 additions & 20 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#!/usr/bin/env sh

#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

##############################################################################
##
## Gradle start up script for UN*X
Expand Down Expand Up @@ -28,7 +44,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m"'
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
Expand Down Expand Up @@ -109,8 +125,8 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
Expand Down Expand Up @@ -138,19 +154,19 @@ if $cygwin ; then
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
i=`expr $i + 1`
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

Expand All @@ -159,14 +175,9 @@ save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
APP_ARGS=`save "$@"`

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"
18 changes: 17 additions & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
Expand All @@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m"
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
Expand Down
10 changes: 5 additions & 5 deletions router-openapi-request-validator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ dependencies {
compile(kotlin("stdlib-jdk8"))
compile(kotlin("reflect"))

compile("com.atlassian.oai:swagger-request-validator-core:2.2.2")
compile("com.atlassian.oai:swagger-request-validator-core:2.11.0")
compile(project(":router"))

testImplementation("org.junit.jupiter:junit-jupiter-engine:5.4.0")
testImplementation("org.assertj:assertj-core:3.11.1")
testImplementation("io.mockk:mockk:1.8.13.kotlin13")
testImplementation("org.slf4j:slf4j-simple:1.7.26")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.7.0")
testImplementation("org.assertj:assertj-core:3.17.2")
testImplementation("io.mockk:mockk:1.10.0")
testImplementation("org.slf4j:slf4j-simple:1.7.30")
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,23 @@ class OpenApiValidator(val specUrlOrPayload: String) {
}

fun assertValid(request: APIGatewayProxyRequestEvent, response: APIGatewayProxyResponseEvent) {
return validate(request, response).let { if (it.hasErrors()) throw ApiInteractionInvalid(
specUrlOrPayload,
request,
response,
it
)
return validate(request, response).let {
if (it.hasErrors()) throw ApiInteractionInvalid(
specUrlOrPayload,
request,
response,
it
)
}
}

fun assertValidRequest(request: APIGatewayProxyRequestEvent) =
validator.validateRequest(request.toRequest()).let { if (it.hasErrors()) throw ApiInteractionInvalid(
spec = specUrlOrPayload,
request = request,
validationReport = it
)
validator.validateRequest(request.toRequest()).let {
if (it.hasErrors()) throw ApiInteractionInvalid(
spec = specUrlOrPayload,
request = request,
validationReport = it
)
}

fun assertValidResponse(request: APIGatewayProxyRequestEvent, response: APIGatewayProxyResponseEvent) =
Expand Down Expand Up @@ -78,4 +80,4 @@ class OpenApiValidator(val specUrlOrPayload: String) {
companion object {
val log = LoggerFactory.getLogger(OpenApiValidator::class.java)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ class ValidatingRequestRouterWrapper(
companion object {
private val log = LoggerFactory.getLogger(ValidatingRequestRouterWrapper::class.java)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.moia.router.openapi

import io.mockk.mockk
import io.moia.router.GET
import io.moia.router.Request
import io.moia.router.RequestHandler
import io.moia.router.ResponseEntity
import io.moia.router.Router
import io.mockk.mockk
import org.assertj.core.api.BDDAssertions.thenThrownBy
import org.junit.jupiter.api.Test

Expand Down Expand Up @@ -73,4 +73,4 @@ class OpenApiValidatorTest {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,32 @@ class ValidatingRequestRouterWrapperTest {
@Test
fun `should skip validation`() {
val response = ValidatingRequestRouterWrapper(InvalidTestRequestHandler(), "openapi.yml")
.handleRequestSkippingRequestAndResponseValidation(GET("/path-not-documented").withAcceptHeader("application/json"), mockk())
.handleRequestSkippingRequestAndResponseValidation(GET("/path-not-documented").withAcceptHeader("application/json"), mockk())
then(response.statusCode).isEqualTo(404)
}

@Test
fun `should apply additional request validation`() {
thenThrownBy { ValidatingRequestRouterWrapper(
delegate = OpenApiValidatorTest.TestRequestHandler(),
specUrlOrPayload = "openapi.yml",
additionalRequestValidationFunctions = listOf({ _ -> throw RequestValidationFailedException() }))
.handleRequest(GET("/tests").withAcceptHeader("application/json"), mockk())
thenThrownBy {
ValidatingRequestRouterWrapper(
delegate = OpenApiValidatorTest.TestRequestHandler(),
specUrlOrPayload = "openapi.yml",
additionalRequestValidationFunctions = listOf({ _ -> throw RequestValidationFailedException() })
)
.handleRequest(GET("/tests").withAcceptHeader("application/json"), mockk())
}
.isInstanceOf(RequestValidationFailedException::class.java)
}

@Test
fun `should apply additional response validation`() {
thenThrownBy { ValidatingRequestRouterWrapper(
delegate = OpenApiValidatorTest.TestRequestHandler(),
specUrlOrPayload = "openapi.yml",
additionalResponseValidationFunctions = listOf({ _, _ -> throw ResponseValidationFailedException() }))
.handleRequest(GET("/tests").withAcceptHeader("application/json"), mockk())
thenThrownBy {
ValidatingRequestRouterWrapper(
delegate = OpenApiValidatorTest.TestRequestHandler(),
specUrlOrPayload = "openapi.yml",
additionalResponseValidationFunctions = listOf({ _, _ -> throw ResponseValidationFailedException() })
)
.handleRequest(GET("/tests").withAcceptHeader("application/json"), mockk())
}
.isInstanceOf(ResponseValidationFailedException::class.java)
}
Expand All @@ -88,4 +92,4 @@ class ValidatingRequestRouterWrapperTest {
}
}
}
}
}
18 changes: 9 additions & 9 deletions router-protobuf/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import com.google.protobuf.gradle.protobuf
import com.google.protobuf.gradle.protoc

plugins {
id("com.google.protobuf") version "0.8.7"
id("com.google.protobuf") version "0.8.13"
}

repositories {
Expand All @@ -13,24 +13,24 @@ dependencies {
compile(kotlin("stdlib-jdk8"))
compile(kotlin("reflect"))

compile("org.slf4j:slf4j-api:1.7.26")
compile("com.google.protobuf:protobuf-java:3.11.1")
compile("com.google.protobuf:protobuf-java-util:3.11.1")
compile("com.google.guava:guava:23.0")
compile("org.slf4j:slf4j-api:1.7.30")
compile("com.google.protobuf:protobuf-java:3.13.0")
compile("com.google.protobuf:protobuf-java-util:3.13.0")
compile("com.google.guava:guava:29.0-jre")
compile(project(":router"))

testImplementation("org.junit.jupiter:junit-jupiter-engine:5.4.0")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.7.0")
testImplementation("com.willowtreeapps.assertk:assertk-jvm:0.12")
testImplementation("org.assertj:assertj-core:3.11.1")
testImplementation("io.mockk:mockk:1.8.13.kotlin13")
testImplementation("org.slf4j:slf4j-simple:1.7.26")
testImplementation("io.mockk:mockk:1.10.0")
testImplementation("org.slf4j:slf4j-simple:1.7.30")
testImplementation("com.jayway.jsonpath:json-path:2.4.0")
}


protobuf {
protoc {
// The artifact spec for the Protobuf Compiler
artifact = "com.google.protobuf:protoc:3.6.1"
artifact = "com.google.protobuf:protoc:3.13.0"
}
}
Loading