Skip to content

Commit 8c42b6a

Browse files
authored
Merge pull request #19 from hmcts/duncancrawford-patch-1
Update OpenAPI spec by removing pipeline details
2 parents ef8493d + db8469c commit 8c42b6a

File tree

7 files changed

+85
-235
lines changed

7 files changed

+85
-235
lines changed

src/main/java/uk/gov/hmcts/cp/config/OpenAPIConfigurationLoader.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@
33
import io.swagger.v3.oas.models.OpenAPI;
44
import io.swagger.v3.parser.OpenAPIV3Parser;
55
import io.swagger.v3.parser.core.models.SwaggerParseResult;
6-
import org.slf4j.Logger;
7-
import org.slf4j.LoggerFactory;
6+
import lombok.extern.slf4j.Slf4j;
87

98
import java.io.IOException;
109
import java.io.InputStream;
1110
import java.io.UncheckedIOException;
1211
import java.nio.charset.StandardCharsets;
1312

13+
@Slf4j
1414
public final class OpenAPIConfigurationLoader {
1515

16-
private static final Logger LOG = LoggerFactory.getLogger(OpenAPIConfigurationLoader.class);
17-
1816
// Match your Gradle include("*.openapi.yml")
1917
private static final String SPEC_PATH = "openapi/case-admin-doc-knowledge-api.openapi.yml";
2018

@@ -28,7 +26,7 @@ public static OpenAPI loadOpenApiFromClasspath(final String path) {
2826
Thread.currentThread().getContextClassLoader().getResourceAsStream(path)) {
2927

3028
if (inputStream == null) {
31-
LOG.error("OpenAPI specification file not found on classpath: {}", path);
29+
log.error("OpenAPI specification file not found on classpath: {}", path);
3230
throw new IllegalArgumentException("Missing resource: " + path);
3331
}
3432

@@ -37,12 +35,12 @@ public static OpenAPI loadOpenApiFromClasspath(final String path) {
3735
throw new IllegalArgumentException("OpenAPI specification is empty: " + path);
3836
}
3937

40-
SwaggerParseResult result = new OpenAPIV3Parser().readContents(yaml, null, null);
38+
final SwaggerParseResult result = new OpenAPIV3Parser().readContents(yaml, null, null);
4139
if (result == null || result.getOpenAPI() == null) {
42-
String messages = (result != null && result.getMessages() != null)
40+
final String messages = (result != null && result.getMessages() != null)
4341
? String.join("; ", result.getMessages())
4442
: "Unknown parser error";
45-
LOG.error("Failed to parse OpenAPI spec at {}: {}", path, messages);
43+
log.error("Failed to parse OpenAPI spec at {}: {}", path, messages);
4644
throw new IllegalStateException("Failed to parse OpenAPI spec at " + path + ": " + messages);
4745
}
4846

@@ -53,7 +51,9 @@ public static OpenAPI loadOpenApiFromClasspath(final String path) {
5351
}
5452
}
5553

56-
/** Convenience accessor using the default SPEC_PATH. */
54+
/**
55+
* Convenience accessor using the default SPEC_PATH.
56+
*/
5757
public OpenAPI openAPI() {
5858
return loadOpenApiFromClasspath(SPEC_PATH);
5959
}

src/main/resources/openapi/case-admin-doc-knowledge-api.openapi.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ info:
88
- The latest snapshot for a Case
99
- An **as-of** view at a timestamp for reproducibility
1010
- A specific **version** of an answer
11-
12-
Pipeline (context): IDPC documents are associated to a **Case ID**, uploaded to Azure Blob
13-
Storage by a background Spring service, ingested, and then predefined queries/prompts are
14-
executed by the LLM with results stored in the DB.
1511
version: 0.0.0
1612
contact:
1713
@@ -281,7 +277,7 @@ paths:
281277
schema: { $ref: '#/components/schemas/ErrorResponse' }
282278

283279
# ---------------------------
284-
# Answers (UPDATED)
280+
# Answers
285281
# ---------------------------
286282
/answers/{caseId}/{queryId}:
287283
parameters:
@@ -611,6 +607,3 @@ components:
611607
type: string
612608
format: date-time
613609
description: UTC timestamp when the error was created.
614-
traceId:
615-
type: string
616-
description: Distributed trace id (from the current span) to help correlate logs/traces.

src/test/java/uk/gov/hmcts/cp/config/OpenAPIConfigurationLoaderTest.java

Lines changed: 0 additions & 97 deletions
This file was deleted.

src/test/java/uk/gov/hmcts/cp/openapi/codegen/GeneratedApiContractsExistTest.java

Lines changed: 0 additions & 111 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package uk.gov.hmcts.cp.openapi.model.cdk;
2+
3+
import io.swagger.v3.oas.models.OpenAPI;
4+
import io.swagger.v3.oas.models.info.Info;
5+
import io.swagger.v3.oas.models.media.Schema;
6+
import org.junit.jupiter.api.Test;
7+
import uk.gov.hmcts.cp.config.OpenAPIConfigurationLoader;
8+
9+
import java.util.Map;
10+
11+
import static org.assertj.core.api.Assertions.assertThat;
12+
13+
class GeneratedApiContractsExistTest {
14+
15+
@Test
16+
void openAPI_bean_should_have_expected_properties() {
17+
OpenAPI openAPI = new OpenAPIConfigurationLoader().openAPI();
18+
Info info = openAPI.getInfo();
19+
20+
String thisRepository = "api-cp-crime-caseadmin-case-document-knowledge";
21+
String expectedVersion = System.getProperty("API_SPEC_VERSION", "0.0.0");
22+
String expectedUrl = String.format("https://virtserver.swaggerhub.com/HMCTS-DTS/%s/%s", thisRepository, expectedVersion);
23+
assertThat(openAPI.getServers().get(0).getUrl()).isEqualTo(expectedUrl);
24+
25+
assertThat(info.getTitle()).isEqualTo("Case Documents AI Responses API");
26+
27+
assertThat(info.getDescription()).contains("Versioned");
28+
assertThat(info.getDescription()).contains("as-of");
29+
assertThat(info.getDescription()).contains("Case");
30+
31+
assertThat(info.getVersion()).isEqualTo(expectedVersion);
32+
33+
assertThat(info.getLicense().getName()).isEqualTo("MIT");
34+
assertThat(info.getLicense().getUrl()).isEqualTo("https://opensource.org/licenses/MIT");
35+
36+
assertThat(info.getContact().getEmail()).isEqualTo("[email protected]");
37+
}
38+
39+
@Test
40+
void answerResponse_schema_should_require_userQuery_and_createdAt() {
41+
OpenAPI openAPI = new OpenAPIConfigurationLoader().openAPI();
42+
Schema<?> answerResponseSchema = openAPI.getComponents().getSchemas().get("AnswerResponse");
43+
44+
Map<String, Schema> properties = answerResponseSchema.getProperties();
45+
assertThat(properties).containsKey("userQuery");
46+
assertThat(properties).containsKey("createdAt");
47+
48+
Schema<?> createdAtSchema = properties.get("createdAt");
49+
assertThat(createdAtSchema.getType()).isEqualTo("string");
50+
assertThat(createdAtSchema.getFormat()).isEqualTo("date-time");
51+
52+
assertThat(answerResponseSchema.getRequired()).contains("userQuery");
53+
assertThat(answerResponseSchema.getRequired()).contains("createdAt");
54+
}
55+
}

src/test/java/uk/gov/hmcts/cp/openapi/codegen/GeneratedModelContractsExistTest.java renamed to src/test/java/uk/gov/hmcts/cp/openapi/model/cdk/GeneratedModelContractsExistTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package uk.gov.hmcts.cp.openapi.codegen;
1+
package uk.gov.hmcts.cp.openapi.model.cdk;
22

33
import org.junit.jupiter.api.Test;
44

0 commit comments

Comments
 (0)