oliyh / martian

The HTTP abstraction library for Clojure/script, supporting OpenAPI, Swagger, Schema, re-frame and more
MIT License
525 stars 42 forks source link

Support OpenAPI 3 servers specification #121

Open kiranshila opened 2 years ago

kiranshila commented 2 years ago

I am pretty new to swagger/openapi in general so please bear with me if this is already solved - I couldn't quite tell if it was the case. I am trying to use this library with Radarr's OpenAPI and am having some problems. Their API is OpenAPI 3, specifically with a servers section as such:

  "servers": [
    {
      "url": "{protocol}://{hostPath}/api/v3",
      "variables": {
        "protocol": {
          "enum": ["https", "http"],
          "default": "https"
        },
        "hostPath": {
          "default": "localhost:7878",
          "description": "Your Radarr Server URL"
        }
      }
    }
  ],

However, trying martian/url-for on one of the endpoints, say :get-movie results in the peculiar URL https://raw.githubusercontent.com{protocol}://{hostPath}/api/v3/movie

Any help would be appreciated as to how to use the servers section of the api with this library. Fantastic work on this, by the way, this library is quite wonderful!

kiranshila commented 2 years ago

Also, I am bootstrapping with

(def radarr-api
 (martian-http/bootstrap-openapi "https://raw.githubusercontent.com/Radarr/Radarr/develop/src/Radarr.Api.V3/swagger.json"))
oliyh commented 2 years ago

Hi,

This is not currently supported in Martian. It probably could be without too much trouble. I'll have to do some reading on what that section means, but probably a first pass to just use the defaults would at least get you able to use it.

Thanks for reporting.

oliyh commented 2 years ago

Hi,

In #129 support was added for an option :server-url in the options when you call bootstrap-openapi. You could change to this as a workaround:

(def radarr-api
 (martian-http/bootstrap-openapi 
    "https://raw.githubusercontent.com/Radarr/Radarr/develop/src/Radarr.Api.V3/swagger.json"
    {:server-url "https://localhost:7878/api/v3"}))

This is available in the latest snapshot 0.1.21-SNAPSHOT

arichiardi commented 1 year ago

A question, I have been eyeing this project for loading our OpenAPI 3 spec, is it, in general, supported by martian?

oliyh commented 1 year ago

Hi @arichiardi ,

The OpenAPI spec is in general supported by martian, this was added in #90 and #91 with various extra bits added since. This issue in particular is still unaddressed and there are likely other small parts that are not supported but you should find that core functionality is all there.

If you find something missing, issues and PRs are welcome as always.

Cheers

damesek commented 9 months ago

Please add to Readme this :server-url option. :) It took me a long time to find this here..