springwolf-core icon indicating copy to clipboard operation
springwolf-core copied to clipboard

Mismatch between Channel Message and Schema object name

Open jn-monster opened this issue 3 years ago • 1 comments

Bug description When a producer (possibly consumer as well - not tested) payload class is annotated by Swagger @Schema annotation with name the name is used in the schema definitions but in the channel payload message a class simple name is used and therefore there is a mismatch between those 2 which leads to invalid AsyncAPI definition.

See the details in the AsyncAPI result bellow (ExamplePayloadDto vs ExampleProducerPayload)

Dependencies and versions used springwolf-core version 0.7.0 swagger-annotations version 2.1.0

Code example Example Payload DTO:

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(name = "ExampleProducerPayload")
public class ExamplePayloadDto {
  private String someString;
  public String getSomeString() {
    return someString;
  }
  public void setSomeString(String someString) {
    this.someString = someString;
  }
}

AsyncApiDocket configuration:

@Bean
  public AsyncApiDocket asyncApiDocket() {
    Info info = Info.builder()
        .version("1.0.0")
        .title("Springwolf example project")
        .build();

    ProducerData exampleProducerData = ProducerData.builder()
        .channelName("example-producer-topic")
        .operationBinding(Map.of("pubsub", new KafkaOperationBinding()))
        .payloadType(ExamplePayloadDto.class)
        .build();

    return AsyncApiDocket.builder()
        .info(info)
        .producer(exampleProducerData)
        .build();
  }

AsyncAPI result

{
  "Springwolf example project": {
    "asyncapi": "2.0.0",
    "info": {
      "title": "Springwolf example project",
      "version": "1.0.0"
    },
    "servers": {},
    "channels": {
      "example-producer-topic": {
        "subscribe": {
          "bindings": {
            "pubsub": {}
          },
          "message": {
            "name": "com.example.springfoxexample.dto.ExamplePayloadDto",
            "title": "ExamplePayloadDto",
            "payload": {
              "$ref": "#/components/schemas/ExamplePayloadDto"
            }
          }
        }
      }
    },
    "components": {
      "schemas": {
        "ExampleProducerPayload": {
          "type": "object",
          "properties": {
            "someString": {
              "type": "string"
            }
          },
          "example": {
            "someString": "string"
          }
        }
      }
    }
  }
}

jn-monster avatar Oct 05 '22 09:10 jn-monster

Thanks for reporting this, will look into it in the next few days

stavshamir avatar Oct 08 '22 17:10 stavshamir

Fixed, will be available in next release (or see snapshot - current ui will not work with this version however)

stavshamir avatar Oct 15 '22 12:10 stavshamir