Skip to content

Instantly share code, notes, and snippets.

{
"@context": { "@vocab": "http://todosapp.com/api/vocab#" },
"@id": "http://todosapp.com/api/version_7/#self",
"@type": "http://todosapp.com/api/vocab#EntryPoint",
"users_url": { "@id": "http://todosapp.com/api/version_7/users#self" }
}
curl -X GET "http://todosapp.com/api/version_7/spec#EntryPoint
{
"@context": {
"hydra": "http://www.w3.org/ns/hydra/core#"
},
"@id": "http://todosapp.com/api/vocab#self",
"@type": "hydra:ApiDocumentation",
"hydra:entryPoint": { "@id":"http://todosapp.com/api/version_7/#self" },
"hydra:supportedClass": [
{
(ns api-modelling-framework.parser.domain.common-test
#?(:cljs (:require-macros [cljs.test :refer [deftest is async]]))
(:require #?(:clj [clojure.test :refer :all])
[api-modelling-framework.parser.domain.common :as common]
[api-modelling-framework.model.document :as document]
[api-modelling-framework.model.vocabulary :as v]
[api-modelling-framework.utils :as utils]))
(deftest wrapped-ast-token?-test
(defn apply-template [uri parameters {:keys [result]}]
(reduce (fn [acc {:keys [name property]}]
(let [value (get result property)
value (or (get value "@value") (get value "@id"))]
(if (nil? value)
(throw (Exception. (str "Missing parameter " name " for template " uri)))
(string/replace uri (str "{" name "}") (str value)))))
uri
parameters))
(defn apply-template [uri parameters {:keys [result]}]
(reduce (fn [acc {:keys [name property]}]
(let [value (get result property)
value (or (get value "@value") (get value "@id"))]
(if (nil? value)
(throw (Exception. (str "Missing parameter " name " for template " uri)))
(string/replace uri (str "{" name "}") (str value)))))
uri
parameters))
(deftest error-1
(let [input {"Foo" {:properties {:id "string"}}
"Foos" "Foo[]"}
expanded (expanded-form "Foos" input)
canonical (canonical-form expanded)]
(is (= canonical
{:type "array",
:items
{:properties {"id" {:type "string", :required true}},
:additionalProperties true,
{
"@id": "http://localhost:4567/customers/$ID",
"payload:email": "?email",
"payload:account_owner": {
"payload:amount": "?amount"
},
"payload:reports": {
"payload:provider": "?provider",
"payload:score": "?score"
},
{
"raml-http:path": "?path",
"hydra:supportedOperation":
{
"hydra:method": "?method",
"hydra:returns": {
"hydra:statusCode": "200"
}
}
}