Giter Club home page Giter Club logo

Comments (3)

weavejester avatar weavejester commented on May 27, 2024

Sorry, how are you using Schema? Can you explain a little further?

from compojure.

igotti avatar igotti commented on May 27, 2024

what plumatic/schema is.

my sample code:

(api/defendpoint GET "/:card-id/alerts"
  "Getting alerts for card with specifications"
  [card-id enabled :<< as-bool :as {{:keys [page size] :or {page 1 size 20}} :params}]
  {enabled                (s/maybe s/Bool)
   page                   su/IntGreaterThanZero
   size                   su/IntGreaterThanZero}
  (do-something))

where s alias for schema.core and su things alike, api/defendpoint refers to:

(doc metabase.api.common/defendpoint)

([method route docstr? args schemas-map? & body])
Macro
Define an API function.
This automatically does several things:

  • calls auto-parse to automatically parse certain args. e.g. id is converted from String to
    Integer via Integer/parseInt

  • converts ROUTE from a simple form like "/:id" to a typed one like ["/:id" :id #"[0-9]+"]

  • sequentially applies specified annotation functions on args to validate them.

  • automatically calls wrap-response-if-needed on the result of BODY

  • tags function's metadata in a way that subsequent calls to define-routes (see below) will
    automatically include the function in the generated defroutes form.

  • Generates a super-sophisticated Markdown-formatted docstring

from compojure.

weavejester avatar weavejester commented on May 27, 2024

We can't break existing functionality in Compojure, so I see only two ways forward.

The first is to create another symbol or object to denote a missing value, and create an appropriate schema function. For example, (def missing (Object.)), or ::missing.

The second is to add in a new symbol for coercion that matches even on nil. For example, enabled :<<? as-bool.

from compojure.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.