~jomco/ring-openapi-validator

9a43e1d44da67b2ed3f2dd70dbb28d96e1d5a206 — Joost Diepenmaat 2 years ago 816790c
Add option to ignore additional properties when validating
1 files changed, 9 insertions(+), 1 deletions(-)

M src/nl/jomco/ring_openapi_validator.clj
M src/nl/jomco/ring_openapi_validator.clj => src/nl/jomco/ring_openapi_validator.clj +9 -1
@@ 6,6 6,7 @@
           com.atlassian.oai.validator.model.Response
           com.atlassian.oai.validator.report.ValidationReport$Level
           com.atlassian.oai.validator.report.ValidationReport$MessageContext$Location
           com.atlassian.oai.validator.report.LevelResolverFactory
           java.util.Optional))

(def ^:private ring->Method


@@ 115,15 116,22 @@
   - `: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
   - `:ignore-additional-properties? true` will disable errors on
      additional properties. This can help if you use `allOf` schemas. See also
      https://bitbucket.org/atlassian/swagger-request-validator/src/master/docs/FAQ.md

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

     ignore-additional-properties?
     (.withLevelResolver (LevelResolverFactory/withAdditionalPropertiesIgnored))

     true
     (.build)))
  ([spec]