jast 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b89c4b7e50ecf55dd5d7fddf6e12973625343e05
4
+ data.tar.gz: eeec861ef26db9ddee01e1ec4bb0acc5214fd40a
5
+ SHA512:
6
+ metadata.gz: 693673073b03cd26747fe11ea24570ac7cc70fcec350e773004ee394188d3d72df6144b7a79ba30357303dcc66a217ef978a9309cf6d10b40e06b18ea9db85f1
7
+ data.tar.gz: a550e73cd46c914c4167f6c580cbdec83f5917b82bd66517afd06cd1a51b09aedf4f57b449b7f5d89db6abb3bc831ed65f9ea7c19416f8d49293b478a6b78927
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea/
11
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jast.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Daniel Schweighoefer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,51 @@
1
+ # Jast
2
+
3
+ Json-Api Schema Tools support you to specify [JSON-API](http://jsonapi.org/ "jsonapi webside") compliant APIs with [JSON-Schema](http://json-schema.org/ "json-schema webside").
4
+
5
+ It is initially written with the aim to support your rspec test-setup in an rails application but didn't have those as dependencies so it can be used in any other context, too.
6
+
7
+ ## Usage
8
+
9
+ jast expects that the files will be stored in the spec/support/api/v1/schemas/ directory.
10
+
11
+ To render schemas do:
12
+
13
+ jast schemas name attr1:type attr2:type
14
+
15
+ You can set required attributes by adding :required to the call, e.g.:
16
+
17
+ jast schemas name attr1:type attr2:type attr3:type:required
18
+
19
+ Please consult the JSON-Schema documentation for a [list of attribute types](http://json-schema.org/latest/json-schema-core.html#anchor8 "jsonapi docs"), is it also possible to have an attributes of type object containing a JSON-object.
20
+
21
+ ## Installation
22
+
23
+ Add this line to your application's Gemfile:
24
+
25
+ ```ruby
26
+ gem 'jast'
27
+ ```
28
+
29
+ And then execute:
30
+
31
+ $ bundle
32
+
33
+ Or install it yourself as:
34
+
35
+ $ gem install jast
36
+
37
+ ## Development
38
+
39
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
40
+
41
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/POSpulse/jast. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
46
+
47
+
48
+ ## License
49
+
50
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
51
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jast"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "thor"
4
+ require "jast"
5
+
6
+ class JastCLI < Thor
7
+ class_option :path, desc: "set the base path", type: :string, default: nil, aliases: "-p"
8
+ class_option :api_version, desc: "set the api version", type: :string, default: 1, aliases: "-a"
9
+
10
+ desc "schemas name property:type[:required] ...", "render all schema files"
11
+ def schemas( name, *schemaspecs)
12
+ properties = {}
13
+ required = []
14
+ schemaspecs.each do |opt|
15
+ props = opt.split(":")
16
+ properties[props[0].to_sym] = props[1]
17
+ if props.size > 2
18
+ required << props[0]
19
+ end
20
+ end
21
+ generator = Jast::Generator.new api_version: options[:api_version], base_path: options[:path]
22
+ generator.render_schemas name, properties, required
23
+ end
24
+
25
+ end
26
+
27
+ JastCLI.start
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jast/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jast"
8
+ spec.version = Jast::VERSION
9
+ spec.authors = ["Daniel Schweighoefer"]
10
+ spec.email = ["daniel.schweighoefer@pospulse.com"]
11
+ spec.required_ruby_version = ">= 2.2.3"
12
+
13
+ spec.summary = "JSON Api Schema Tools"
14
+ spec.description = "A Collection of Tools for building JSON-Api comliant Api definitions ready to be tested with JSON-schema"
15
+ spec.homepage = "https://github.com/POSpulse/jast"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "thor", "~> 0.19.1"
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.3.0"
27
+ end
@@ -0,0 +1,18 @@
1
+ require "jast/version"
2
+ require "jast/schema_renderer"
3
+
4
+ module Jast
5
+ class Generator
6
+ attr_accessor :api_version, :base_path, :definitions_path
7
+
8
+ def initialize api_version: 1, base_path: nil
9
+ @api_version = api_version
10
+ @base_path = base_path.nil? ? "spec/support/api/v#{api_version}/schemas/" : base_path
11
+ end
12
+
13
+ def render_schemas name, properties, required
14
+ schema_renderer = Jast::SchemaRenderer.new name, base_path
15
+ schema_renderer.render_resource properties, required
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,42 @@
1
+ require "erb"
2
+
3
+ module Jast
4
+ class SchemaRenderer
5
+ def initialize name, path
6
+ @name = name
7
+ @path = path
8
+ end
9
+
10
+ def build_json file, properties = {}, required = []
11
+ filename = "#{file}.json.erb"
12
+ template_path = "#{File.expand_path(File.dirname(__FILE__))}/templates/#{filename}"
13
+ ERB.new(File.read(template_path), nil, ">").result(binding)
14
+ end
15
+
16
+ def render_definition properties, required
17
+ render_file :definition, {path: "#{@path}definitions/", properties: properties, required: required, filename: @name}
18
+ end
19
+
20
+ def render_file file, fileopts = {}
21
+ content = build_json(file, fileopts[:properties], fileopts[:required])
22
+ path = fileopts[:path].nil? ? @path : fileopts[:path]
23
+ FileUtils.mkdir_p(path)
24
+ filename = fileopts[:filename].nil? ? "#{@name}_#{file}.json" : fileopts[:filename]
25
+ IO.write("#{path}#{filename}", content)
26
+ end
27
+
28
+ def render_list_response
29
+ render_file :list_response
30
+ end
31
+
32
+ def render_resource properties, required
33
+ render_definition(properties, required)
34
+ render_list_response
35
+ render_response
36
+ end
37
+
38
+ def render_response
39
+ render_file :response
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,15 @@
1
+ {
2
+ "definitions": {
3
+ "<%= @name%>_attributes": {
4
+ "attributes": {
5
+ "type": "object",
6
+ "required": <%= required %>,
7
+ "properties": {
8
+ <% properties.each_with_index do |(key, value), i| %>
9
+ "<%= key.to_s %>": { "type": "<%= value.to_s %>" }<%= i < properties.size - 1 ? "," : "" %>
10
+ <% end %>
11
+ }
12
+ }
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "type": "object",
3
+ "required": [ "data" ],
4
+ "properties": {
5
+ "data": {
6
+ "type": "array",
7
+ "items": {
8
+ "type": "object",
9
+ "required": [ "attributes" ],
10
+ "properties": {
11
+ "id": { "type": "string" },
12
+ "type": { "type": "string" },
13
+ "attributes": { "$ref": "definitions/<%= @name%>.json#/definitions/<%= @name%>_attributes" },
14
+ "relationships": { "type": "object"}
15
+ }
16
+ }
17
+ }
18
+ }
19
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "type": "object",
3
+ "required": [ "data" ],
4
+ "properties": {
5
+ "data": {
6
+ "type": "object",
7
+ "required": [ "attributes" ],
8
+ "properties": {
9
+ "id": { "type": "string" },
10
+ "type": { "type": "string" },
11
+ "attributes": { "$ref": "definitions/<%= @name%>.json#/definitions/<%= @name%>_attributes" },
12
+ "relationships": { "type": "object"}
13
+ }
14
+ }
15
+ }
16
+ }
@@ -0,0 +1,3 @@
1
+ module Jast
2
+ VERSION = "0.1.4"
3
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jast
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Schweighoefer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.19.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.19.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.3.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.3.0
69
+ description: A Collection of Tools for building JSON-Api comliant Api definitions
70
+ ready to be tested with JSON-schema
71
+ email:
72
+ - daniel.schweighoefer@pospulse.com
73
+ executables:
74
+ - jast
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".travis.yml"
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - exe/jast
89
+ - jast.gemspec
90
+ - lib/jast.rb
91
+ - lib/jast/schema_renderer.rb
92
+ - lib/jast/templates/definition.json.erb
93
+ - lib/jast/templates/list_response.json.erb
94
+ - lib/jast/templates/response.json.erb
95
+ - lib/jast/version.rb
96
+ homepage: https://github.com/POSpulse/jast
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: 2.2.3
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.4.5.1
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: JSON Api Schema Tools
120
+ test_files: []