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] Can't generate swagger with var references #669

Closed
bsless opened this issue Apr 4, 2024 · 2 comments · Fixed by #673
Closed

[Bug] Can't generate swagger with var references #669

bsless opened this issue Apr 4, 2024 · 2 comments · Fixed by #673

Comments

@bsless
Copy link
Contributor

bsless commented Apr 4, 2024

I encountered two different problems when schemas use var refs - no schema for GET and bad resolution for POST

Steps to reproduce:

Go to examples/ring-malli-swagger

Explicitly bump reitit to 15:

[metosin/malli "0.15.0"]

Add

(def X :int)
(def Y :int)
(def Plus [:map
           [:x
            {:title "X parameter"
             :description "Description for X parameter"
             :json-schema/default 42}
            #'X]
           [:y #'Y]])

Change parameters in get and post to use schema reference:

:parameters {:query #'Plus}

Start server and navigate to openapi page

Get error:

Resolver error at requestBody.content.application/json.schema.$ref
Could not resolve reference: JSON Pointer evaluation failed while evaluating token "definitions" against an ObjectElement
Resolver error at requestBody.content.application/json.schema.$ref
Could not resolve reference: JSON Pointer evaluation failed while evaluating token "definitions" against an ObjectElement

Observe the generated openapi.json

  • No parameters for GET /math/plus at all
  • Ref for POST /math/plus is dangling: "#/definitions/example.server~1Plus"

See schema opbject:

{
  "$ref": "#/definitions/example.server~1Plus",
  "definitions": {
    "example.server/Plus": {
      "type": "object",
      "properties": {
        "x": {
          "title": "X parameter",
          "description": "Description for X parameter",
          "$ref": "#/definitions/example.server~1X",
          "default": 42
        },
        "y": {
          "$ref": "#/definitions/example.server~1Y"
        }
      },
      "required": [
        "x",
        "y"
      ]
    },
    "example.server/X": {
      "type": "integer"
    },
    "example.server/Y": {
      "type": "integer"
    }
  }
}
@opqdonut
Copy link
Member

This is interesting! I started testing and thought reitit + malli vars is completely broken, but it seems to actually mostly works. I'll try to narrow down what exactly goes wrong in the example.

@opqdonut
Copy link
Member

opqdonut commented Apr 19, 2024

Ok, so the example ring-malli-swagger is broken in two three ways (when edited to use var references).

  1. The openapi doc is invalid and has the reference errors you pasted. This is probably related to
  2. The swagger doc generation fails (HTTP 500). I have a fix for this: fix: remove unsupported coercions when generating swagger #671
  3. The swagger doc is missing the GET parameters. This is fixed by Inline refs in non-:body swagger parameters malli#1044

opqdonut added a commit that referenced this issue Apr 19, 2024
If we don't remove them, :responses :content gets passed out verbatim
in the swagger.json, breaking stuff.

In particular, fixes the swagger.json in
examples/reitit-malli-swagger. Reported broken in #669.
opqdonut added a commit that referenced this issue Apr 19, 2024
If we don't remove them, :responses :content gets passed out verbatim
in the swagger.json, breaking stuff.

In particular, fixes the swagger.json in
examples/reitit-malli-swagger. Reported broken in #669.
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