Skip to content

martian.schema/lookup-ref does not decode slash in JSON Pointer #217

@gandalfthegraydelson

Description

@gandalfthegraydelson

Would like to first say that I love the library, great work.

I am generating an OpenAPI spec using reitit and malli.

One of the specs I am using is :time/local-date.

When it is referred to in a schema, it has "$ref": "#/components/schemas/time~1local-date", where the slash is encoded as ~1.

When I call martian-http/bootstrap-openapi, it fails with

clojure.lang.ExceptionInfo: Cannot find reference {:reference "#/components/schemas/time~1local-date"} (schema.cljc:89)

I have been using the following workaround in Martian in order to get this to work. The only difference is that I am calling decode-ref after splitting by slash.

(defn decode-ref [s] (string/replace s "~1" "/"))

(defn lookup-ref
  "Patch of `martian.schema/lookup-ref`. Calls `decode-ref` to convert ~1 to /"
  [ref ref-lookup]
  (if (string/starts-with? ref "#/")
    (or (get-in ref-lookup (drop 1 (map (comp keyword decode-ref) (string/split ref #"/"))))
        (throw (ex-info "Cannot find reference"
                        {:reference ref})))
    (throw (ex-info "Non-local references are not supported yet. References should start ref with '#/'"
                    {:reference ref}))))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions