Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Atlassian swagger-request-validator library #118

Merged
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5845df2
Implemented support for exceptions from atlassian-swagger-request-val…
smals-mavh Oct 14, 2024
d1322b8
Implemented feedback
smals-mavh Oct 15, 2024
3657fa3
Experimental if errorhandler works with order specified on gh actions
smals-mavh Oct 17, 2024
66761b8
Implement feedback: Only check for non-empty in title and details field
smals-mavh Oct 17, 2024
2cf840c
Implement feedback: Added javadoc
smals-mavh Oct 17, 2024
25911bd
Implemented feedback: override test in SB2 IT
smals-mavh Oct 17, 2024
06dc134
Implemented feedback: Use existing factory methods to create InputVal…
smals-mavh Oct 17, 2024
760bee6
Add openapi-validation integration tests to code coverage
jpraet Oct 17, 2024
cb2ce19
Implemented feedback: Removed versions that were already set in depen…
smals-mavh Oct 18, 2024
e46cb51
Remove unnecessary @Order(1)
jpraet Oct 18, 2024
9852b4f
Add @Order(1) again
jpraet Oct 18, 2024
85bb831
Implement feedback: Remove log().all()
smals-mavh Oct 18, 2024
2a8dbae
Implement feedback: Use queryParam method in restassured tests
smals-mavh Oct 18, 2024
762f13e
Implement feedback: Use ContentType.JSON
smals-mavh Oct 18, 2024
98e1562
Implement feedback: Add test for missing required query param
smals-mavh Oct 18, 2024
e258843
Refactor #118 (#121)
jpraet Oct 21, 2024
da8daa2
Merge branch 'main' into 97-support-exceptions-from-atlassian-swagger…
jpraet Oct 21, 2024
9f28cb5
Implemented feedback
smals-mavh Oct 21, 2024
7945dd8
Merge branch '97-support-exceptions-from-atlassian-swagger-request-va…
smals-mavh Oct 21, 2024
69e26d6
re-activate missing path for sb3
smals-mavh Oct 21, 2024
04b99a0
Merge branch 'main' into 97-support-exceptions-from-atlassian-swagger…
jpraet Oct 21, 2024
8d2c865
Merge branch 'main' into 97-support-exceptions-from-atlassian-swagger…
jpraet Oct 23, 2024
656449a
Merge branch 'main' into 97-support-exceptions-from-atlassian-swagger…
smals-mavh Oct 24, 2024
ee1324d
Added documentation and releasenote
smals-mavh Oct 24, 2024
882f2f6
Merge branch 'main' into 97-support-exceptions-from-atlassian-swagger…
jpraet Oct 29, 2024
c15c736
Implement feedback: lazy load requestBody
smals-mavh Oct 29, 2024
663c0c4
Implemented feedback: Removed check for HTTP method
smals-mavh Oct 29, 2024
b9e25a4
Merge branch '97-support-exceptions-from-atlassian-swagger-request-va…
smals-mavh Oct 29, 2024
663358d
Implemented feedback: Added unit tests for exception handler
smals-mavh Oct 29, 2024
e2e8b77
Implemented feedback: Created InvalidRequestUtilTest
smals-mavh Oct 29, 2024
44ae7c9
Merge branch 'main' into 97-support-exceptions-from-atlassian-swagger…
jpraet Oct 30, 2024
50e36f5
Improve doc
jpraet Oct 30, 2024
33b438a
Apply sonar-suggested improvement of regex
jpraet Oct 30, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
package io.github.belgif.rest.problem;

import static org.hamcrest.Matchers.*;

import org.junit.jupiter.api.Test;

import io.restassured.specification.RequestSpecification;

