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

[BUG] OpenAPI callbacks on operations doesn't match spec #2095

Closed
seglo opened this issue Apr 29, 2022 · 0 comments · Fixed by #2098
Closed

[BUG] OpenAPI callbacks on operations doesn't match spec #2095

seglo opened this issue Apr 29, 2022 · 0 comments · Fixed by #2098
Milestone

Comments

@seglo
Copy link
Contributor

seglo commented Apr 29, 2022

Tapir version: 1.0.0-M5

Scala version: 2.12.12

Describe the bug

In tapir's Open API object model there's support to add callbacks to Operations and Components. Both models have an addComponents helper that accepts a Callback. When I define a Callback and render the docs as YAML I'll get something like the following:

openapi: 3.0.3
...
paths:
  /my_endpoint:
    post:
      ...
      callbacks:
        myCallback:
          pathItems:
            /my_callback:
              put:
                ...

But based on the OpenAPI spec for callbacks the pathItems level isn't valid. If I omit this I get the expected result and I can render callbacks correctly with the tapir redoc library.

paths:
  /my_endpoint:
    post:
      ...
      callbacks:
        myCallback:
          /my_callback:
            put:
                ...

How to reproduce?

I have some hacky code that uses a "callback" endpoint that I defined with the endpoint DSL in the Callback added to an existing endpoint operation my_endpoint:

  def customizeDocs(docs: OpenAPI): OpenAPI = {
    import com.softwaremill.quicklens._
    val callback = Callback(ListMap("/my_callback" -> docs.paths.pathItems("/my_callback")))
    docs
      .modify(_.paths.pathItems.at("/my_endpoint").post.each).using(_.addCallback("myCallback", callback))
  }

I think the issue might be with the context of where a Callback is added. Callback accepts a list of map of PathItem, but the pathItem stanza is rendered into the API docs when it shouldn't.

I could probably PR a fix, but I'm hesitant because I don't know why Callback is the way it is and I don't want to introduce a regression for anyone.

@adamw adamw added this to the 1.0.0 milestone May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants