softwaremill / sttp-apispec

OpenAPI, AsyncAPI and JSON Schema Scala models.
Apache License 2.0
23 stars 11 forks source link

Non-empty sttp.apispec.asyncapi.Message.examples or MessageTrait.examples yields invalid specification #174

Closed zorba128 closed 1 month ago

zorba128 commented 1 month ago

Adding example to either Message or MessageTrait produces invalid specification.

Generated specs:

 messages:
    WsRequest:
      payload:
        $ref: '#/components/schemas/WsRequest'
      contentType: application/json
      examples:
      - payload:
        - wsTag: 1
          channel: notifications
          requestType: Subscribe
      - payload:
        - wsTag: 2
          channel: notifications
          requestType: Unsubscribe

And should be:

 messages:
    WsRequest:
      payload:
        $ref: '#/components/schemas/WsRequest'
      contentType: application/json
      examples:
      - payload:
          wsTag: 1
          channel: notifications
          requestType: Subscribe
      - payload:
          wsTag: 2
          channel: notifications
          requestType: Unsubscribe

Original,broken definition is following:

case class SingleMessage(..., examples: List[Map[String, List[ExampleValue]]] = Nil, ...) extends Message

It should be either simplified to:

case class SingleMessage(..., examples: List[ListMap[String, ExampleValue]] = Nil, ...) extends Message

or simply to follow specification asyncapi spec, MessageExampleObject section. This would also make example name/description support better (now only payload is used).

// TODO: headers, extensions
case class MessageExample(payload: ExampleValue, name: Option[String], summary: Option[String])
case class SingleMessage(..., examples: List[MessageExample], ...) extends Message

See PR https://github.com/softwaremill/sttp-apispec/pull/175

adamw commented 1 month ago

Thanks for working on this :)

zorba128 commented 1 month ago

Actually this one, plus some minor updates on tapir side would fix issue with examples - but I have no idea how to proceed as both will be breaking changes.

adamw commented 1 month ago

It's a 0.x version, so breaking changes are fine, mima is there so that we know when to bump the minor version (vs. patch)

zorba128 commented 1 month ago

It seems PR works fine - generated spec worked fine in AsyncAPI Studio: image

adamw commented 1 month ago

Released in 0.11.0