abstract class AbstractOpenApiValidationSpringBootIT {

private static final String BAD_REQUEST_URN = "urn:problem-type:belgif:badRequest";
private static final String SCHEMA_VIOLATION_URN = "urn:problem-type:belgif:input-validation:schemaViolation";

protected abstract RequestSpecification getSpec();

@Test
void validPathParamWorksTest() {
getSpec().when().get("/myFirstPath/abc1234567").then().assertThat()
.statusCode(200).log().all()
clone1612 marked this conversation as resolved.
Show resolved Hide resolved
.body(equalTo("All good!"));
}

@Test
void notFound() {
getSpec().when().get("/not/found").then().assertThat()
.statusCode(404).log().all()
.body("type", equalTo("urn:problem-type:belgif:resourceNotFound"));
}

@Test
void unknownQueryParamTest() {
getSpec().when().get("/myFirstPath?myUnknownParam=123").then().assertThat()
smals-mavh marked this conversation as resolved.
Show resolved Hide resolved
.statusCode(400).log().all()
.body("type", equalTo(BAD_REQUEST_URN))
.body("issues[0].type", equalTo("urn:problem-type:belgif:input-validation:unknownInput"))
.body("issues[0].title", not(empty()))
.body("issues[0].in", equalTo("query"))
.body("issues[0].name", equalTo("myUnknownParam"))
.body("issues[0].value", equalTo("123"))
.body("issues[0].detail",
not(empty()));
}

@Test
void invalidPathParamTest() {
getSpec().when().get("/myFirstPath/a1a1234567").then().assertThat()
.statusCode(400).log().all()
.body("type", equalTo(BAD_REQUEST_URN))
.body("issues[0].type", equalTo(SCHEMA_VIOLATION_URN))
.body("issues[0].title", not(empty()))
.body("issues[0].in", equalTo("path"))
.body("issues[0].name", equalTo("pathParam"))
.body("issues[0].value", equalTo("a1a1234567"))
.body("issues[0].detail",
not(empty()));
}

@Test
void pathParamTooShortTest() {
getSpec().when().get("/myFirstPath/abc").then().assertThat()
.statusCode(400).log().all()
.body("type", equalTo(BAD_REQUEST_URN))
.body("issues[0].type", equalTo(SCHEMA_VIOLATION_URN))
.body("issues[0].title", not(empty()))
.body("issues[0].in", equalTo("path"))
.body("issues[0].name", equalTo("pathParam"))
.body("issues[0].value", equalTo("abc"))
.body("issues[0].detail",
not(empty()));
}

@Test
void validQueryParamWorksTest() {
getSpec().when().get("/myFirstPath?myParam=abc1234567").then().assertThat()
.statusCode(200).log().all()
.body(equalTo("All good!"));
}

smals-mavh marked this conversation as resolved.
Show resolved Hide resolved
@Test
void invalidQueryParamTest() {
getSpec().when().get("/myFirstPath?myParam=a1a1234567").then().assertThat()
.statusCode(400).log().all()
.body("type", equalTo(BAD_REQUEST_URN))
.body("issues[0].type", equalTo(SCHEMA_VIOLATION_URN))
.body("issues[0].title", not(empty()))
.body("issues[0].in", equalTo("query"))
.body("issues[0].name", equalTo("myParam"))
.body("issues[0].value", equalTo("a1a1234567"))
.body("issues[0].detail",
not(empty()));
}

@Test
void queryParamTooShortTest() {
getSpec().when().get("/myFirstPath?myParam=abc").then().assertThat()
.statusCode(400).log().all()
.body("type", equalTo(BAD_REQUEST_URN))
.body("issues[0].type", equalTo(SCHEMA_VIOLATION_URN))
.body("issues[0].title", not(empty()))
.body("issues[0].in", equalTo("query"))
.body("issues[0].name", equalTo("myParam"))
.body("issues[0].value", equalTo("abc"))
.body("issues[0].detail",
not(empty()));
}

@Test
void absentHeaderParamTest() {
getSpec().when().get("/myHeaderPath").then().assertThat()
.statusCode(400).log().all()
.body("type", equalTo(BAD_REQUEST_URN))
.body("issues[0].type", equalTo(SCHEMA_VIOLATION_URN))
.body("issues[0].title", not(empty()))
.body("issues[0].in", equalTo("header"))
.body("issues[0].name", equalTo("MyHeader"))
.body("issues[0].value", nullValue())
.body("issues[0].detail",
not(empty()));
}

@Test
void headerParamTooShortTest() {
getSpec().when().header("MyHeader", "abc").get("/myHeaderPath").then().assertThat()
.statusCode(400).log().all()
.body("type", equalTo(BAD_REQUEST_URN))
.body("issues[0].type", equalTo(SCHEMA_VIOLATION_URN))
.body("issues[0].title", not(empty()))
.body("issues[0].in", equalTo("header"))
.body("issues[0].name", equalTo("MyHeader"))
.body("issues[0].value", equalTo("abc"))
.body("issues[0].detail",
not(empty()));
}

@Test
void requestBodyJsonParseErrorTest() {
getSpec().contentType("application/json").body("{" +
smals-mavh marked this conversation as resolved.
Show resolved Hide resolved
"\"name\" ; this is my name" +
"}").when().post("/myFirstPath").then().assertThat()
.statusCode(400).log().all()
.body("type", equalTo(BAD_REQUEST_URN))
.body("issues[0].type", equalTo(SCHEMA_VIOLATION_URN))
.body("issues[0].title", not(empty()))
.body("issues[0].in", equalTo("body"))
.body("issues[0].value", nullValue())
.body("issues[0].detail",
not(empty()));
}

@Test
void missingRequestBodyTest() {
getSpec().contentType("application/json").when().post("/myFirstPath").then().assertThat()
.statusCode(400).log().all()
.body("type", equalTo(BAD_REQUEST_URN))
.body("issues[0].type", equalTo(SCHEMA_VIOLATION_URN))
.body("issues[0].title", not(empty()))
.body("issues[0].in", equalTo("body"))
.body("issues[0].value", nullValue())
.body("issues[0].detail",
not(empty()));
}

clone1612 marked this conversation as resolved.
Show resolved Hide resolved
@Test
void invalidRequestBodyTest() {
getSpec().contentType("application/json").body("{" +
"\"myFirstProperty\": \"yes\"," +
"\"myInnerObject\": {" +
"\"myParam\": \"abc\"" +
"}" +
"}").when().post("/myFirstPath").then().assertThat()
.statusCode(400).log().all()
.body("type", equalTo(BAD_REQUEST_URN))
.body("issues[0].type", equalTo(SCHEMA_VIOLATION_URN))
.body("issues[0].title", not(empty()))
.body("issues[0].in", equalTo("body"))
.body("issues[0].name", equalTo("/myInnerObject/myParam"))
.body("issues[0].value", equalTo("abc"))
.body("issues[0].detail",
not(empty()));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
openapi: 3.0.3
info:
title: Belgif REST problem IT
version: v1
servers:
- url: /demo/v1
paths:
/myFirstPath:
get:
operationId: myFirstGetOperation
parameters:
- name: myParam
in: query
description: My First Parameter
required: false
schema:
$ref: '#/components/schemas/MyParameterSchema'
responses:
200:
$ref: '#/components/responses/MyDummyResponse'
post:
operationId: myFirstPostOperation
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/MyRequestBodySchema'
required: true
responses:
200:
$ref: '#/components/responses/MyDummyResponse'

/myFirstPath/{pathParam}:
get:
operationId: mySecondGetOperation
parameters:
- name: pathParam
in: path
description: My Path Parameter
required: true
schema:
$ref: '#/components/schemas/MyParameterSchema'
responses:
200:
$ref: '#/components/responses/MyDummyResponse'

/myHeaderPath:
get:
operationId: myHeaderGetOperation
parameters:
- name: MyHeader
in: header
description: My Header Parameter
required: true
schema:
$ref: '#/components/schemas/MyParameterSchema'
responses:
200:
$ref: '#/components/responses/MyDummyResponse'

components:
responses:
MyDummyResponse:
description: successful operation
content:
application/json:
schema:
type: string
schemas:
MyParameterSchema:
type: string
minLength: 10
pattern: ^[a-c]{3}\d*$
MyRequestBodySchema:
type: object
properties:
myFirstProperty:
type: string
myInnerObject:
$ref: '#/components/schemas/MyInnerObject'
MyInnerObject:
type: object
properties:
myParam:
$ref: '#/components/schemas/MyParameterSchema'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/openapi.yaml
Loading