json_schema_rails 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -1
- data/app/controllers/json_schema_rails/schemas_controller.rb +2 -2
- data/config/routes.rb +1 -1
- data/lib/json_schema_rails/version.rb +1 -1
- data/spec/dummy_apps/rails3/app/controllers/helpers_controller.rb +11 -0
- data/spec/dummy_apps/rails3/config/routes.rb +3 -0
- data/spec/dummy_apps/rails4/app/controllers/helpers_controller.rb +11 -0
- data/spec/dummy_apps/rails4/config/routes.rb +3 -0
- data/spec/integration/helpers_controller_spec.rb +17 -0
- data/spec/integration/schemas_controller_spec.rb +12 -3
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30365db9f1e64bb272a6e68e5b82db4ffd5e3e75
|
4
|
+
data.tar.gz: 3fb83828166f3f10e5420d2e6b505167b175183d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cddf1f935f4856c56cc4e3aad13cb05456e2be237022d033864969f498bb5428a550453c785501b063b7c64daa16005edffe19e26d4b5decd7026201311d41e
|
7
|
+
data.tar.gz: 09a91ab2023b4bf7ab367e5ed2efd6354089062985e1651cc40d84ee5723b18dd50d53241a1e43438ff257c3a3d2249e1ead879f0f8533aae3ad21de4a1ec879
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# json_schema_rails
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/kotas/json_schema_rails.svg?branch=master)](https://travis-ci.org/kotas/json_schema_rails) [![Code Climate](https://codeclimate.com/github/kotas/json_schema_rails.png)](https://codeclimate.com/github/kotas/json_schema_rails)
|
3
|
+
[![Build Status](https://travis-ci.org/kotas/json_schema_rails.svg?branch=master)](https://travis-ci.org/kotas/json_schema_rails) [![Code Climate](https://codeclimate.com/github/kotas/json_schema_rails.png)](https://codeclimate.com/github/kotas/json_schema_rails) [![Gem Version](https://badge.fury.io/rb/json_schema_rails.svg)](http://badge.fury.io/rb/json_schema_rails)
|
4
4
|
|
5
5
|
[JSON Schema v4](http://json-schema.org/) validator and generator for Rails 3+
|
6
6
|
|
@@ -114,11 +114,32 @@ And you can get your schemas through the path `/schemas` like following:
|
|
114
114
|
```
|
115
115
|
# Get `app/schemas/posts/create.*` as application/json
|
116
116
|
GET /schemas/posts/create.json
|
117
|
+
GET /schemas/posts/create
|
117
118
|
|
118
119
|
# Get `app/schemas/posts/update.*` as text/yaml
|
119
120
|
GET /schemas/posts/update.yaml
|
120
121
|
```
|
121
122
|
|
123
|
+
To get a path to a specific schema's endpoint, call `json_schema_rails.schema_path(schema_name)` or `json_schema_rails.schema_url(schema_name)`.
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
# In your controller or view
|
127
|
+
json_schema_rails.schema_path("posts/create") # "/schemas/posts/create"
|
128
|
+
json_schema_rails.schema_url("posts/update") # "http://example.com/schemas/posts/create"
|
129
|
+
```
|
130
|
+
|
131
|
+
You can change `json_schema_rails` part of above by specifying `as` parameter when mounting the route:
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
Your::Application.routes.draw do
|
135
|
+
mount JsonSchemaRails::Engine => '/schemas', as: 'json_schema'
|
136
|
+
end
|
137
|
+
|
138
|
+
# And you can call the helpers as
|
139
|
+
json_schema.schema_path("posts/create")
|
140
|
+
json_schema.schema_url("posts/update")
|
141
|
+
```
|
142
|
+
|
122
143
|
### Validate schema files
|
123
144
|
|
124
145
|
json_schema_rails provides a rake task `schema:check` to validate your schema files.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module JsonSchemaRails
|
2
2
|
class SchemasController < ApplicationController
|
3
|
-
def
|
4
|
-
schema = JsonSchemaRails.lookup_schema(params[:
|
3
|
+
def show
|
4
|
+
schema = JsonSchemaRails.lookup_schema(params[:id])
|
5
5
|
raise ActionController::RoutingError.new('No Such Schema') unless schema
|
6
6
|
|
7
7
|
respond_to do |format|
|
data/config/routes.rb
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
class HelpersController < ApplicationController
|
2
|
+
def show_schema_path
|
3
|
+
path = json_schema_rails.schema_path(params[:schema_name])
|
4
|
+
render text: path
|
5
|
+
end
|
6
|
+
|
7
|
+
def show_schema_url
|
8
|
+
url = json_schema_rails.schema_url(params[:schema_name])
|
9
|
+
render text: url
|
10
|
+
end
|
11
|
+
end
|
@@ -2,6 +2,9 @@ Dummy::Application.routes.draw do
|
|
2
2
|
mount JsonSchemaRails::Engine => '/schemas'
|
3
3
|
resources :posts, only: [:create, :update]
|
4
4
|
|
5
|
+
get 'helpers/schema_path', to: 'helpers#show_schema_path'
|
6
|
+
get 'helpers/schema_url', to: 'helpers#show_schema_url'
|
7
|
+
|
5
8
|
# The priority is based upon order of creation:
|
6
9
|
# first created -> highest priority.
|
7
10
|
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class HelpersController < ApplicationController
|
2
|
+
def show_schema_path
|
3
|
+
path = json_schema_rails.schema_path(params[:schema_name])
|
4
|
+
render text: path
|
5
|
+
end
|
6
|
+
|
7
|
+
def show_schema_url
|
8
|
+
url = json_schema_rails.schema_url(params[:schema_name])
|
9
|
+
render text: url
|
10
|
+
end
|
11
|
+
end
|
@@ -2,6 +2,9 @@ Rails.application.routes.draw do
|
|
2
2
|
mount JsonSchemaRails::Engine => '/schemas'
|
3
3
|
resources :posts, only: [:create, :update]
|
4
4
|
|
5
|
+
get 'helpers/schema_path', to: 'helpers#show_schema_path'
|
6
|
+
get 'helpers/schema_url', to: 'helpers#show_schema_url'
|
7
|
+
|
5
8
|
# The priority is based upon order of creation: first created -> highest priority.
|
6
9
|
# See how all your routes lay out with "rake routes".
|
7
10
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe HelpersController, type: :controller do
|
4
|
+
describe "schema_path helper" do
|
5
|
+
it "returns a path to schema endpoint" do
|
6
|
+
get "show_schema_path", { "schema_name" => "posts/create" }
|
7
|
+
expect(response.body).to eq "/schemas/posts/create"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "schema_url helper" do
|
12
|
+
it "returns a URL to schema endpoint" do
|
13
|
+
get "show_schema_url", { "schema_name" => "posts/create" }
|
14
|
+
expect(response.body).to eq "#{request.base_url}/schemas/posts/create"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -3,11 +3,20 @@ require 'spec_helper'
|
|
3
3
|
RSpec.describe JsonSchemaRails::SchemasController, type: :request do
|
4
4
|
describe "GET #get" do
|
5
5
|
context "with existing schema" do
|
6
|
-
before { get "/schemas/posts/create
|
6
|
+
before { get "/schemas/posts/create#{format}" }
|
7
7
|
let(:expected_schema) { YAML.load_file(Rails.root.join('app', 'schemas', 'posts', 'create.yml').to_s) }
|
8
8
|
|
9
9
|
context "as json" do
|
10
|
-
let(:format) { "json" }
|
10
|
+
let(:format) { ".json" }
|
11
|
+
it "returns the schema as json" do
|
12
|
+
expect(response).to be_success
|
13
|
+
expect(response.content_type).to eq :json
|
14
|
+
expect(response.body).to eq expected_schema.to_json
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "without format" do
|
19
|
+
let(:format) { "" }
|
11
20
|
it "returns the schema as json" do
|
12
21
|
expect(response).to be_success
|
13
22
|
expect(response.content_type).to eq :json
|
@@ -16,7 +25,7 @@ RSpec.describe JsonSchemaRails::SchemasController, type: :request do
|
|
16
25
|
end
|
17
26
|
|
18
27
|
context "as yaml" do
|
19
|
-
let(:format) { "yaml" }
|
28
|
+
let(:format) { ".yaml" }
|
20
29
|
it "returns the schema as yaml" do
|
21
30
|
expect(response).to be_success
|
22
31
|
expect(response.content_type).to eq :yaml
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_schema_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kota Saito
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -209,6 +209,7 @@ files:
|
|
209
209
|
- spec/dummy_apps/rails3/app/assets/javascripts/application.js
|
210
210
|
- spec/dummy_apps/rails3/app/assets/stylesheets/application.css
|
211
211
|
- spec/dummy_apps/rails3/app/controllers/application_controller.rb
|
212
|
+
- spec/dummy_apps/rails3/app/controllers/helpers_controller.rb
|
212
213
|
- spec/dummy_apps/rails3/app/controllers/posts_controller.rb
|
213
214
|
- spec/dummy_apps/rails3/app/helpers/application_helper.rb
|
214
215
|
- spec/dummy_apps/rails3/app/schemas/posts/create.yml
|
@@ -248,6 +249,7 @@ files:
|
|
248
249
|
- spec/dummy_apps/rails4/app/assets/stylesheets/posts.css
|
249
250
|
- spec/dummy_apps/rails4/app/controllers/application_controller.rb
|
250
251
|
- spec/dummy_apps/rails4/app/controllers/concerns/.keep
|
252
|
+
- spec/dummy_apps/rails4/app/controllers/helpers_controller.rb
|
251
253
|
- spec/dummy_apps/rails4/app/controllers/posts_controller.rb
|
252
254
|
- spec/dummy_apps/rails4/app/helpers/application_helper.rb
|
253
255
|
- spec/dummy_apps/rails4/app/mailers/.keep
|
@@ -288,6 +290,7 @@ files:
|
|
288
290
|
- spec/fixtures/schemas/posts/search.json
|
289
291
|
- spec/fixtures/schemas/posts/update.yaml
|
290
292
|
- spec/fixtures/schemas/syntax_error.json
|
293
|
+
- spec/integration/helpers_controller_spec.rb
|
291
294
|
- spec/integration/posts_controller_spec.rb
|
292
295
|
- spec/integration/schemas_controller_spec.rb
|
293
296
|
- spec/lib/json_schema_rails/json_schema/parser_spec.rb
|
@@ -327,6 +330,7 @@ test_files:
|
|
327
330
|
- spec/dummy_apps/rails3/app/assets/javascripts/application.js
|
328
331
|
- spec/dummy_apps/rails3/app/assets/stylesheets/application.css
|
329
332
|
- spec/dummy_apps/rails3/app/controllers/application_controller.rb
|
333
|
+
- spec/dummy_apps/rails3/app/controllers/helpers_controller.rb
|
330
334
|
- spec/dummy_apps/rails3/app/controllers/posts_controller.rb
|
331
335
|
- spec/dummy_apps/rails3/app/helpers/application_helper.rb
|
332
336
|
- spec/dummy_apps/rails3/app/schemas/posts/create.yml
|
@@ -366,6 +370,7 @@ test_files:
|
|
366
370
|
- spec/dummy_apps/rails4/app/assets/stylesheets/posts.css
|
367
371
|
- spec/dummy_apps/rails4/app/controllers/application_controller.rb
|
368
372
|
- spec/dummy_apps/rails4/app/controllers/concerns/.keep
|
373
|
+
- spec/dummy_apps/rails4/app/controllers/helpers_controller.rb
|
369
374
|
- spec/dummy_apps/rails4/app/controllers/posts_controller.rb
|
370
375
|
- spec/dummy_apps/rails4/app/helpers/application_helper.rb
|
371
376
|
- spec/dummy_apps/rails4/app/mailers/.keep
|
@@ -406,6 +411,7 @@ test_files:
|
|
406
411
|
- spec/fixtures/schemas/posts/search.json
|
407
412
|
- spec/fixtures/schemas/posts/update.yaml
|
408
413
|
- spec/fixtures/schemas/syntax_error.json
|
414
|
+
- spec/integration/helpers_controller_spec.rb
|
409
415
|
- spec/integration/posts_controller_spec.rb
|
410
416
|
- spec/integration/schemas_controller_spec.rb
|
411
417
|
- spec/lib/json_schema_rails/json_schema/parser_spec.rb
|