All Projects → cxxxr → apispec

cxxxr / apispec

Licence: other
A Common Lisp library for handling Web API requests and responses.

Programming Languages

common lisp
692 projects
NewLisp
63 projects

Projects that are alternatives of or similar to apispec

openapi-lint-vscode
OpenAPI 2.0/3.0.x intellisense, validator, linter, converter and resolver extension for Visual Studio Code
Stars: ✭ 47 (+80.77%)
Mutual labels:  validator, openapi3
Oas Kit
Convert Swagger 2.0 definitions to OpenAPI 3.0 and resolve/validate/lint
Stars: ✭ 516 (+1884.62%)
Mutual labels:  validator, openapi3
Prance
Resolving Swagger/OpenAPI 2.0 and 3.0 Parser
Stars: ✭ 133 (+411.54%)
Mutual labels:  validator, openapi3
dockerfile-utils
A library and command line interface for formatting and linting Dockerfiles.
Stars: ✭ 17 (-34.62%)
Mutual labels:  validator
morpheus
Red pill or blue pill? - A collection of Desmos testnets
Stars: ✭ 22 (-15.38%)
Mutual labels:  validator
checker
Golang parameter validation, which can replace go-playground/validator, includes ncluding Cross Field, Map, Slice and Array diving, provides readable,flexible, configurable validation.
Stars: ✭ 62 (+138.46%)
Mutual labels:  validator
actix-swagger
Swagger code generator for actix-web framework
Stars: ✭ 58 (+123.08%)
Mutual labels:  openapi3
helpdesk-validator
Community discussion forum for INSPIRE validation issues
Stars: ✭ 31 (+19.23%)
Mutual labels:  validator
fastify-openapi-glue
A plugin for Fastify to autogenerate a configuration based on a OpenApi(v2/v3) specification.
Stars: ✭ 94 (+261.54%)
Mutual labels:  openapi3
http-rider
Simple and Powerful desktop client for working with JSON APIs
Stars: ✭ 27 (+3.85%)
Mutual labels:  openapi3
openapi-schema-validator
OpenAPI schema validator for Python
Stars: ✭ 35 (+34.62%)
Mutual labels:  openapi3
shipengine-openapi
The official OpenAPI 3.0 definitions for ShipEngine™
Stars: ✭ 13 (-50%)
Mutual labels:  openapi3
sbt-openapi-schema
Generate schema sources for Scala, Java and Elm from an openapi 3.0 spec.
Stars: ✭ 12 (-53.85%)
Mutual labels:  openapi3
efm-certvalidator
Certificate validator for X.509 certificates.
Stars: ✭ 25 (-3.85%)
Mutual labels:  validator
validation
Validation on Laravel 5.X|6.X|7.X|8.X
Stars: ✭ 26 (+0%)
Mutual labels:  validator
ThinCreditCard
💳 Simple way to add a credit card
Stars: ✭ 40 (+53.85%)
Mutual labels:  validator
NZ-Bank-Account-Validator
A small, zero dependency NZ bank account validation library that runs everywhere.
Stars: ✭ 15 (-42.31%)
Mutual labels:  validator
python-valid8
Yet another validation lib ;). Provides tools for general-purpose variable validation, function inputs/outputs validation as well as class fields validation. All entry points raise consistent ValidationError including all contextual details, with dynamic inheritance of ValueError/TypeError as appropriate.
Stars: ✭ 24 (-7.69%)
Mutual labels:  validator
thema
A CUE-based framework for portable, evolvable schema
Stars: ✭ 41 (+57.69%)
Mutual labels:  openapi3
openapi-schemas
JSON Schemas for every version of the OpenAPI Specification
Stars: ✭ 22 (-15.38%)
Mutual labels:  openapi3

apispec

Build Status Coverage Status

A Common Lisp library for handling Web API specifications. This allows to validate and parse HTTP request headers, parameters and bodies with OpenAPI3 specification.

Warning

This software is still ALPHA quality. The APIs will be likely to change.

Prerequisite

  • libyaml for loading OpenAPI spec files.

Usage

Loading specification file

(defvar *spec*
  (apispec:load-from-file #P"docs/api.yaml"))

(apispec:spec-version *spec*)
;=> "3.0.2"

Getting the operation

(defvar *router* (apispec:spec-router *spec*))

(apispec:find-route *router* :GET "/users/12")
;=> #<APISPEC/CLASSES/OPERATION:OPERATION {1003DDB073}>

Parsing and Validating HTTP requests

(import '(lack.request:request-query-parameters
          lack.request:request-body-parameters
          lack.request:request-cookies
          apispec:request-path-parameters))

;; Clack application
(defvar *app*
  (lambda (env)
    (multiple-value-bind (operation path-parameters)
        (apispec:find-route (spec-router *spec*)
                            (getf env :request-method)
                            (getf env :path-info))
      ;; Getting Lack.Request
      (let ((request (apispec:validate-request operation env
                                               :path-parameters path-parameters)))
        ;; Write the main application here.

        ;; Accessors for getting each parameters.
        (request-query-parameters request)  ;=> Query parameters (alist)
        (request-body-parameters request)   ;=> Body parameters (alist)
        (request-path-parameters request)   ;=> Path parameters (alist)
        (request-cookies)                   ;=> Cookie parameters (alist)

        ))))

;; Start the server
(clack:clackup *app*)

Validating and Encoding HTTP responses

(import 'lack.response:make-response)

(apispec:validate-response operation
                           (make-response 200
                                          '(:content-type "application/json")
                                          '(("id" . 3)
                                            ("name" . "初音ミク")
                                            ("is_admin" . nil))))
;=> (200 (:CONTENT-TYPE "application/json") ("{\"id\":3,\"name\":\"初音ミク\",\"is_admin\":false}"))

Custom Encoder for standard objects

(import 'lack.response:make-response)

;; Custom class
(defclass user ()
  ((id :initarg :id)
   (name :initarg :name)
   (is-admin :initarg :is-admin)))

;; Define APISPEC:ENCODE-OBJECT for the class
(defmethod apispec:encode-object ((user user))
  `(("id" . ,(slot-value user 'id))
    ("name" . ,(slot-value user 'name))
    ("is_admin" . ,(slot-value user 'is-admin))))

(defvar *yukari*
  (make-instance 'user
                 :id 14
                 :name "結月ゆかり"
                 :is-admin nil))

(apispec:validate-response operation
                           (make-response 200
                                          '(:content-type "application/json")
                                          *yukari*))
;=> (200 (:CONTENT-TYPE "application/json") ("{\"id\":14,\"name\":\"結月ゆかり\",\"is_admin\":false}"))

Examples

See examples/.

See Also

Author

Copyright

Copyright (c) 2019 Eitaro Fukamachi ([email protected])

License

Licensed under the BSD 3-Clause License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].