Liking cljdoc? Tell your friends :D

s-exp.legba

Builds ring handlers and middlewares validating requests and responses against an OpenAPI 3.1 schema, routing requests to the matching handler

Builds ring handlers and middlewares validating requests and responses
against an OpenAPI 3.1 schema, routing requests to the matching handler
raw docstring

default-optionsclj

Default options used by openapi-handler

Default options used by openapi-handler
raw docstring

ensure-route-coverage!clj

(ensure-route-coverage! routes schema)

Checks that a map of openapi-handlers covers all paths defined by the schema

Checks that a map of openapi-handlers covers all paths defined by the schema
raw docstring

handlersclj

(handlers routes schema-src & {:as opts})

From a map of [method path] -> ring handler returns a map of [method path] -> openapi-wrapped-handler.

Options:

  • :key-fn - Control map keys decoding when turning jackson JsonNodes to clj data for the handler - default to keyword

  • :query-string-params-key - where to find the decoded query-string parameters - defaults to :query-params

  • :read-request-json-body - when true (default), json request bodies are decoded to clj data for the handler, otherwise the handler receives them as an InputStream

  • :write-response-json-body - when true (default), collection response bodies with a json content-type are encoded to JSON strings

  • :validation-result - function that controls how to turn com.networknt.schema.ValidationResult into a clj -> json response. Defaults to s-exp.legba.openapi-schema/validation-result

  • :include-schema: - adds the path-relevant schema portion to the request-map under :s-exp.legba/schema (false by default)

  • :validate-response - function of response, schema, sub-schema and opts returning the response to send. Defaults to a function returning the response unvalidated, s-exp.legba.response/validate validates the response and throws on invalid responses

From a map of [method path] -> ring handler returns a map of [method path] ->
openapi-wrapped-handler.

Options:

* `:key-fn` - Control map keys decoding when turning jackson JsonNodes to clj
  data for the handler - default to `keyword`

* `:query-string-params-key` - where to find the decoded query-string
   parameters - defaults to `:query-params`

* `:read-request-json-body` - when true (default), json request bodies are
decoded to clj data for the handler, otherwise the handler receives them as an
InputStream

* `:write-response-json-body` - when true (default), collection response
bodies with a json content-type are encoded to JSON strings

* `:validation-result` - function that controls how to turn
`com.networknt.schema.ValidationResult` into a clj -> json response. Defaults
to `s-exp.legba.openapi-schema/validation-result`

* `:include-schema`: - adds the path-relevant schema portion to the
request-map under `:s-exp.legba/schema` (`false` by default)

* `:validate-response` - function of `response`, `schema`, `sub-schema` and
`opts` returning the response to send. Defaults to a function returning the
response unvalidated, `s-exp.legba.response/validate` validates the response
and throws on invalid responses
raw docstring

middlewaresclj

(middlewares schema-src & {:as opts})

From a sequence of [method path] tuples returns a map of [method path] -> openapi validation middlewares.

Options:

  • :key-fn - Control map keys decoding when turning jackson JsonNodes to clj data for the handler - default to keyword

  • :query-string-params-key - where to find the decoded query-string parameters - defaults to :query-params

  • :read-request-json-body - when true (default), json request bodies are decoded to clj data for the handler, otherwise the handler receives them as an InputStream

  • :write-response-json-body - when true (default), collection response bodies with a json content-type are encoded to JSON strings

  • :validation-result - function that controls how to turn com.networknt.schema.ValidationResult into a clj -> json response. Defaults to s-exp.legba.openapi-schema/validation-result

  • :include-schema: - adds the path-relevant schema portion to the request-map under :s-exp.legba/schema (false by default)

  • :schema-src-type - :path (default) to load from a URI/path via read-schema, or :string to load from a raw JSON/YAML string via read-schema-str

  • :validate-response - function of response, schema, sub-schema and opts returning the response to send. Defaults to a function returning the response unvalidated, s-exp.legba.response/validate validates the response and throws on invalid responses

From a sequence of [method path] tuples returns a map of [method path] ->
openapi validation middlewares.

