ftr_ruby 0.1.8 → 0.1.10

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
  SHA256:
3
- metadata.gz: 476f26ca6810bd7111ed4a35329d6f054adf12d70e80efed0d90618fd922a621
4
- data.tar.gz: 9863bb01606fd966e7595e73439486bf86ea7fe78c981b544bdc4d9f7c94ec61
3
+ metadata.gz: e667a36034df0b5e34edc576681737cb36d010ad54ae6f71a9254823438ddf0e
4
+ data.tar.gz: 48b56876e75bc26dd80c430f9a0e242538895aa239e5290ebbdd77253010bb64
5
5
  SHA512:
6
- metadata.gz: 33aefb062131b7dbfc017639d8f9e7d2763d27399f93f42f6b0e5d3e2dce2678881cacd284f1e20650967716486c58bedf0f9c27502c39009214d986d715bbc0
7
- data.tar.gz: fe77d4b8418bd8284b8bb269c72c184d30e5aa207f7302e63012e845bab9384ae75d0bbe2f200b5ab00f6e3fcb50414af0bdc6c4e57f9d2b2ec8d1e18c0415c9
6
+ metadata.gz: c26ebde15b974102fbf169f7d4a60118cdde56ceaa041306f5edf8c81f8c260b0deb389b1e36d9e7a5fbd4c11ca7e2f729dfdbd24bf59560a82f8c62d5f8de1a
7
+ data.tar.gz: 6c5746418ab0aba173c1cd8f975ecaf71b4df961cc365570873d795b75d6ee414080ab2c78a253f3c4c58e07a713bc2800b4d0ce806659628749b2c7ef124568
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FtrRuby
4
- VERSION = "0.1.8"
4
+ VERSION = "0.1.10"
5
5
  end
data/lib/openapi.rb CHANGED
@@ -1,10 +1,26 @@
1
1
  module FtrRuby
2
+ # Generates a valid OpenAPI 3.0 YAML document describing a single FAIR test endpoint.
3
+ #
4
+ # The document is built from metadata supplied by the test author (title, description,
5
+ # contact info, etc.) and is served as a machine-readable API specification that client
6
+ # UIs fetch to dynamically build submission forms.
7
+ #
8
+ # Key concern: author-supplied text (especially +description+) may contain arbitrary
9
+ # Markdown, including blank lines and heading markers (##). YAML block scalars require
10
+ # every continuation line to be indented at least as deeply as the first content line;
11
+ # raw multi-line strings break this rule. All free-text fields are therefore passed
12
+ # through +yaml_block_indent+ before interpolation.
2
13
  class OpenAPI
3
14
  attr_accessor :title, :metric, :description, :indicator, :testid,
4
15
  :organization, :org_url, :version, :creator,
5
16
  :responsible_developer, :email, :developer_ORCiD, :protocol,
6
17
  :host, :basePath, :path, :response_description, :schemas, :endpointpath
7
18
 
19
+ # Initialises the OpenAPI document from a metadata hash.
20
+ #
21
+ # @param meta [Hash] keys: :testid, :testname, :testversion, :metric, :description,
22
+ # :indicators, :organization, :org_url, :responsible_developer, :email, :creator,
23
+ # :host, :protocol, :basePath, :response_description, :schemas
8
24
  def initialize(meta:)
9
25
  indics = [meta[:indicators]] unless meta[:indicators].is_a? Array
10
26
  @testid = meta[:testid]
@@ -30,7 +46,14 @@ module FtrRuby
30
46
  # @end_url = "#{protocol}://#{host}#{basePath}/#{endpointpath}/#{testid}" # basepath starts with /
31
47
  end
32
48
 
49
+ # Returns the complete OpenAPI 3.0 YAML document as a String.
50
+ #
51
+ # Free-text fields that may contain Markdown (description, response_description) are
52
+ # pre-processed with +yaml_block_indent+ so that embedded newlines do not escape the
53
+ # YAML block scalar — see that method for details.
33
54
  def get_api
55
+ safe_desc = yaml_block_indent(description, 4)
56
+ safe_resp = yaml_block_indent(response_description, 12)
34
57
  <<~"EOF_EOF"
35
58
 
36
59
  openapi: 3.0.0
@@ -39,7 +62,7 @@ module FtrRuby
39
62
  title: "#{title}"
40
63
  x-tests_metric: "#{metric}"
41
64
  description: >-
42
- "#{description}"
65
+ #{safe_desc}
43
66
  x-applies_to_principle: "#{indicator}"
44
67
  contact:
45
68
  x-organization: "#{organization}"
@@ -60,7 +83,7 @@ module FtrRuby
60
83
  responses:
61
84
  "200":
62
85
  description: >-
63
- #{response_description}
86
+ #{safe_resp}
64
87
  servers:
65
88
  - url: "#{protocol}://#{host}#{basePath}/#{endpointpath}"
66
89
  components:
@@ -69,11 +92,35 @@ module FtrRuby
69
92
  required:
70
93
  - resource_identifier
71
94
  properties:
72
- - resource_identifier:
95
+ resource_identifier:
73
96
  type: string
74
97
  description: the GUID being tested
75
98
 
76
99
  EOF_EOF
77
100
  end
101
+
102
+ private
103
+
104
+ # Ensures a multi-line string is safe for use inside a YAML block scalar (>- or |).
105
+ #
106
+ # YAML block scalars determine their indentation level from the first content line.
107
+ # Any subsequent line that is indented less than that level terminates the scalar,
108
+ # which causes parse errors when the text contains blank lines followed by
109
+ # unindented content (a common pattern in Markdown).
110
+ #
111
+ # This method leaves the first line untouched (the heredoc template already places
112
+ # it at the correct column) and prepends +spaces+ spaces to every non-empty
113
+ # continuation line so they remain inside the block scalar. Blank lines are left
114
+ # blank intentionally — YAML allows empty lines within a block scalar without
115
+ # requiring indentation.
116
+ #
117
+ # @param text [String] the raw author-supplied text
118
+ # @param spaces [Integer] number of spaces matching the block scalar's indentation
119
+ # in the rendered YAML (4 for +description+, 12 for +response_description+)
120
+ # @return [String]
121
+ def yaml_block_indent(text, spaces)
122
+ indent = " " * spaces
123
+ text.split("\n").map.with_index { |line, i| i.zero? || line.empty? ? line : "#{indent}#{line}" }.join("\n")
124
+ end
78
125
  end
79
126
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ftr_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - markwilkinson