Skip to content

Commit 22329f7

Browse files
openapi: add explanatory comments on the three OpenApiSpecGenerator fixes
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b25539e commit 22329f7

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ public OpenApiSpecGenerator(ConfigurationContext configContext, OpenApiConfigura
9999
this.configuration = config != null ? config : new OpenApiConfiguration();
100100
this.serviceIntrospector = new ServiceIntrospector(configContext);
101101

102-
// Configure Jackson for OpenAPI model serialization with HTTP/2 optimization metrics
102+
// Configure Jackson for OpenAPI model serialization with HTTP/2 optimization metrics.
103+
// Fix: NON_NULL inclusion is required because the Swagger model POJOs (Info, Contact,
104+
// License, Schema, etc.) declare many optional fields that default to null. Without this,
105+
// Jackson serializes every null field as "key": null, inflating a simple 3-service spec
106+
// by ~300 null entries and producing invalid Swagger UI display artifacts.
103107
this.objectMapper = new ObjectMapper();
104108
this.objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
105109
this.objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
@@ -108,7 +112,11 @@ public OpenApiSpecGenerator(ConfigurationContext configContext, OpenApiConfigura
108112
this.objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
109113
}
110114

111-
// Configure YAML mapper (same settings, different factory)
115+
// Fix: generateOpenApiYaml() was returning JSON because it delegated to
116+
// generateOpenApiJson(). A second ObjectMapper backed by YAMLFactory produces
117+
// proper YAML. WRITE_DOC_START_MARKER is disabled to suppress the "---" header
118+
// that confuses some YAML parsers. jackson-dataformat-yaml is already on the
119+
// classpath transitively from io.swagger.core.v3:swagger-core.
112120
YAMLFactory yamlFactory = YAMLFactory.builder()
113121
.disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER)
114122
.build();
@@ -381,7 +389,11 @@ private Operation generateOperation(AxisService service, AxisOperation axisOpera
381389
tags.add(service.getName());
382390
operation.setTags(tags);
383391

384-
// Add request body (all JSON-RPC services accept a JSON POST body)
392+
// Fix: requestBody was null on every generated operation. All services registered
393+
// here use JsonRpcMessageReceiver and expect a JSON POST body. Axis2 services have
394+
// no JAX-RS annotations or WSDL parameter metadata that would let us introspect
395+
// field-level schemas, so the body is typed as a generic "object" — sufficient for
396+
// Swagger UI to render a Try-It-Out editor and for clients to know a body is required.
385397
RequestBody requestBody = new RequestBody();
386398
requestBody.setRequired(true);
387399
requestBody.setDescription("JSON request body for " + axisOperation.getName().getLocalPart());

0 commit comments

Comments
 (0)