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
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.parser.OpenAPIV3Parser;
import io.swagger.v3.parser.core.models.SwaggerParseResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;

@Slf4j
public final class OpenAPIConfigurationLoader {

private static final Logger LOG = LoggerFactory.getLogger(OpenAPIConfigurationLoader.class);

// Match your Gradle include("*.openapi.yml")
private static final String SPEC_PATH = "openapi/case-admin-doc-knowledge-api.openapi.yml";

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

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

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

SwaggerParseResult result = new OpenAPIV3Parser().readContents(yaml, null, null);
final SwaggerParseResult result = new OpenAPIV3Parser().readContents(yaml, null, null);
if (result == null || result.getOpenAPI() == null) {
String messages = (result != null && result.getMessages() != null)
final String messages = (result != null && result.getMessages() != null)
? String.join("; ", result.getMessages())
: "Unknown parser error";
LOG.error("Failed to parse OpenAPI spec at {}: {}", path, messages);
log.error("Failed to parse OpenAPI spec at {}: {}", path, messages);
throw new IllegalStateException("Failed to parse OpenAPI spec at " + path + ": " + messages);
}

Expand All @@ -53,7 +51,9 @@ public static OpenAPI loadOpenApiFromClasspath(final String path) {
}
}

/** Convenience accessor using the default SPEC_PATH. */
/**
* Convenience accessor using the default SPEC_PATH.
*/
public OpenAPI openAPI() {
return loadOpenApiFromClasspath(SPEC_PATH);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ info:
- The latest snapshot for a Case
- An **as-of** view at a timestamp for reproducibility
- A specific **version** of an answer

Pipeline (context): IDPC documents are associated to a **Case ID**, uploaded to Azure Blob
Storage by a background Spring service, ingested, and then predefined queries/prompts are
executed by the LLM with results stored in the DB.
version: 0.0.0
contact:
email: [email protected]
Expand Down Expand Up @@ -281,7 +277,7 @@ paths:
schema: { $ref: '#/components/schemas/ErrorResponse' }

# ---------------------------
# Answers (UPDATED)
# Answers
# ---------------------------
/answers/{caseId}/{queryId}:
parameters:
Expand Down Expand Up @@ -611,6 +607,3 @@ components:
type: string
format: date-time
description: UTC timestamp when the error was created.
traceId:
type: string
description: Distributed trace id (from the current span) to help correlate logs/traces.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package uk.gov.hmcts.cp.openapi.model.cdk;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.media.Schema;
import org.junit.jupiter.api.Test;
import uk.gov.hmcts.cp.config.OpenAPIConfigurationLoader;

import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;

class GeneratedApiContractsExistTest {

@Test
void openAPI_bean_should_have_expected_properties() {
OpenAPI openAPI = new OpenAPIConfigurationLoader().openAPI();
Info info = openAPI.getInfo();

String thisRepository = "api-cp-crime-caseadmin-case-document-knowledge";
String expectedVersion = System.getProperty("API_SPEC_VERSION", "0.0.0");
String expectedUrl = String.format("https://virtserver.swaggerhub.com/HMCTS-DTS/%s/%s", thisRepository, expectedVersion);
assertThat(openAPI.getServers().get(0).getUrl()).isEqualTo(expectedUrl);

assertThat(info.getTitle()).isEqualTo("Case Documents AI Responses API");

assertThat(info.getDescription()).contains("Versioned");
assertThat(info.getDescription()).contains("as-of");
assertThat(info.getDescription()).contains("Case");

assertThat(info.getVersion()).isEqualTo(expectedVersion);

assertThat(info.getLicense().getName()).isEqualTo("MIT");
assertThat(info.getLicense().getUrl()).isEqualTo("https://opensource.org/licenses/MIT");

assertThat(info.getContact().getEmail()).isEqualTo("[email protected]");
}

@Test
void answerResponse_schema_should_require_userQuery_and_createdAt() {
OpenAPI openAPI = new OpenAPIConfigurationLoader().openAPI();
Schema<?> answerResponseSchema = openAPI.getComponents().getSchemas().get("AnswerResponse");

Map<String, Schema> properties = answerResponseSchema.getProperties();
assertThat(properties).containsKey("userQuery");
assertThat(properties).containsKey("createdAt");

Schema<?> createdAtSchema = properties.get("createdAt");
assertThat(createdAtSchema.getType()).isEqualTo("string");
assertThat(createdAtSchema.getFormat()).isEqualTo("date-time");

assertThat(answerResponseSchema.getRequired()).contains("userQuery");
assertThat(answerResponseSchema.getRequired()).contains("createdAt");
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package uk.gov.hmcts.cp.openapi.codegen;
package uk.gov.hmcts.cp.openapi.model.cdk;

import org.junit.jupiter.api.Test;

Expand Down
Loading
Loading