prmd 0.7.3 → 0.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 991f3f369ace8993454c827543547b3d3b16dd79
4
- data.tar.gz: b75648a1d59e295af15f91ff05386cb946547b96
3
+ metadata.gz: 74cb8c4e07101320893a1a99c2cbbdb9d1db05e9
4
+ data.tar.gz: 54623e6a8c00abdc86f1800d327df8fe091f8b5f
5
5
  SHA512:
6
- metadata.gz: ccc994060505e113f80b4709e6ae1bef92ae070182f3d8901028bd94b00c9b55cf2aefffdad68c4dc52b412de84b810c6cdaa084e6ad84a0c9eec78756958625
7
- data.tar.gz: 8d773628f0cc4e02e42bd8cc39d8baa0ea2b4726890e5308a38cd45c3c74a68d2c51782eeec2684cee985b5d3e97cd1a5854bb21d991ca7d5d77b8bc3255d1e3
6
+ metadata.gz: cf7f7a284348b34634f2ee4ce6c6135fecd460b1d1be153477fd9a8d1a29e5537cbe9d5150bdacfec2c38844b0b0eb71c8f5c4488d20be204026a97e757867e3
7
+ data.tar.gz: 6075c2f9d282c53f7317ae6c41ba0411f9793e0a4ce755edc14567a5fecc2ca404462f78aa574011b9206e407dba74f24d309a2070df839b73fe9bc0f82fecf8
@@ -4,14 +4,12 @@
4
4
  "definitions": {
5
5
  "id": {
6
6
  "description": "unique identifier of <%= resource %>",
7
- "example": "01234567-89ab-cdef-0123-456789abcdef",
8
7
  "readOnly": true,
9
8
  "format": "uuid",
10
9
  "type": ["string"]
11
10
  },
12
11
  "name": {
13
12
  "description": "unique name of <%= resource %>",
14
- "example": "name",
15
13
  "readOnly": true,
16
14
  "type": ["string"]
17
15
  },
@@ -27,13 +25,11 @@
27
25
  },
28
26
  "created_at": {
29
27
  "description": "when <%= resource %> was created",
30
- "example": "2012-01-01T12:00:00Z",
31
28
  "format": "date-time",
32
29
  "type": ["string"]
33
30
  },
34
31
  "updated_at": {
35
32
  "description": "when <%= resource %> was updated",
36
- "example": "2012-01-01T12:00:00Z",
37
33
  "format": "date-time",
38
34
  "type": ["string"]
39
35
  }
@@ -1,6 +1,4 @@
1
1
  <%-
2
- return unless schemata.has_key?('links') && !schemata['links'].empty?
3
-
4
2
  Prmd::Template.render('schemata/helper.erb', options[:template], {
5
3
  options: options,
6
4
  resource: resource,
@@ -11,7 +9,7 @@
11
9
  title = schemata['title'].split(' - ', 2).last
12
10
  -%>
13
11
  <%- unless options[:doc][:disable_title_and_description] %>
14
- ## <%= title %>
12
+ ## <a name="resource-<%= resource %>"></a><%= title %>
15
13
 
16
14
  <%= schemata['description'] %>
17
15
  <%- end -%>
@@ -21,12 +19,18 @@
21
19
 
22
20
  | Name | Type | Description | Example |
23
21
  | ------- | ------- | ------- | ------- |
24
- <%- extract_attributes(schema, schemata['properties']).each do |(key, type, description, example)| %>
25
- | **<%= key %>** | *<%= type %>* | <%= description %> | <%= example %> |
22
+ <%- refs = extract_schemata_refs(schema, schemata['properties']).map {|v| v && v.split("/")} %>
23
+ <%- extract_attributes(schema, schemata['properties']).each_with_index do |(key, type, description, example), i| %>
24
+ <%- if refs[i] && refs[i][1] == "definitions" && refs[i][2] != resource %>
25
+ <%- name = '[%s](#%s)' % [key, 'resource-' + refs[i][2]] %>
26
+ <%- else %>
27
+ <%- name = key %>
28
+ <%- end %>
29
+ | **<%= name %>** | *<%= type %>* | <%= description %> | <%= example %> |
26
30
  <%- end %>
27
31
 
28
32
  <%- end %>
29
- <%- schemata['links'].each do |link, datum| %>
33
+ <%- (schemata['links'] || []).each do |link, datum| %>
30
34
  <%=
31
35
  Prmd::Template.render('schemata/link.md.erb', options[:template], {
32
36
  options: options,
@@ -58,13 +58,45 @@
58
58
  end
59
59
  attributes.map! { |key, type, description, example|
60
60
  if example.nil? && Prmd::DefaultExamples.key?(type)
61
- example = Prmd::DefaultExamples[type]
61
+ example = "`%s`" % Prmd::DefaultExamples[type].to_json
62
62
  end
63
63
  [key, type, description, example]
64
64
  }
65
65
  return attributes
66
66
  end
67
67
 
68
+ def extract_schemata_refs(schema, properties)
69
+ ret = []
70
+ properties.each do |_, value|
71
+ ref, value = schema.dereference(value)
72
+ if value['properties']
73
+ refs = extract_schemata_refs(schema, value['properties'])
74
+ elsif value['items'] && value['items']['properties']
75
+ refs = extract_schemata_refs(schema, value['items']['properties'])
76
+ else
77
+ refs = [ref]
78
+ end
79
+ if value.has_key?('type') && value['type'].include?('null') && (value.has_key?('items') || value.has_key?('properties'))
80
+ # A nullable object usually isn't a reference to another schema. It's
81
+ # either not a reference at all, or it's a reference within the same
82
+ # schema. Instead, the definition of the nullable object might contain
83
+ # references to specific properties.
84
+ #
85
+ # If all properties refer to the same schema, we'll use that as the
86
+ # reference. This might even overwrite an actual, intra-schema
87
+ # reference.
88
+
89
+ l = refs.map {|v| v && v.split("/")[0..2]}
90
+ if l.uniq.size == 1 && l[0] != nil
91
+ ref = l[0].join("/")
92
+ end
93
+ ret << ref
94
+ end
95
+ ret.concat(refs)
96
+ end
97
+ ret
98
+ end
99
+
68
100
  def build_attribute(schema, key, value)
69
101
  description = value['description'] || ""
70
102
  if value['default']
@@ -64,6 +64,7 @@ HTTP/1.1 <%=
64
64
  <%- end %>
65
65
  ```
66
66
 
67
+ <%- if response_example || link['rel'] != 'empty' %>
67
68
  ```json
68
69
  <%- if response_example %>
69
70
  <%= response_example['body'] %>
@@ -78,3 +79,4 @@ HTTP/1.1 <%=
78
79
  <%- end %>
79
80
  <%- end %>
80
81
  ```
82
+ <%- end %>
@@ -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, 7, 3, nil
5
+ MAJOR, MINOR, TEENY, PATCH = 0, 7, 4, nil
6
6
  # version string
7
7
  # @return [String]
8
8
  STRING = [MAJOR, MINOR, TEENY, PATCH].compact.join('.').freeze
@@ -10,6 +10,9 @@
10
10
  "definitions": {
11
11
  "identity": {
12
12
  "anyOf": [
13
+ {
14
+ "$ref": "#/definitions/ref"
15
+ },
13
16
  {
14
17
  "additionalProperties": false,
15
18
  "properties": {
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.7.3
4
+ version: 0.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - geemus
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-13 00:00:00.000000000 Z
11
+ date: 2015-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubis