~jomco/ring-openapi-validator

bd0a061ec473c519d36a44673391c1c74167c013 — Joost Diepenmaat 3 years ago 992e852
Allow supplying the specification as string
M src/nl/zeekat/ring_openapi_validator.clj => src/nl/zeekat/ring_openapi_validator.clj +6 -2
@@ 132,11 132,15 @@

  `opts` is an optional map of options:
   - `:base-path` overrides the base path in the spec.
   - `:inline? true` indicate that `spec` is the specification body
      as a string, instead of a url or path

  If you need to customize the validator you can create a builder using
  `com.atlassian.oai.validator.OpenApiInteractionValidator/createFor`"
  ([spec {:keys [base-path] :as opts}]
   (cond-> (OpenApiInteractionValidator/createFor spec)
  ([spec {:keys [base-path inline?] :as opts}]
   (cond-> (if inline?
             (OpenApiInteractionValidator/createForInlineApiSpecification spec)
             (OpenApiInteractionValidator/createFor spec))
     base-path
     (.withBasePathOverride base-path)
     true

M test/nl/zeekat/ring_openapi_validator_test.clj => test/nl/zeekat/ring_openapi_validator_test.clj +7 -2
@@ 1,7 1,8 @@
(ns nl.zeekat.ring-openapi-validator-test
  (:require [nl.zeekat.ring-openapi-validator :as validator]
  (:require [clojure.data.json :as json]
            [clojure.java.io :as io]
            [clojure.test :refer [deftest testing is]]
            [clojure.data.json :as json]))
            [nl.zeekat.ring-openapi-validator :as validator]))

(def ooapi-content-type "application/hal+json; charset=utf-8")



@@ 60,3 61,7 @@
      (is (= "validation.response.body.schema.required"
             (get-in (validator/validate-response validator :get "/" ooapi-invalid-response) [0 :key]))
          "Report on invalid request"))))

(deftest test-inline-validator
  (is (instance? com.atlassian.oai.validator.OpenApiInteractionValidator
                 (validator/openapi-validator (slurp (io/resource "ooapi.json")) {:inline? true}))))