Options:

* `:key-fn` - Control map keys decoding when turning jackson JsonNodes to clj
  data for the handler - default to `keyword`

* `:query-string-params-key` - where to find the decoded query-string
   parameters - defaults to `:query-params`

* `:read-request-json-body` - when true (default), json request bodies are
decoded to clj data for the handler, otherwise the handler receives them as an
InputStream

* `:write-response-json-body` - when true (default), collection response
bodies with a json content-type are encoded to JSON strings

* `:validation-result` - function that controls how to turn
`com.networknt.schema.ValidationResult` into a clj -> json response. Defaults
to `s-exp.legba.openapi-schema/validation-result`

* `:include-schema`: - adds the path-relevant schema portion to the
request-map under `:s-exp.legba/schema` (`false` by default)

* `:schema-src-type` - `:path` (default) to load from a URI/path via
`read-schema`, or `:string` to load from a raw JSON/YAML string via
`read-schema-str`

* `:validate-response` - function of `response`, `schema`, `sub-schema` and
`opts` returning the response to send. Defaults to a function returning the
response unvalidated, `s-exp.legba.response/validate` validates the response
and throws on invalid responses
raw docstring

routing-handlerclj

(routing-handler routes schema-src & {:as opts})

Same as routing-handler* but wraps with s-exp.legba.middleware/wrap-error-response middleware turning exceptions into nicely formatted error responses

Same as `routing-handler*` but wraps with
`s-exp.legba.middleware/wrap-error-response` middleware turning exceptions
into nicely formatted error responses
raw docstring

routing-handler*clj

(routing-handler* routes schema-src & {:as opts})

Takes a map of routes as [method path] -> ring-handler, turns them into a map of routes to openapi handlers then creates a handler that will dispatch on the appropriate openapi handler from a potential router match. If no match is found, returns not-found-response.

Options:

  • :not-found-response - defaults to {:status 404 :body " Not found "}

  • :key-fn - Control map keys decoding when turning jackson JsonNodes to clj data for the handler - default to keyword

  • :query-string-params-key - where to find the decoded query-string parameters - defaults to :query-params

  • :read-request-json-body - when true (default), json request bodies are decoded to clj data for the handler, otherwise the handler receives them as an InputStream

  • :write-response-json-body - when true (default), collection response bodies with a json content-type are encoded to JSON strings

  • :validation-result - function that controls how to turn com.networknt.schema.ValidationResult into a clj -> json response. Defaults to s-exp.legba.openapi-schema/validation-result

  • :extra-routes - extra routes to be passed to the underlying router

  • :validate-response - function of response, schema, sub-schema and opts returning the response to send. Defaults to a function returning the response unvalidated, s-exp.legba.response/validate validates the response and throws on invalid responses

Takes a map of routes as [method path] -> ring-handler, turns them into a map
of routes to openapi handlers then creates a handler that will dispatch on the
appropriate openapi handler from a potential router match. If no match is
found, returns `not-found-response`.

Options:

* `:not-found-response` - defaults to `{:status 404 :body " Not found "}`

* `:key-fn` - Control map keys decoding when turning jackson JsonNodes to clj
  data for the handler - default to `keyword`

* `:query-string-params-key` - where to find the decoded query-string
   parameters - defaults to `:query-params`

* `:read-request-json-body` - when true (default), json request bodies are
decoded to clj data for the handler, otherwise the handler receives them as an
InputStream

* `:write-response-json-body` - when true (default), collection response
bodies with a json content-type are encoded to JSON strings

* `:validation-result` - function that controls how to turn
  `com.networknt.schema.ValidationResult` into a clj -> json response. Defaults
  to `s-exp.legba.openapi-schema/validation-result`

* `:extra-routes` - extra routes to be passed to the underlying router

* `:validate-response` - function of `response`, `schema`, `sub-schema` and
`opts` returning the response to send. Defaults to a function returning the
response unvalidated, `s-exp.legba.response/validate` validates the response
and throws on invalid responses
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close