prmd 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b88e4f305b59c16a0117cfb8a91f5fa890ed4431
4
- data.tar.gz: a13809a6a6d33936359c7ab04248dd6d43a4b798
3
+ metadata.gz: f1daeca9c90d711692403468076030d0634b25e3
4
+ data.tar.gz: 76efedd3c3af5cbe612fb184e73e34b15bf69070
5
5
  SHA512:
6
- metadata.gz: 705022feeb033937ef9c2c08257f9cd4daefd7ea369fe05dce114ced1af67305fcf2060c559ca60519e2d64ef0f0b1b5652e957c94c3e711f2cad773c3beec47
7
- data.tar.gz: 2277f2883652417e4dbe0fd0064dea23997def5044622c641a1684ee537795c81f3c0ab54d6f79675006bf796f9e924d7ceec71e63150b59763c2e0c71599323
6
+ metadata.gz: e6eb7a54f6172d8098800ff3f61d61b7d1d139effb12ad4615a16686a2d18051fd1a0acfd492901005380a3348a73d2bdc3d402832b12618cc62c6e0a1fdb43e
7
+ data.tar.gz: 2ae5d2cbbecf6361f5287e1876ba7ac33f8ec72971f9897e1044e7473b33310ac67f3db3b9a2ff9490c7f6e7c979e0f6a8832297cc141290239f1f2bbf13b0a1
@@ -141,6 +141,8 @@ Links that expect a custom http header MUST include the following attributes:
141
141
  }
