Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): handle nullable schema in NamedSchemaObject #794

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 @@ -105,7 +105,7 @@ protected MessageObject buildMessage(AsyncOperation operationData, Method method
.build());

String description = operationData.message().description();
if (!StringUtils.hasText(description)) {
if (!StringUtils.hasText(description) && payloadSchema.schema() != null) {
description = payloadSchema.schema().getDescription();
}
if (StringUtils.hasText(description)) {
Expand All @@ -116,7 +116,7 @@ protected MessageObject buildMessage(AsyncOperation operationData, Method method
var builder = MessageObject.builder()
.messageId(payloadSchema.name())
.name(payloadSchema.name())
.title(payloadSchema.schema().getTitle())
.title(payloadSchema.title())
.description(description)
.payload(messagePayload)
.headers(MessageHeaders.of(MessageReference.toSchema(headerSchemaName)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected MessageObject buildMessage(ClassAnnotation classAnnotation, NamedSchem
MessageObject message = MessageObject.builder()
.messageId(payloadSchema.name())
.name(payloadSchema.name())
.title(payloadSchema.schema().getTitle())
.title(payloadSchema.title())
.description(null)
.payload(payload)
.headers(MessageHeaders.of(MessageReference.toSchema(headerSchemaName)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected MessageObject buildMessage(MethodAnnotation annotation, NamedSchemaObj
MessageObject message = MessageObject.builder()
.messageId(payloadSchema.name())
.name(payloadSchema.name())
.title(payloadSchema.schema().getTitle())
.title(payloadSchema.title())
.description(null)
.payload(payload)
.headers(MessageHeaders.of(MessageReference.toSchema(headerModelName)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
package io.github.springwolf.core.asyncapi.scanners.common.payload;

import io.github.springwolf.asyncapi.v3.model.schema.SchemaObject;
import jakarta.annotation.Nullable;

/**
* Encapsulates the resolved name for the contained schema.
* @param name The fully qualified name or the simple name of the schema.
* @param schema The SchemaObject.
*/
public record NamedSchemaObject(String name, SchemaObject schema) {}
public record NamedSchemaObject(String name, @Nullable SchemaObject schema) {
public String title() {
return schema != null ? schema.getTitle() : name();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ public String extractSchemaForName(Class<?> payloadType) {
}

private NamedSchemaObject useUnusedPayload() {
this.componentsService.registerSchema(PAYLOAD_NOT_USED.schema());
SchemaObject schema = PAYLOAD_NOT_USED.schema();
if (schema != null) {
this.componentsService.registerSchema(schema);
}

return PAYLOAD_NOT_USED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
public class AsyncHeadersForKafkaBuilder implements AsyncHeadersBuilder {
@Override
public SchemaObject buildHeaders(NamedSchemaObject payloadSchema) {
return new AsyncHeadersForSpringKafkaBuilder(
"SpringKafkaDefaultHeaders-" + payloadSchema.schema().getTitle())
return new AsyncHeadersForSpringKafkaBuilder("SpringKafkaDefaultHeaders-" + payloadSchema.title())
.withTypeIdHeader(payloadSchema.name())
.build();
}
Expand Down