Code Monkey home page Code Monkey logo

raml-clj-parser's Introduction

raml-clj-parser Build Status codecov

This is a RAML parser implemented in clojure, which is based on SnakeYaml libarary.

It is able to parse a given raml file into clojure map, including all the included resource (tag !include) and subordinate raml files.

It also provides validtion according to raml spec v08

Version

Clojars Project

Installation

Add the following dependency to your project.clj file:

[raml-clj-parser "0.1.1-SNAPSHOT"]

Usage

Read raml file into clojure map

(require '[raml-clj-parser.core :as raml])

(raml/read-raml "resource/sample.raml")

;; => {:raml-version "0.8", :title "Jukebox API", :baseUri {:uri "http://jukebox.api.com", :raml-clj-parser.reader/uri-parameters []}, :version "v1"}

It will convert all the raml tag into clojure keywords and all the routes into string. And you can use regular clojure fn to navigate though the map and retrieve associated values.

Validate raml content [optional]

The validation is build on Schema for more informatino you could refer to https://github.com/plumatic/schema

(require '[raml-clj-parser.core :as raml])

;;valid raml file
(let [raml_content (raml/read-raml "resource/valid.raml")]
  (raml/validate raml_content))

;; valid raml will return its content
;; => {:raml-version "0.8", :title "Jukebox API", :baseUri {:uri "http://jukebox.api.com", :raml-clj-parser.reader/uri-parameters []}, :version "v1"}

;;invalid raml file
(let [raml_content (raml/read-raml "resource/invalid.raml")
      validation_result (raml/validate raml_content)]
    (:error validation_result)

;; invalid raml will return a map contains the :error for the violation
;; in this case, there some key missing in the raml file
;; => {:title missing-required-key, :raml-version missing-required-key, :baseUri missing-required-key, (not ("Resource must starts with /" :error)) invalid-key}

Util fn (WIP)

;;for a parsed raml file
(get-abs-uri raml ["/sub_uri" "/sub_uri"])
;;=> will return a map contains the leaf resources's information including uri parameter and header

License

Copyright © 2017 FIXME

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

raml-clj-parser's People

Contributors

yaodanzhang avatar zacyang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

raml-clj-parser's Issues

Adding "raml-parser" as a topic

Hi,

Would be nice if you could add an additional topic "raml-parser". I want to use it in the future for the raml.org projects page to link to projects that are related to specific categories like "Parser" :)

Let me know if you have any questions!

Thanks,
Christian

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.