142
142
  ```
143
143
 
144
+ Links MAY specify a different serialization than defined in [properties](#properties) via `targetSchema`.
145
+
144
146
  ### `properties`
145
147
 
146
148
  Properties defines the attributes that exist in the serialization of the object.
@@ -3,6 +3,7 @@ require_relative 'cli/combine'
3
3
  require_relative 'cli/doc'
4
4
  require_relative 'cli/generate'
5
5
  require_relative 'cli/render'
6
+ require_relative 'cli/stub'
6
7
  require_relative 'cli/verify'
7
8
 
8
9
  # :nodoc:
@@ -17,6 +18,7 @@ module Prmd
17
18
  doc: CLI::Doc.make_parser(props),
18
19
  init: CLI::Generate.make_parser(props),
19
20
  render: CLI::Render.make_parser(props),
21
+ stub: CLI::Stub.make_parser(props),
20
22
  verify: CLI::Verify.make_parser(props)
21
23
  }
22
24
  end
@@ -95,6 +97,8 @@ module Prmd
95
97
  CLI::Generate.run(argv, options)
96
98
  when :render
97
99
  CLI::Render.run(argv, options)
100
+ when :stub
101
+ CLI::Stub.run(argv, options)
98
102
  when :verify
99
103
  CLI::Verify.run(argv, options)
100
104
  end
@@ -18,6 +18,9 @@ module Prmd
18
18
 
19
19
  OptionParser.new do |opts|
20
20
  opts.banner = "#{binname} init [options] <resource name>"
21
+ opts.on('-t', '--template templates', String, 'Use alternate template') do |t|
22
+ yield :template, t
23
+ end
21
24
  opts.on('-y', '--yaml', 'Generate YAML') do |y|
22
25
  yield :yaml, y
23
26
  end
@@ -0,0 +1,45 @@
1
+ require_relative 'base'
2
+
3
+ module Prmd
4
+ module CLI
5
+ # 'stub' command module'
6
+ module Stub
7
+ extend CLI::Base
8
+
9
+ # Returns a OptionParser for parsing 'stub' command options.
10
+ #
11
+ # @param (see Prmd::CLI::Base#make_parser)
12
+ # @return (see Prmd::CLI::Base#make_parser)
13
+ def self.make_parser(options = {})
14
+ binname = options.fetch(:bin, 'prmd')
15
+
16
+ OptionParser.new do |opts|
17
+ opts.banner = "#{binname} stub [options] <combined schema>"
18
+ end
19
+ end
20
+
21
+ # Executes the 'stub' command.
22
+ #
23
+ # @example Usage
24
+ # Prmd::CLI::Stub.execute(argv: ['schema/api.json'])
25
+ #
26
+ # @param (see Prmd::CLI::Base#execute)
27
+ # @return (see Prmd::CLI::Base#execute)
28
+ def self.execute(options = {})
29
+ require "committee"
30
+
31
+ filename = options.fetch(:argv).first
32
+ _, schema = try_read(filename)
33
+
34
+ app = Rack::Builder.new {
35
+ use Committee::Middleware::RequestValidation, schema: schema
36
+ use Committee::Middleware::ResponseValidation, schema: schema
37
+ use Committee::Middleware::Stub, schema: schema
38
+ run lambda { |_| [404, {}, ["Not found"]] }
39
+ }
40
+
41
+ Rack::Server.start(app: app)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -79,7 +79,16 @@ module Prmd
79
79
  base = Prmd::Template.load_json('combine_head.json')
80
80
  schema = base['$schema']
81
81
  meta = {}
82
- meta = Prmd.load_schema_file(options[:meta]) if options[:meta]
82
+ filename = options[:meta]
83
+ meta = Prmd.load_schema_file(filename) if filename
84
+ if meta.nil? || meta.empty?
85
+ if filename
86
+ warn "Meta file (#{filename}) is empty, please fill it next time."
87
+ else
88
+ warn "Meta is empty, please fill it next time."
89
+ end
90
+ meta ||= {}
91
+ end
83
92
  combiner = Prmd::Combiner.new(meta: meta, base: base, schema: schema)
84
93
  combiner.combine(*schemata)
85
94
  end
@@ -9,9 +9,21 @@ module Prmd
9
9
  # Creates a default Prmd::Generator using default templates
10
10
  #
11
11
  # @return [Prmd::Generator]
12
- def self.make_generator
12
+ def self.make_generator(options)
13
13
  base = Prmd::Template.load_json('init_default.json')
14
- template = Prmd::Template.load_template('init_resource.json.erb', '')
14
+ template_name = options.fetch(:template) do
15
+ abort 'render: Template was not provided'
16
+ end
17
+ if template_name && !template_name.empty?
18
+ template_dir = File.expand_path(template_name)
19
+ # to keep backward compatibility
20
+ template_dir = File.dirname(template_name) unless File.directory?(template_dir)
21
+ template_name = File.basename(template_name)
22
+ else
23
+ template_name = 'init_resource.json.erb'
24
+ template_dir = ''
25
+ end
26
+ template = Prmd::Template.load_template(template_name, template_dir)
15
27
  Prmd::Generator.new(base: base, template: template)
16
28
  end
17
29
  end
@@ -22,7 +34,7 @@ module Prmd
22
34
  # @param [Hash<Symbol, Object>] options
23
35
  # @return [String] schema template in YAML (yaml option was enabled) else JSON
24
36
  def self.init(resource, options = {})
25
- gen = Generate.make_generator
37
+ gen = Generate.make_generator(template: options[:template])
26
38
 
27
39
  generator_options = { resource: nil, parent: nil }
28
40
  if resource
@@ -1,3 +1,5 @@
1
+ require 'ostruct'
2
+
1
3
  module Prmd
2
4
  class Link
3
5
  def initialize(link_schema)
@@ -126,6 +126,8 @@ module Prmd
126
126
  else
127
127
  [schema_example(items)]
128
128
  end
129
+ elsif value.key?('enum')
130
+ value['enum'][0]
129
131
  elsif DefaultExamples.key?(value["format"])
130
132
  DefaultExamples[value["format"]]
131
133
  elsif DefaultExamples.key?(value["type"][0])
@@ -45,8 +45,7 @@
45
45
  end
46
46
  attributes.concat(nested)
47
47
 
48
- # found an array with nested objects
49
- elsif value['items']
48
+ elsif array_with_nested_objects?(value['items'])
50
49
  if value['items']['properties']
51
50
  nested = extract_attributes(schema, value['items']['properties'])
52
51
  nested.each do |attribute|
@@ -164,8 +163,8 @@
164
163
  else
165
164
  "`#{value['example'].to_json}`"
166
165
  end
167
- elsif value['type'] == ['array'] && value.has_key?('items')
168
- example = "`#{schema.schema_value_example(value)}`"
166
+ elsif (value['type'] == ['array'] && value.has_key?('items')) || value.has_key?('enum')
167
+ example = "`#{schema.schema_value_example(value).to_json}`"
169
168
  elsif value['type'].include?('null')
170
169
  example = "`null`"
171
170
  end
@@ -192,4 +191,9 @@
192
191
  end
193
192
  end
194
193
  end
194
+
195
+ def array_with_nested_objects?(items)
196
+ return unless items
197
+ items['properties'] || items['oneOf']
198
+ end
195
199
  %>
@@ -2,7 +2,7 @@
2
2
  module Prmd
3
3
  # Well, duh, its a Version module, what did you expect?
4
4
  module Version
5
- MAJOR, MINOR, TEENY, PATCH = 0, 8, 0, nil
5
+ MAJOR, MINOR, TEENY, PATCH = 0, 9, 0, nil
6
6
  # version string
7
7
  # @return [String]
8
8
  STRING = [MAJOR, MINOR, TEENY, PATCH].compact.join('.').freeze
@@ -66,7 +66,7 @@
66
66
  },
67
67
  "properties": {
68
68
  "patternProperties": {
69
- "^[a-z][a-z_]*[a-z]$": {
69
+ "^[a-z][a-zA-Z_]*[a-zA-Z]$": {
70
70
  "$ref": "#/definitions/resourceProperty"
71
71
  }
72
72
  },
@@ -107,18 +107,23 @@
107
107
  "resourceLink": {
108
108
  "properties": {
109
109
  "href": {
110
- "pattern": "^(/([a-z0-9][a-z0-9_\\-]*[a-z0-9]|\\{\\(.*\\)\\}))+$"
110
+ "pattern": "^(\/((?!-|_)[a-z0-9_\\-]+(?<!-|_)|\\{\\(.*\\)\\}))+$"
111
111
  },
112
112
  "schema": {
113
113
  "anyOf": [
114
114
  {
115
- "required": ["properties"]
115
+ "$ref": "#/definitions/ref"
116
+ },
117
+ {
118
+ "required": ["items", "type"]
119
+ },
120
+ {
121
+ "required": ["properties", "type"]
116
122
  },
117
123
  {
118
- "required": ["patternProperties"]
124
+ "required": ["patternProperties", "type"]
119
125
  }
120
- ],
121
- "required": ["type"]
126
+ ]
122
127
  }
123
128
  },
124
129
  "required": ["description", "href", "method", "rel", "title"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prmd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - geemus
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-12 00:00:00.000000000 Z
11
+ date: 2015-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubis
@@ -111,6 +111,7 @@ files:
111
111
  - lib/prmd/cli/doc.rb
112
112
  - lib/prmd/cli/generate.rb
113
113
  - lib/prmd/cli/render.rb
114
+ - lib/prmd/cli/stub.rb
114
115
  - lib/prmd/cli/verify.rb
115
116
  - lib/prmd/commands.rb
116
117
  - lib/prmd/commands/combine.rb
@@ -207,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
207
208
  version: '0'
208
209
  requirements: []
209
210
  rubyforge_project:
210
- rubygems_version: 2.2.2
211
+ rubygems_version: 2.4.5.1
211
212
  signing_key:
212
213
  specification_version: 4
213
214
  summary: JSON Schema tooling