wadl_generator 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.markdown +64 -0
- data/Rakefile +2 -0
- data/lib/wadl/generator.rb +78 -0
- data/lib/wadl_generator.rb +1 -0
- data/wadl_generator.gemspec +21 -0
- metadata +74 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# WADL Generator
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
# Gemfile
|
6
|
+
gem 'wadl_generator'
|
7
|
+
|
8
|
+
## Usage / Example
|
9
|
+
|
10
|
+
#### config/routes.rb
|
11
|
+
|
12
|
+
namespace 'api' do
|
13
|
+
namespace 'v1' do
|
14
|
+
get 'description.:format' => 'base#description'
|
15
|
+
resources :posts, :only => [:index, :show]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
#### app/controllers/api/v1/base_controller.rb
|
20
|
+
|
21
|
+
class Api::V1::BaseController < ApplicationController
|
22
|
+
def description
|
23
|
+
respond_to do |format|
|
24
|
+
format.html do
|
25
|
+
render :text => %q{<iframe src="http://apigee.com/<user>/embed/console/<name>"
|
26
|
+
width="100%" height="95%"></iframe>}
|
27
|
+
end
|
28
|
+
|
29
|
+
format.wadl do
|
30
|
+
render :text => WADL::Generator.new(wadl_description, :apigee => true),
|
31
|
+
:content_type => 'application/xml'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def wadl_description
|
39
|
+
{
|
40
|
+
:base => "#{request.url.gsub('/description.wadl', '')}",
|
41
|
+
:resources => {
|
42
|
+
'posts' => {
|
43
|
+
:index_formats => {
|
44
|
+
:json => 'application/json',
|
45
|
+
},
|
46
|
+
:show_formats => {
|
47
|
+
:json => 'application/json',
|
48
|
+
:html => 'application/html',
|
49
|
+
:pdf => 'application/pdf',
|
50
|
+
},
|
51
|
+
:example_id => 28,
|
52
|
+
},
|
53
|
+
}
|
54
|
+
}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
## Todos
|
59
|
+
|
60
|
+
* Add tests
|
61
|
+
|
62
|
+
## License
|
63
|
+
|
64
|
+
MIT License - Thomas Maurer
|
data/Rakefile
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
module WADL
|
2
|
+
class Generator
|
3
|
+
VERSION = '0.1.0'
|
4
|
+
|
5
|
+
attr_reader :description, :options, :wadl
|
6
|
+
|
7
|
+
def initialize(description, options = {})
|
8
|
+
@description, @options, @wadl = description, options, ''
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_text
|
12
|
+
generate
|
13
|
+
@wadl
|
14
|
+
end
|
15
|
+
|
16
|
+
def generate
|
17
|
+
xml = Builder::XmlMarkup.new :indent => 2, :target => @wadl
|
18
|
+
xml.instruct!
|
19
|
+
|
20
|
+
namespaces = {
|
21
|
+
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
|
22
|
+
'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
|
23
|
+
'xsi:schemaLocation' => 'http://wadl.dev.java.net/2009/02',
|
24
|
+
'xmlns' => 'http://wadl.dev.java.net/2009/02',
|
25
|
+
}
|
26
|
+
|
27
|
+
if options[:apigee]
|
28
|
+
namespaces['xmlns:apigee'] = 'http://api.apigee.com/wadl/2010/07/'
|
29
|
+
namespaces['xsi:schemaLocation'] << ' http://apigee.com/schemas/wadl-schema.xsd http://api.apigee.com/wadl/2010/07/ http://apigee.com/schemas/apigee-wadl-extensions.xsd'
|
30
|
+
end
|
31
|
+
|
32
|
+
xml.application(namespaces) do
|
33
|
+
xml.resources(:base => description[:base]) do
|
34
|
+
description[:resources].each do |name, config|
|
35
|
+
# index
|
36
|
+
xml.resource(:path => "#{name.pluralize.underscore}.{format}") do
|
37
|
+
xml.param(:name => 'format', :type => 'xsd:string', :style => 'template',
|
38
|
+
:required => true, :default => config[:index_formats].keys.first) do
|
39
|
+
config[:index_formats].each do |format, mime_type|
|
40
|
+
xml.option(:value => format, :mediaType => mime_type)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
xml.method('id' => name.pluralize.underscore, 'name' => 'GET') do
|
45
|
+
if options[:agigee]
|
46
|
+
xml.tag!('apigee:tags') { xml.tag!('apigee:tag', name.singularize.camelcase, :primary => true) }
|
47
|
+
xml.tag!('apigee:authentication', :required => false)
|
48
|
+
xml.tag!('apigee:example', :url => "/#{name.pluralize.underscore}.#{config[:index_formats].keys.first}")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# show
|
54
|
+
xml.resource(:path => "#{name.pluralize.underscore}/{id}.{format}") do
|
55
|
+
xml.param(:name => 'format', :type => 'xsd:string', :style => 'template',
|
56
|
+
:required => true, :default => config[:show_formats].keys.first) do
|
57
|
+
config[:show_formats].each do |format, mime_type|
|
58
|
+
xml.option(:value => format, :mediaType => mime_type)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
xml.param(:name => 'id', :type => 'xsd:string', :style => 'query', :required => true)
|
62
|
+
|
63
|
+
xml.method('id' => name.singularize.underscore, 'name' => 'GET') do
|
64
|
+
if options[:agigee]
|
65
|
+
xml.tag!('apigee:tags') { xml.tag!('apigee:tag', name.singularize.camelcase, :primary => true) }
|
66
|
+
xml.tag!('apigee:authentication', :required => false)
|
67
|
+
xml.tag!('apigee:example', :url => "/#{name.pluralize.underscore}/#{config[:example_id]}.#{config[:show_formats].keys.first}")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
self
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'wadl/generator'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "wadl/generator"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "wadl_generator"
|
7
|
+
s.version = WADL::Generator::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Thomas Maurer"]
|
10
|
+
s.email = ["tma@freshbit.ch"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Simple WADL Generator targeted on REST APIs with optional Apigee Flavour}
|
13
|
+
s.description = %q{Simple WADL Generator targeted on REST APIs with optional Apigee Flavour}
|
14
|
+
|
15
|
+
s.rubyforge_project = "wadl_generator"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wadl_generator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Thomas Maurer
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-03-10 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Simple WADL Generator targeted on REST APIs with optional Apigee Flavour
|
23
|
+
email:
|
24
|
+
- tma@freshbit.ch
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- README.markdown
|
35
|
+
- Rakefile
|
36
|
+
- lib/wadl/generator.rb
|
37
|
+
- lib/wadl_generator.rb
|
38
|
+
- wadl_generator.gemspec
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: ""
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
hash: 3
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 3
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project: wadl_generator
|
69
|
+
rubygems_version: 1.5.3
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Simple WADL Generator targeted on REST APIs with optional Apigee Flavour
|
73
|
+
test_files: []
|
74
|
+
|