Skip to content
Open
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
17 changes: 9 additions & 8 deletions .github/workflows/swagger.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
name: Publish Swagger Specs

on:
push:
branches:
- master

- CCD-6801-fix-swagger-ui-ft-patch
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v3
- name: Set up Cache
uses: actions/cache@v4
uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
Expand All @@ -29,11 +28,13 @@ jobs:
cd swagger-staging
git init
git config user.email "github-actions@users.noreply.github.com"
git config user.name "CCD GitHub action"
git remote add upstream https://${{ secrets.SWAGGER_PUBLISHER_API_TOKEN }}@github.com/hmcts/cnp-api-docs.git
git config user.name "GitHub action"
git remote add upstream "https://jenkins-reform-hmcts:${{ secrets.SWAGGER_PUBLISHER_API_TOKEN }}@github.com/hmcts/cnp-api-docs.git"
git pull upstream master
repo=`echo "$GITHUB_REPOSITORY" | cut -f2- -d/`
echo "$(cat /tmp/swagger-specs.json)" > "docs/specs/$repo.json"
git add "docs/specs/$repo.json"
git add "docs/specs/ccd-data-store-api.v1_internal.json"
git add "docs/specs/ccd-data-store-api.v1_external.json"
git add "docs/specs/ccd-data-store-api.v2_internal.json"
git add "docs/specs/ccd-data-store-api.v2_external.json"
# Only commit and push if we have changes.
git diff --quiet && git diff --staged --quiet || (git commit -m "Update spec for $repo#${GITHUB_SHA:7}"; git push --set-upstream upstream master)
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ protected BeftaTestDataLoader buildTestDataLoader() {
public synchronized Object calculateCustomValue(BackEndFunctionalTestScenarioContext scenarioContext, Object key) {
//the docAMUrl is is referring the self link in PR
String docAmUrl = EnvironmentVariableUtils.getRequiredVariable("TEST_URL");
if (key.toString().startsWith("contains ") && key.toString().contains(" and does not contain ")) {
return getContainsAndDoesNotContainPlainText(scenarioContext, key.toString());
}
switch (key.toString()) {
case ("documentIdInTheResponse"):
return getDocumentIdInTheRresponse(scenarioContext);
Expand All @@ -40,6 +43,25 @@ public synchronized Object calculateCustomValue(BackEndFunctionalTestScenarioCon

}

private Object getContainsAndDoesNotContainPlainText(BackEndFunctionalTestScenarioContext scenarioContext,
String key) {
try {
String actualValueStr = (String) ReflectionUtils.deepGetFieldInObject(scenarioContext,
"testData.actualResponse.body.__plainTextValue__");
String[] expectedValues = key.split(" and does not contain ", 2);
String expectedPresentValueStr = expectedValues[0].replace("contains ", "");
String expectedAbsentValueStr = expectedValues[1];

if (actualValueStr.contains(expectedPresentValueStr)
&& !actualValueStr.contains(expectedAbsentValueStr)) {
return actualValueStr;
}
return "response did not match plain text expectations";
} catch (Exception e) {
throw new FunctionalTestException("Problem checking acceptable response payload: ", e);
}
}

private Object getHashTokenDifferentFromPrevious(BackEndFunctionalTestScenarioContext scenarioContext) {
try {
String newHashToken = (String) ReflectionUtils
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#===============================================
@F-125
Feature: F-125: Swagger Pages and Open API Specs
#===============================================

#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@S-125.1
Scenario: must show Swagger UI page for Internal V1 APIs

Given an appropriate test context as detailed in the test data source,

When a request is prepared with appropriate values,
And it is submitted to call the [Get Swagger UI Page] operation of [CCD Case Document Am Api],

Then a positive response is received,
And the response has all the details as expected
And a call [to observe the swagger json content] will get the expected response as in [S-125_Swagger_JSON_V1_Internal].

#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@S-125.2
Scenario: must show Swagger UI page for External V1 APIs

Given an appropriate test context as detailed in the test data source,

When a request is prepared with appropriate values,
And it is submitted to call the [Get Swagger UI Page] operation of [CCD Case Document Am Api],

Then a positive response is received,
And the response has all the details as expected
And a call [to observe the swagger json content] will get the expected response as in [S-125_Swagger_JSON_V1_External].

#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@S-125.3
Scenario: must show Swagger UI page for Internal V2 APIs

Given an appropriate test context as detailed in the test data source,

When a request is prepared with appropriate values,
And it is submitted to call the [Get Swagger UI Page] operation of [CCD Case Document Am Api],

Then a positive response is received,
And the response has all the details as expected
And a call [to observe the swagger json content] will get the expected response as in [S-125_Swagger_JSON_V2_Internal].

#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@S-125.4
Scenario: must show Swagger UI page for External V2 APIs

Given an appropriate test context as detailed in the test data source,

When a request is prepared with appropriate values,
And it is submitted to call the [Get Swagger UI Page] operation of [CCD Case Document Am Api],

Then a positive response is received,
And the response has all the details as expected
And a call [to observe the swagger json content] will get the expected response as in [S-125_Swagger_JSON_V2_External].

#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@S-125.5
Scenario: must show Swagger Config JSON Page

Given an appropriate test context as detailed in the test data source,

When a request is prepared with appropriate values,
And it is submitted to call the [Get Swagger Config JSON Page] operation of [CCD Case Document Am Api],

Then a positive response is received,
And the response has all the details as expected
And a call [to observe the swagger config json content] will get the expected response as in [S-125.5].

#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"_guid_": "F-125_Swagger_JSON",
"title": "Verify swagger JSON Content",

"productName": "CCD Case Document Am Api",
"operationName": "Get Swagger JSON",

"method": "GET",
"uri": "https://hmcts.github.io/cnp-api-docs/specs/{ccd-case-document-am-api-version}",

"expectedResponse": {
"headers" : {
"Content-Encoding" : "gzip",
"Content-Length" : "${[scenarioContext][customValues][approximately 5838]}",
"Content-Type" : "application/json; charset=utf-8",
"Date" : "[[ANYTHING_PRESENT]]",
"Expires" : "[[ANYTHING_PRESENT]]",
"Last-Modified" : "[[ANYTHING_PRESENT]]",
"Server" : "GitHub.com"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"_guid_": "F-125_Swagger_UI",
"title": "Verify swagger UI Content",

"productName": "CCD Case Document Am Api",
"operationName": "Get Swagger UI Page",

"method": "GET",
"uri": "/swagger-ui/index.html",

"expectedResponse": {
"responseCode" : 200,
"responseMessage" : "OK",
"headers" : {
"Accept-Ranges" : "bytes",
"Content-Encoding" : "gzip",
"Content-Length" : "${[scenarioContext][customValues][approximately 1190]}",
"Content-Type" : "text/html"
},
"body" : {
"__plainTextValue__": "${[scenarioContext][customValues][contains Swagger UI and does not contain Failed to load remote configuration]}"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"_guid_": "F-125_Test_Swagger_Config_Base_Data",
"title": "Verify swagger Config",

"productName": "CCD Case Document Am Api",
"operationName": "Get Swagger Config JSON Page",

"method": "GET",
"uri": "/v3/api-docs/swagger-config",

"expectedResponse": {
"responseCode" : 200,
"responseMessage" : "OK",
"headers" : {
"Accept-Ranges" : "bytes",
"Content-Encoding" : "gzip",
"Content-Type" : "application/json"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"_guid_": "S-125.1",
"title": "must show Swagger UI page for Internal V1 APIs",
"_extends_": "F-125_Swagger_UI",

"specs": [
"to observe the swagger UI content"
],

"request": {
"queryParams": {
"urls.primaryName": "v1_internal"
}
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"_guid_": "S-125.2",
"title": "must show Swagger UI page for External V1 APIs",
"_extends_": "F-125_Swagger_UI",

"specs": [
"to observe the swagger UI content"
],

"request": {
"queryParams": {
"urls.primaryName": "v1_internal"
}
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"_guid_": "S-125.3",
"title": "must show Swagger UI page for Internal V2 APIs",
"_extends_": "F-125_Swagger_UI",

"specs": [
"to observe the swagger UI content"
],

"request": {
"queryParams": {
"urls.primaryName": "v1_internal"
}
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"_guid_": "S-125.4",
"title": "must show Swagger UI page for External V2 APIs",
"_extends_": "F-125_Swagger_UI",

"specs": [
"to observe the swagger UI content"
],

"request": {
"queryParams": {
"urls.primaryName": "v1_internal"
}
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"_guid_": "S-125.5",
"title": "Must return a positive appropriate response when Swagger config URL is accessed",
"_extends_": "F-125_Test_Swagger_Config_Base_Data",

"specs": [
"to observe the swagger config json content"
],

"request" :{
},

"expectedResponse": {
"body" : {
"configUrl" : "[[ANYTHING_PRESENT]]",
"url" : "[[ANYTHING_PRESENT]]",
"oauth2RedirectUrl" : "[[ANYTHING_PRESENT]]",
"validatorUrl" : "[[ANYTHING_PRESENT]]"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"_guid_": "S-125_Swagger_JSON_V1_External",
"title": "Must return a positive appropriate response when Swagger JSON External V1 URL is accessed",
"_extends_": "F-125_Swagger_JSON",

"specs": [
"to observe the swagger json content"
],

"request" :{
"pathVariables" : {
"ccd-case-document-am-api-version": "ccd-case-document-am-api-version.v3_external.json"
}
},

"expectedResponse": {
"responseCode" : 200,
"responseMessage" : "OK",
"body" : {
"host" : "[[ANYTHING_PRESENT]]",
"basePath": "/",
"tags": "[[ANYTHING_PRESENT]]",
"paths": "[[ANYTHING_PRESENT]]",
"definitions": "[[ANYTHING_PRESENT]]",
"swagger": "2.0",
"info": {
"description": "Create, modify, retrieve and search cases",
"title": "Core Case Data - Data store API",
"contact":"[[ANYTHING_PRESENT]]",
"license": "[[ANYTHING_PRESENT]]",
"version": "[[ANYTHING_PRESENT]]"

}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"_guid_": "S-125_Swagger_JSON_V1_Internal",
"title": "Must return a positive appropriate response when Swagger JSON Internal V1 URL is accessed",
"_extends_": "F-125_Swagger_JSON",

"specs": [
"to observe the swagger json content"
],

"request" :{
"pathVariables" : {
"ccd-case-document-am-api-version": "ccd-case-document-am-api-version.v3_internal.json"
}
},

"expectedResponse": {
"responseCode" : 200,
"responseMessage" : "OK",
"body" : {
"host" : "[[ANYTHING_PRESENT]]",
"basePath": "/",
"tags": "[[ANYTHING_PRESENT]]",
"paths": "[[ANYTHING_PRESENT]]",
"definitions": "[[ANYTHING_PRESENT]]",
"swagger": "2.0",
"info": {
"description": "Create, modify, retrieve and search cases",
"title": "Core Case Data - Data store API",
"contact":"[[ANYTHING_PRESENT]]",
"license": "[[ANYTHING_PRESENT]]",
"version": "[[ANYTHING_PRESENT]]"

}
}
}
}
Loading
Loading