SlideShare uma empresa Scribd logo
1 de 25
Baixar para ler offline
Clojure Finland 10.3.2016
Tommi Reiman / Metosin
@ikitommi
Schema-tools & tricks
Schema-tools & tricks
& quick clojure.spec intro
Clojure Finland 10.3.2016 22.6.2016
Tommi Reiman / Metosin
@ikitommi
Schema
‱ https://github.com/plumatic/schema
‱ Structural data validation library for Clojure(Script)
– Based on predicates, (almost) just data
‱ Runtime type-checking
‱ Documentation for data & functions
‱ Recursive transformations with coercion and matchers
‱ Macros for defining schematized functions
‱ Data generation & completion
‱ DEMO: basic syntax
Schema is real life projects (~all of ours)
‱ (Optionally) annotate your domain functions and values
with Schema
– Schema def , defschema & defn
– Plumbing defnk , fnk & letk
‱ Enable schema checking for tests (catching 90% of type
bugs)
‱ Turn off optional validation in production
‱ Force coercion when needed / at the system boundaries
‱ Data coercion between contexts
Schemas in web development
‱ Schema coercions when reading from external sources (JSON, XML,
db, 
)
‱ Schema-based remote apis
– Ring-swagger (https://github.com/metosin/ring-swagger)
– Used by compojure-api,fnhouse-swagger, kekkonen, pedestal-api,yada
‱ Schemas for the ClojureScript frontend
– Code sharing via cljc (common domain: both data & function to operate on ’em)
– schema-tools for combining ui-views & server-views
‱ End2end schemas for Clojure(Script)?
– Dynamic Schemas over the wire withTransit (allows only partial validation)
– Resolve the expression problem (new wire-formats, new types)
Schema example (with kekkonen.io)
Schema-tools (https://github.com/metosin/schema-tools)
‱ Selectors, transformers, walkers
‱ Handling of defaults
‱ Coercion helpers
‱ DEMO: cut & paste models
‱ DEMO: declarative transformations
‱ DEMO: defaults
‱ DEMO: coercion speed (case RegistryX)
Schema-viz (https://github.com/metosin/schema-viz)
Schema takeaways
‱ Schema is awesome for runtime structural validation – for both
system boundaries & tests
‱ Noise-free syntax with schematized data & function definitions
‱ Has been de facto in Clojure web (api) development
‱ Mostly just data, enabling cool things like declarative
transformations
clojure.spec
(a quick overview)
What is
‱ a new Integrated system for specification and testing, shipped with Clojure 1.9
‱ Automatic validation, error reporting, test-data & test generation
‱ Specs can be written external to the actual functions & data (like core.typed)
‱ Build from ground-up, recursive,regexps
‱ (Mutable) Global spec registry
‱ Form, Conform & Unform, multi-spec
‱ Function specs on :args,:ret and :fn(!)
‱ Opinions
– Maps should be open
– Namespaced keywords
– Verification via (generative) tests
‱ Currently is not
– A runtime validation system
– In alpha6, the :ret and :fn was removed from standard instrumentation,hmph.
CODE
Function specs
https://clojure.org/guides/spec
+	spec	for	higher	 order	functions
+	spec	for	macros
+	multispec for	multimethods
Spec for runtime validation?
https://clojure.org/guides/spec
Coercion?
‱ Conformers live
within the spec (vs
external with
Schema)
‱ How can I do custom
conform based on
external info (e.g.
protocol used)
Generating data
https://clojure.org/guides/spec
Generative testing
https://clojure.org/guides/spec
More info about spec
‱ https://clojure.org/guides/spec
‱ Slack #clojure-spec (both Rich & Alex seem to hang
out there)
‱ Changes in the language
– Lot’s of new predicates in clojure.core
– Namespaced maps http://dev.clojure.org/jira/browse/CLJ-1910
– Destructuring http://dev.clojure.org/jira/browse/CLJ-1919
Schema, Spec vs Both?
Performance
2-6x	
faster
Not	optimized	
for	perf,	yet.http://muhuk.github.io/validation-benchmark/
Differences
‱ Spec has better support for language level
features like multi-methods and higher order
functions
‱ Schema supports closed maps & coercion
‱ Both support data generation & generative
tests
‱ Schema is not found by Rich Hickey
Specs for the web, today?
‱ Played with a idea to combine the two:
– Convert a pragmatic subset of spec predicates into Schema Predicates
‱ integer? => s/Int
‱ boolean? => s/Bool
‱ (and integer? pos?) => (s/constrained s/Int pos?)
– Use Schema as before (web-libs, snappy coercion etc.)
Ăš https://github.com/metosin/spec-tools & integrate into current apis
My 2 cents
‱ Schema is currently much better for runtime validation (at borders)
– Support (api-docs, api-libs), coercions, performance, low ceremony
‱ Spec will become de facto way for specifying Clojure systems as it will be
part of the core
– Under active development, let’s enjoy the ride!
– Better runtime validation support via 3rd
party libs
‱ Low ceremony function & data definitions via extra macros
‱ Coercions(!)
– Tooling support (IDEs, api-libs)
‱ At least for now, the can co-exist

Ăš TODAY: Schema for the boundaries, more spec when things freeze down
Thanks!
Links
‱ Schema https://github.com/plumatic/schema
– Schema-tools https://github.com/metosin/schema-tools
– Schema-viz https://github.com/metosin/schema-viz
– Ring-Swagger https://github.com/metosin/ring-swagger
‱ Spec http://clojure.org/about/spec
– Regular Expressions:
https://en.wikipedia.org/wiki/Regular_expression

Mais conteĂșdo relacionado

Mais procurados

Understanding Presto - Presto meetup @ Tokyo #1
Understanding Presto - Presto meetup @ Tokyo #1Understanding Presto - Presto meetup @ Tokyo #1
Understanding Presto - Presto meetup @ Tokyo #1
Sadayuki Furuhashi
 
Operational Tips for Deploying Spark by Miklos Christine
Operational Tips for Deploying Spark by Miklos ChristineOperational Tips for Deploying Spark by Miklos Christine
Operational Tips for Deploying Spark by Miklos Christine
Spark Summit
 
Debugging Apache Spark
Debugging Apache SparkDebugging Apache Spark
Debugging Apache Spark
Joey Echeverria
 

Mais procurados (20)

HBaseConEast2016: Coprocessors – Uses, Abuses and Solutions
HBaseConEast2016: Coprocessors – Uses, Abuses and SolutionsHBaseConEast2016: Coprocessors – Uses, Abuses and Solutions
HBaseConEast2016: Coprocessors – Uses, Abuses and Solutions
 
Internals of Presto Service
Internals of Presto ServiceInternals of Presto Service
Internals of Presto Service
 
Boston Hadoop Meetup: Presto for the Enterprise
Boston Hadoop Meetup: Presto for the EnterpriseBoston Hadoop Meetup: Presto for the Enterprise
Boston Hadoop Meetup: Presto for the Enterprise
 
Treasure Data and AWS - Developers.io 2015
Treasure Data and AWS - Developers.io 2015Treasure Data and AWS - Developers.io 2015
Treasure Data and AWS - Developers.io 2015
 
Understanding Presto - Presto meetup @ Tokyo #1
Understanding Presto - Presto meetup @ Tokyo #1Understanding Presto - Presto meetup @ Tokyo #1
Understanding Presto - Presto meetup @ Tokyo #1
 
Operational Tips for Deploying Spark by Miklos Christine
Operational Tips for Deploying Spark by Miklos ChristineOperational Tips for Deploying Spark by Miklos Christine
Operational Tips for Deploying Spark by Miklos Christine
 
Tale of ISUCON and Its Bench Tools
Tale of ISUCON and Its Bench ToolsTale of ISUCON and Its Bench Tools
Tale of ISUCON and Its Bench Tools
 
Gobblin on-aws
Gobblin on-awsGobblin on-aws
Gobblin on-aws
 
HBaseConEast2016: How yarn timeline service v.2 unlocks 360 degree platform i...
HBaseConEast2016: How yarn timeline service v.2 unlocks 360 degree platform i...HBaseConEast2016: How yarn timeline service v.2 unlocks 360 degree platform i...
HBaseConEast2016: How yarn timeline service v.2 unlocks 360 degree platform i...
 
H-Hypermap - Heatmap Analytics at Scale: Presented by David Smiley, D W Smile...
H-Hypermap - Heatmap Analytics at Scale: Presented by David Smiley, D W Smile...H-Hypermap - Heatmap Analytics at Scale: Presented by David Smiley, D W Smile...
H-Hypermap - Heatmap Analytics at Scale: Presented by David Smiley, D W Smile...
 
Facebook Presto presentation
Facebook Presto presentationFacebook Presto presentation
Facebook Presto presentation
 
Getting started with Apollo Client and GraphQL
Getting started with Apollo Client and GraphQLGetting started with Apollo Client and GraphQL
Getting started with Apollo Client and GraphQL
 
From Zero to Hero with Kafka Connect
From Zero to Hero with Kafka ConnectFrom Zero to Hero with Kafka Connect
From Zero to Hero with Kafka Connect
 
StackMate - CloudFormation for CloudStack
StackMate - CloudFormation for CloudStackStackMate - CloudFormation for CloudStack
StackMate - CloudFormation for CloudStack
 
Asynchronous Orchestration DSL on squbs
Asynchronous Orchestration DSL on squbsAsynchronous Orchestration DSL on squbs
Asynchronous Orchestration DSL on squbs
 
What is the State of my Kafka Streams Application? Unleashing Metrics. | Neil...
What is the State of my Kafka Streams Application? Unleashing Metrics. | Neil...What is the State of my Kafka Streams Application? Unleashing Metrics. | Neil...
What is the State of my Kafka Streams Application? Unleashing Metrics. | Neil...
 
Akka Streams and HTTP
Akka Streams and HTTPAkka Streams and HTTP
Akka Streams and HTTP
 
Fluentd - Flexible, Stable, Scalable
Fluentd - Flexible, Stable, ScalableFluentd - Flexible, Stable, Scalable
Fluentd - Flexible, Stable, Scalable
 
Paxquery
PaxqueryPaxquery
Paxquery
 
Debugging Apache Spark
Debugging Apache SparkDebugging Apache Spark
Debugging Apache Spark
 

Semelhante a Schema tools-and-trics-and-quick-intro-to-clojure-spec-22.6.2016

End-to-end Data Governance with Apache Avro and Atlas
End-to-end Data Governance with Apache Avro and AtlasEnd-to-end Data Governance with Apache Avro and Atlas
End-to-end Data Governance with Apache Avro and Atlas
DataWorks Summit
 
Architectures, Frameworks and Infrastructure
Architectures, Frameworks and InfrastructureArchitectures, Frameworks and Infrastructure
Architectures, Frameworks and Infrastructure
harendra_pathak
 
API-Testing-SOAPUI-1.pptx
API-Testing-SOAPUI-1.pptxAPI-Testing-SOAPUI-1.pptx
API-Testing-SOAPUI-1.pptx
amarnathdeo
 
hibernateormfeatures-140223193044-phpapp02.pdf
hibernateormfeatures-140223193044-phpapp02.pdfhibernateormfeatures-140223193044-phpapp02.pdf
hibernateormfeatures-140223193044-phpapp02.pdf
Patiento Del Mar
 

Semelhante a Schema tools-and-trics-and-quick-intro-to-clojure-spec-22.6.2016 (20)

Performance and Abstractions
Performance and AbstractionsPerformance and Abstractions
Performance and Abstractions
 
Real-time Big Data Analytics Engine using Impala
Real-time Big Data Analytics Engine using ImpalaReal-time Big Data Analytics Engine using Impala
Real-time Big Data Analytics Engine using Impala
 
Play Framework and Activator
Play Framework and ActivatorPlay Framework and Activator
Play Framework and Activator
 
Using existing language skillsets to create large-scale, cloud-based analytics
Using existing language skillsets to create large-scale, cloud-based analyticsUsing existing language skillsets to create large-scale, cloud-based analytics
Using existing language skillsets to create large-scale, cloud-based analytics
 
Tuenti Release Workflow v1.1
Tuenti Release Workflow v1.1Tuenti Release Workflow v1.1
Tuenti Release Workflow v1.1
 
End-to-end Data Governance with Apache Avro and Atlas
End-to-end Data Governance with Apache Avro and AtlasEnd-to-end Data Governance with Apache Avro and Atlas
End-to-end Data Governance with Apache Avro and Atlas
 
Protractor survival guide
Protractor survival guideProtractor survival guide
Protractor survival guide
 
Tuenti Release Workflow
Tuenti Release WorkflowTuenti Release Workflow
Tuenti Release Workflow
 
COMMitMDE'18: Eclipse Hawk: model repository querying as a service
COMMitMDE'18: Eclipse Hawk: model repository querying as a serviceCOMMitMDE'18: Eclipse Hawk: model repository querying as a service
COMMitMDE'18: Eclipse Hawk: model repository querying as a service
 
Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1
 
Architectures, Frameworks and Infrastructure
Architectures, Frameworks and InfrastructureArchitectures, Frameworks and Infrastructure
Architectures, Frameworks and Infrastructure
 
API-Testing-SOAPUI-1.pptx
API-Testing-SOAPUI-1.pptxAPI-Testing-SOAPUI-1.pptx
API-Testing-SOAPUI-1.pptx
 
Integrating Microservices with Apache Camel
Integrating Microservices with Apache CamelIntegrating Microservices with Apache Camel
Integrating Microservices with Apache Camel
 
DataFrames: The Extended Cut
DataFrames: The Extended CutDataFrames: The Extended Cut
DataFrames: The Extended Cut
 
SolrCloud on Hadoop
SolrCloud on HadoopSolrCloud on Hadoop
SolrCloud on Hadoop
 
Cmake kitware
Cmake kitwareCmake kitware
Cmake kitware
 
Ruby and Distributed Storage Systems
Ruby and Distributed Storage SystemsRuby and Distributed Storage Systems
Ruby and Distributed Storage Systems
 
Scala at Treasure Data
Scala at Treasure DataScala at Treasure Data
Scala at Treasure Data
 
hibernateormfeatures-140223193044-phpapp02.pdf
hibernateormfeatures-140223193044-phpapp02.pdfhibernateormfeatures-140223193044-phpapp02.pdf
hibernateormfeatures-140223193044-phpapp02.pdf
 
Performance Benchmarking: Tips, Tricks, and Lessons Learned
Performance Benchmarking: Tips, Tricks, and Lessons LearnedPerformance Benchmarking: Tips, Tricks, and Lessons Learned
Performance Benchmarking: Tips, Tricks, and Lessons Learned
 

Mais de Metosin Oy

Mais de Metosin Oy (16)

Navigating container technology for enhanced security by Niklas Saari
Navigating container technology for enhanced security by Niklas SaariNavigating container technology for enhanced security by Niklas Saari
Navigating container technology for enhanced security by Niklas Saari
 
Where is Technical Debt?
Where is Technical Debt?Where is Technical Debt?
Where is Technical Debt?
 
Creating an experimental GraphQL formatter using Clojure, Instaparse, and Gra...
Creating an experimental GraphQL formatter using Clojure, Instaparse, and Gra...Creating an experimental GraphQL formatter using Clojure, Instaparse, and Gra...
Creating an experimental GraphQL formatter using Clojure, Instaparse, and Gra...
 
Serverless Clojure and ML prototyping: an experience report
Serverless Clojure and ML prototyping: an experience reportServerless Clojure and ML prototyping: an experience report
Serverless Clojure and ML prototyping: an experience report
 
Designing with malli
Designing with malliDesigning with malli
Designing with malli
 
Malli: inside data-driven schemas
Malli: inside data-driven schemasMalli: inside data-driven schemas
Malli: inside data-driven schemas
 
Naked Performance With Clojure
Naked Performance With ClojureNaked Performance With Clojure
Naked Performance With Clojure
 
Reitit - Clojure/North 2019
Reitit - Clojure/North 2019Reitit - Clojure/North 2019
Reitit - Clojure/North 2019
 
Fun with errors? - Clojure Finland Meetup 26.3.2019 Tampere
Fun with errors? - Clojure Finland Meetup 26.3.2019 TampereFun with errors? - Clojure Finland Meetup 26.3.2019 Tampere
Fun with errors? - Clojure Finland Meetup 26.3.2019 Tampere
 
Clojutre Real Life (2012 ClojuTRE Retro Edition)
Clojutre Real Life (2012 ClojuTRE Retro Edition)Clojutre Real Life (2012 ClojuTRE Retro Edition)
Clojutre Real Life (2012 ClojuTRE Retro Edition)
 
The Ancient Art of Data-Driven - reitit, the library -
The Ancient Art of Data-Driven - reitit, the library - The Ancient Art of Data-Driven - reitit, the library -
The Ancient Art of Data-Driven - reitit, the library -
 
Craft Beer & Clojure
Craft Beer & ClojureCraft Beer & Clojure
Craft Beer & Clojure
 
ClojuTRE2016 Opening slides
ClojuTRE2016 Opening slidesClojuTRE2016 Opening slides
ClojuTRE2016 Opening slides
 
ClojuTRE - a (very) brief history
ClojuTRE - a (very) brief historyClojuTRE - a (very) brief history
ClojuTRE - a (very) brief history
 
Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Clojure in real life 17.10.2014
Clojure in real life 17.10.2014
 
Euroclojure2014: Schema & Swagger - making your Clojure web APIs more awesome
Euroclojure2014: Schema & Swagger - making your Clojure web APIs more awesomeEuroclojure2014: Schema & Swagger - making your Clojure web APIs more awesome
Euroclojure2014: Schema & Swagger - making your Clojure web APIs more awesome
 

Último

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Último (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

Schema tools-and-trics-and-quick-intro-to-clojure-spec-22.6.2016

  • 1. Clojure Finland 10.3.2016 Tommi Reiman / Metosin @ikitommi Schema-tools & tricks
  • 2. Schema-tools & tricks & quick clojure.spec intro Clojure Finland 10.3.2016 22.6.2016 Tommi Reiman / Metosin @ikitommi
  • 3. Schema ‱ https://github.com/plumatic/schema ‱ Structural data validation library for Clojure(Script) – Based on predicates, (almost) just data ‱ Runtime type-checking ‱ Documentation for data & functions ‱ Recursive transformations with coercion and matchers ‱ Macros for defining schematized functions ‱ Data generation & completion ‱ DEMO: basic syntax
  • 4. Schema is real life projects (~all of ours) ‱ (Optionally) annotate your domain functions and values with Schema – Schema def , defschema & defn – Plumbing defnk , fnk & letk ‱ Enable schema checking for tests (catching 90% of type bugs) ‱ Turn off optional validation in production ‱ Force coercion when needed / at the system boundaries ‱ Data coercion between contexts
  • 5. Schemas in web development ‱ Schema coercions when reading from external sources (JSON, XML, db, 
) ‱ Schema-based remote apis – Ring-swagger (https://github.com/metosin/ring-swagger) – Used by compojure-api,fnhouse-swagger, kekkonen, pedestal-api,yada ‱ Schemas for the ClojureScript frontend – Code sharing via cljc (common domain: both data & function to operate on ’em) – schema-tools for combining ui-views & server-views ‱ End2end schemas for Clojure(Script)? – Dynamic Schemas over the wire withTransit (allows only partial validation) – Resolve the expression problem (new wire-formats, new types)
  • 6. Schema example (with kekkonen.io)
  • 7. Schema-tools (https://github.com/metosin/schema-tools) ‱ Selectors, transformers, walkers ‱ Handling of defaults ‱ Coercion helpers ‱ DEMO: cut & paste models ‱ DEMO: declarative transformations ‱ DEMO: defaults ‱ DEMO: coercion speed (case RegistryX)
  • 9. Schema takeaways ‱ Schema is awesome for runtime structural validation – for both system boundaries & tests ‱ Noise-free syntax with schematized data & function definitions ‱ Has been de facto in Clojure web (api) development ‱ Mostly just data, enabling cool things like declarative transformations
  • 11. What is ‱ a new Integrated system for specification and testing, shipped with Clojure 1.9 ‱ Automatic validation, error reporting, test-data & test generation ‱ Specs can be written external to the actual functions & data (like core.typed) ‱ Build from ground-up, recursive,regexps ‱ (Mutable) Global spec registry ‱ Form, Conform & Unform, multi-spec ‱ Function specs on :args,:ret and :fn(!) ‱ Opinions – Maps should be open – Namespaced keywords – Verification via (generative) tests ‱ Currently is not – A runtime validation system – In alpha6, the :ret and :fn was removed from standard instrumentation,hmph.
  • 12. CODE
  • 14. Spec for runtime validation? https://clojure.org/guides/spec
  • 15. Coercion? ‱ Conformers live within the spec (vs external with Schema) ‱ How can I do custom conform based on external info (e.g. protocol used)
  • 18. More info about spec ‱ https://clojure.org/guides/spec ‱ Slack #clojure-spec (both Rich & Alex seem to hang out there) ‱ Changes in the language – Lot’s of new predicates in clojure.core – Namespaced maps http://dev.clojure.org/jira/browse/CLJ-1910 – Destructuring http://dev.clojure.org/jira/browse/CLJ-1919
  • 21. Differences ‱ Spec has better support for language level features like multi-methods and higher order functions ‱ Schema supports closed maps & coercion ‱ Both support data generation & generative tests ‱ Schema is not found by Rich Hickey
  • 22. Specs for the web, today? ‱ Played with a idea to combine the two: – Convert a pragmatic subset of spec predicates into Schema Predicates ‱ integer? => s/Int ‱ boolean? => s/Bool ‱ (and integer? pos?) => (s/constrained s/Int pos?) – Use Schema as before (web-libs, snappy coercion etc.) Ăš https://github.com/metosin/spec-tools & integrate into current apis
  • 23. My 2 cents ‱ Schema is currently much better for runtime validation (at borders) – Support (api-docs, api-libs), coercions, performance, low ceremony ‱ Spec will become de facto way for specifying Clojure systems as it will be part of the core – Under active development, let’s enjoy the ride! – Better runtime validation support via 3rd party libs ‱ Low ceremony function & data definitions via extra macros ‱ Coercions(!) – Tooling support (IDEs, api-libs) ‱ At least for now, the can co-exist
 Ăš TODAY: Schema for the boundaries, more spec when things freeze down
  • 25. Links ‱ Schema https://github.com/plumatic/schema – Schema-tools https://github.com/metosin/schema-tools – Schema-viz https://github.com/metosin/schema-viz – Ring-Swagger https://github.com/metosin/ring-swagger ‱ Spec http://clojure.org/about/spec – Regular Expressions: https://en.wikipedia.org/wiki/Regular_expression