All Projects → lispyclouds → navi

lispyclouds / navi

Licence: EPL-1.0 license
A tiny library converting OpenAPI route definitions to Reitit routes.

Programming Languages

clojure
4091 projects

Projects that are alternatives of or similar to navi

OpenDocumenter
OpenDocumenter is a automatic documentation generator for OpenAPI v3 schemas. Simply provide your schema file in JSON or YAML, then sit back and enjoy the documentation.
Stars: ✭ 137 (+756.25%)
Mutual labels:  openapi
flownet
FlowNet - Data-Driven Reservoir Predictions
Stars: ✭ 36 (+125%)
Mutual labels:  data-driven
SimInf
A framework for data-driven stochastic disease spread simulations
Stars: ✭ 21 (+31.25%)
Mutual labels:  data-driven
graphql-to-openapi
Convert a graphql query + graphql schema into an openapi spec.
Stars: ✭ 31 (+93.75%)
Mutual labels:  openapi
spectree
API spec validator and OpenAPI document generator for Python web frameworks.
Stars: ✭ 190 (+1087.5%)
Mutual labels:  openapi
api
Typescript typings and OpenAPI v3 generator for the Revolt API.
Stars: ✭ 23 (+43.75%)
Mutual labels:  openapi
starling-developer-sdk
The official JavaScript development kit for building on the Starling API
Stars: ✭ 45 (+181.25%)
Mutual labels:  openapi
arcanist-linters
A collection of custom Arcanist linters
Stars: ✭ 64 (+300%)
Mutual labels:  openapi
firecracker
Stop half-done API specifications! Cherrybomb is a CLI tool that helps you avoid undefined user behaviour by validating your API specifications.
Stars: ✭ 438 (+2637.5%)
Mutual labels:  openapi
OpenAPI-ObjectiveC
KKBOX Open API Developer SDK for iOS/macOS/watchOS/tvOS
Stars: ✭ 19 (+18.75%)
Mutual labels:  openapi
Bolt
⚡ is a fast grunt based, data driven, static site seed project, for rapid web development of PWA's or JAMstack projects
Stars: ✭ 30 (+87.5%)
Mutual labels:  data-driven
tester
Lightweight test utilities to use with Go's testing package
Stars: ✭ 43 (+168.75%)
Mutual labels:  data-driven
KaiZen-OpenApi-Parser
High-performance Parser, Validator, and Java Object Model for OpenAPI 3.x
Stars: ✭ 119 (+643.75%)
Mutual labels:  openapi
Swiftgger
OpenAPI support for server side Swift projects.
Stars: ✭ 97 (+506.25%)
Mutual labels:  openapi
specification
GA4GH Beacon specification.
Stars: ✭ 31 (+93.75%)
Mutual labels:  openapi
fastapi-azure-auth
Easy and secure implementation of Azure AD for your FastAPI APIs 🔒 B2C, single- and multi-tenant support.
Stars: ✭ 174 (+987.5%)
Mutual labels:  openapi
kommentaar
Generate documentation for Go APIs
Stars: ✭ 33 (+106.25%)
Mutual labels:  openapi
crud
Swagger/OpenAPI builder and input validation for Go APIs
Stars: ✭ 34 (+112.5%)
Mutual labels:  openapi
eave
优雅的接口文档制作工具 | A Restful Api Document Builder For Pythonista
Stars: ✭ 18 (+12.5%)
Mutual labels:  openapi
swagger-petstore
petstore.swagger.io
Stars: ✭ 84 (+425%)
Mutual labels:  openapi

navi Tests

A tiny library converting OpenAPI route definitions to Reitit routes.

Suitable for spec-first servers.

Status

Experimental

Features

  • Read OpenAPI 3 definitions as JSON or YAML
  • Remote and relative refs
  • Request coercions powered by Malli
  • requestBody coercion
  • The following OpenAPI types are currently supported:
    • string
    • integer
    • array
    • object

Currently unsupported:

  • Response coercions
  • Other coercion libs
  • A lot more of the OpenAPI spec

Any contributions are much much welcome and appreciated!

Installation

Leiningen/Boot

[org.clojars.lispyclouds/navi "0.0.2"]

Clojure CLI/deps.edn

{org.clojars.lispyclouds/navi {:mvn/version "0.0.2"}}

Gradle

compile 'org.clojars.lispyclouds:navi:0.0.2'

Maven

<dependency>
  <groupId>org.clojars.lispyclouds</groupId>
  <artifactId>navi</artifactId>
  <version>0.0.2</version>
</dependency>

Usage

Given a api.yaml:

openapi: "3.0.0"

info:
  title: My calculator
  version: "0.1.0"
  description: My awesome calc!

paths:
  "/add/{n1}/{n2}":
    get:
      operationId: AddGet
      summary: Adds two numbers

      parameters:
        - name: n1
          required: true
          in: path
          description: The first number
          schema:
            type: integer
        - name: n2
          required: true
          in: path
          description: The second number
          schema:
            type: integer
    post:
      operationId: AddPost
      summary: Adds two numbers via POST

      requestBody:
        description: The numebers map
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/NumbersMap"
  "/health":
    get:
      operationId: HealthCheck
      summary: Returns Ok if all is well

components:
  schemas:
    NumbersMap:
      type: object
      required:
        - n1
        - n2
      properties:
        n1:
          type: integer
          description: The first number
        n2:
          type: integer
          description: The second number

A clojure map of OperationId to handler fns:

(def handlers
  {"AddGet"      (fn [{{{:keys [n1 n2]} :path} :parameters}]
                   {:status 200
                    :body   (str (+ n1 n2))})
   "AddPost"     (fn [{{{:keys [n1 n2]} :body} :parameters}]
                   {:status 200
                    :body   (str (+ n1 n2))})
   "HealthCheck" (fn [_]
                   {:status 200
                    :body   "Ok"})})

Generate the routes:

(require '[navi.core :as navi])

(navi/routes-from (slurp "api.yaml") handlers)
=>
[["/add/{n1}/{n2}"
  {:get
   {:handler #function[navi.core/fn--8260],
    :parameters
    {:path
     [:map
      [:n1 #function[clojure.core/int?]]
      [:n2 #function[clojure.core/int?]]]}},
   :post
   {:handler #function[navi.core/fn--8266],
    :parameters
    {:body
     [:map
      {:closed false}
      [:n1 #function[clojure.core/int?]]
      [:n2 #function[clojure.core/int?]]]}}}]
 ["/health" {:get {:handler #function[navi.core/fn--8271]}}]]

Bootstrapping a Jetty server:

(ns server
  (:require [muuntaja.core :as m]
            [reitit.ring :as ring]
            [reitit.http :as http]
            [reitit.coercion.malli :as malli]
            [reitit.http.coercion :as coercion]
            [reitit.http.interceptors.parameters :as parameters]
            [reitit.http.interceptors.muuntaja :as muuntaja]
            [reitit.interceptor.sieppari :as sieppari]
            [ring.adapter.jetty :as jetty]
            [navi.core :as navi]))

(def server
  (http/ring-handler
    (http/router (-> "api.yaml"
                     slurp
                     (navi/routes-from handlers)) ; handlers is the map described before
                 {:data {:coercion     malli/coercion
                         :muuntaja     m/instance
                         :interceptors [(parameters/parameters-interceptor)
                                        (muuntaja/format-negotiate-interceptor)
                                        (muuntaja/format-response-interceptor)
                                        (muuntaja/format-request-interceptor)
                                        (coercion/coerce-response-interceptor)
                                        (coercion/coerce-request-interceptor)]}})
    (ring/routes
      (ring/create-default-handler
        {:not-found (constantly {:status  404
                                 :headers {"Content-Type" "application/json"}
                                 :body    "{\"message\": \"Took a wrong turn?\"}"})}))
    {:executor sieppari/executor}))

(jetty/run-jetty (var server)
                 {:host   "0.0.0.0"
                  :port   7777
                  :join?  false
                  :async? true})

deps.edn used for this example:

{:deps {org.clojars.lispyclouds/navi {:mvn/version "0.0.2"}
        metosin/reitit-core          {:mvn/version "0.5.12"}
        metosin/reitit-http          {:mvn/version "0.5.12"}
        metosin/reitit-interceptors  {:mvn/version "0.5.12"}
        metosin/reitit-malli         {:mvn/version "0.5.12"}
        metosin/reitit-ring          {:mvn/version "0.5.12"}
        metosin/reitit-sieppari      {:mvn/version "0.5.12"}
        metosin/reitit-middleware    {:mvn/version "0.5.12"}
        metosin/muuntaja             {:mvn/version "0.6.8"}
        ring/ring-jetty-adapter      {:mvn/version "1.9.2"}}}

Build Requirements

Running tests locally

  • clojure -M:test to run all tests

License

Copyright © 2020-2021 Rahul De

Distributed under the EPL License, same as Clojure. See 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].