Skip to content

Commit 916cd85

Browse files
openapi: address Gemini review findings (items 3-5)
- Sanitize operation name defensively in requestBody description: replaceAll non-word/non-safe chars to '_'; Axis2 NCNames are already safe but guards against malformed deployment descriptors (item 3) - Replace fragile jsonSpec.length() > 3000 size assertion with content-key checks ("openapi", "paths") in Http2OpenApiBasicTest (item 4) - Add visible SKIPPED warning instead of silent return when financial-api-schema.json is absent from classpath (item 5) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2e786f6 commit 916cd85

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

modules/openapi/src/main/java/org/apache/axis2/openapi/OpenApiSpecGenerator.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,11 @@ private Operation generateOperation(AxisService service, AxisOperation axisOpera
422422
// Swagger UI to render a Try-It-Out editor and for clients to know a body is required.
423423
RequestBody requestBody = new RequestBody();
424424
requestBody.setRequired(true);
425-
requestBody.setDescription("JSON request body for " + axisOperation.getName().getLocalPart());
425+
// Sanitize operation name: Axis2 QName local parts follow XML NCName rules and
426+
// cannot contain angle brackets or control characters, but sanitize defensively
427+
// in case a malformed deployment descriptor produces unexpected characters.
428+
String safeOpName = axisOperation.getName().getLocalPart().replaceAll("[^\\w.\\-]", "_");
429+
requestBody.setDescription("JSON request body for " + safeOpName);
426430
Content requestContent = new Content();
427431
MediaType requestMediaType = new MediaType();
428432
Schema requestSchema = new Schema();

modules/openapi/src/test/java/org/apache/axis2/openapi/Http2OpenApiBasicTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ public void testLargeServiceCatalogDocumentation() throws Exception {
160160
// Validate large catalog handling
161161
assertNotNull("Should generate large OpenAPI spec", openApi);
162162
assertTrue("Should document many services", openApi.getPaths().size() >= 20);
163-
assertTrue("Should generate substantial JSON", jsonSpec.length() > 3000); // >3KB (nulls no longer inflating output)
163+
// Assert on content rather than byte count — size is fragile across platforms/JVM versions
164+
assertTrue("JSON spec must contain openapi version key", jsonSpec.contains("\"openapi\""));
165+
assertTrue("JSON spec must contain paths key", jsonSpec.contains("\"paths\""));
164166

165167
// Performance validation
166168
assertTrue("Spec generation should be efficient", specTime < 2000);

modules/openapi/src/test/java/org/apache/axis2/openapi/OpenApiSpecGeneratorTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,11 @@ public void testFinancialApiSchemaAdvancedFeatures() throws Exception {
481481
java.io.File schemaFile = new java.io.File(
482482
"../../samples/swagger-server/src/main/resources/openapi/financial-api-schema.json");
483483
if (!schemaFile.exists()) {
484-
// Skip gracefully when running outside the full repo checkout
484+
// File lives in the swagger-server module; skip with a visible warning
485+
// when this test runs outside the full multi-module checkout.
486+
System.out.println("SKIPPED testFinancialApiSchemaAdvancedFeatures: " +
487+
"financial-api-schema.json not found at " + schemaFile.getAbsolutePath() +
488+
" — run from the repo root to include this assertion.");
485489
return;
486490
}
487491
is = new java.io.FileInputStream(schemaFile);

0 commit comments

Comments
 (0)