fhir_stub_server 0.1.0
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 +7 -0
- data/.rubocop.yml +20 -0
- data/.yardopts +3 -0
- data/CHANGELOG.md +37 -0
- data/CODE_OF_CONDUCT.md +10 -0
- data/LICENSE.txt +201 -0
- data/README.md +352 -0
- data/Rakefile +46 -0
- data/Steepfile +7 -0
- data/config.ru +6 -0
- data/exe/fhir-stub-server +25 -0
- data/lib/fhir_stub_server/fhir_role.rb +62 -0
- data/lib/fhir_stub_server/http_server.rb +35 -0
- data/lib/fhir_stub_server/includes.rb +69 -0
- data/lib/fhir_stub_server/paging.rb +51 -0
- data/lib/fhir_stub_server/pairs.rb +162 -0
- data/lib/fhir_stub_server/rack_app.rb +38 -0
- data/lib/fhir_stub_server/replay.rb +37 -0
- data/lib/fhir_stub_server/request.rb +35 -0
- data/lib/fhir_stub_server/responses.rb +59 -0
- data/lib/fhir_stub_server/sources.rb +139 -0
- data/lib/fhir_stub_server/stub.rb +57 -0
- data/lib/fhir_stub_server/unmatched.rb +32 -0
- data/lib/fhir_stub_server/validator.rb +73 -0
- data/lib/fhir_stub_server/version.rb +5 -0
- data/lib/fhir_stub_server/webmock_adapter.rb +53 -0
- data/lib/fhir_stub_server.rb +66 -0
- data/sig/fhir_stub_server.rbs +273 -0
- metadata +92 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
module FHIRStubServer
|
|
2
|
+
VERSION: String
|
|
3
|
+
|
|
4
|
+
def self.load: (String path) -> Stub
|
|
5
|
+
def self.require_gem: (String name, String needed_by) -> void
|
|
6
|
+
def self.read_file: (String path) -> String
|
|
7
|
+
def self.parse_file: (String path, :json | :yaml format) -> untyped
|
|
8
|
+
|
|
9
|
+
# What every adapter hands to Stub#respond.
|
|
10
|
+
type request = {
|
|
11
|
+
role: :fhir | :validator,
|
|
12
|
+
method: String,
|
|
13
|
+
base_url: String,
|
|
14
|
+
path: String,
|
|
15
|
+
query: Hash[String, Array[String]],
|
|
16
|
+
body: String?
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
# What an adapter reads off its transport, before Request.build normalizes it.
|
|
20
|
+
type raw_request = {
|
|
21
|
+
role: :fhir | :validator,
|
|
22
|
+
method: String,
|
|
23
|
+
base_url: String,
|
|
24
|
+
path: String,
|
|
25
|
+
query: String,
|
|
26
|
+
body: String?
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
# Rack-style [status, headers, body].
|
|
30
|
+
type response = [Integer, Hash[String, String], String]
|
|
31
|
+
|
|
32
|
+
type resource = Hash[String, untyped]
|
|
33
|
+
|
|
34
|
+
# A Pair as Stub#unused_pairs lists it: where it is written and its request as the config writes it.
|
|
35
|
+
type unused_pair = { role: :fhir | :validator, pair: String, request: Hash[String, untyped] }
|
|
36
|
+
|
|
37
|
+
# A `select` or `include` that yielded nothing, as Stub#empty_selects lists it.
|
|
38
|
+
type empty_select = { role: :fhir, pair: String, expression: String }
|
|
39
|
+
|
|
40
|
+
class Error < StandardError
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
class Stub
|
|
44
|
+
def initialize: (Hash[String, untyped] config, ?dir: String) -> void
|
|
45
|
+
def served: () -> Array[Hash[Symbol, untyped]]
|
|
46
|
+
def unmatched: () -> Array[Hash[Symbol, untyped]]
|
|
47
|
+
def context_mismatches: () -> Array[Hash[Symbol, untyped]]
|
|
48
|
+
def unmatched_report: () -> String
|
|
49
|
+
def unused_pairs: () -> Array[unused_pair]
|
|
50
|
+
def unused_pairs_report: () -> String
|
|
51
|
+
def empty_selects: () -> Array[empty_select]
|
|
52
|
+
def validator?: () -> bool
|
|
53
|
+
def respond: (request request) -> response
|
|
54
|
+
|
|
55
|
+
@validator: bool
|
|
56
|
+
@roles: { fhir: FHIRRole, validator: Validator }
|
|
57
|
+
@reports: Hash[Symbol, Array[Hash[Symbol, untyped]]]
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# What a role answers a request with: what answered it (where the Pair is written, :demo_data or :miss),
|
|
61
|
+
# the response and the report entries to append, by report name.
|
|
62
|
+
type answer = [String | Symbol, response, Hash[Symbol, Array[Hash[Symbol, untyped]]]]
|
|
63
|
+
|
|
64
|
+
class FHIRRole
|
|
65
|
+
@pairs: Array[Pairs::pair]
|
|
66
|
+
@reads: Hash[String, resource]
|
|
67
|
+
|
|
68
|
+
def initialize: (Hash[String, untyped] config, Hash[String, resource] demo_data, String model, String dir) -> void
|
|
69
|
+
def answer: (request request) -> answer
|
|
70
|
+
def pairs: () -> Array[unused_pair]
|
|
71
|
+
def empty_selects: () -> Array[empty_select]
|
|
72
|
+
def self.listed: (Array[Pairs::pair] pairs) -> Array[unused_pair]
|
|
73
|
+
def self.config: (Request::key key) -> Hash[String, untyped]
|
|
74
|
+
def self.config_values: (Hash[String, Array[String]]? params) -> Hash[String, String | Array[String]]?
|
|
75
|
+
def self.read_path: (request request) -> String?
|
|
76
|
+
|
|
77
|
+
private
|
|
78
|
+
|
|
79
|
+
def read_answer: (request request) -> [Symbol, response]?
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
module Pairs
|
|
83
|
+
type body = ^(request request, Paging::page page) -> String?
|
|
84
|
+
type pair = { key: Request::key, status: Integer, body: body, where: String, empty_selects: Array[empty_select] }
|
|
85
|
+
# Evaluates a FHIRPath expression over all Demo Data.
|
|
86
|
+
type fhirpath = ^(String expression) -> Array[untyped]
|
|
87
|
+
type differences = Hash[String, { expected: Array[String]?, actual: Array[String]? }]
|
|
88
|
+
|
|
89
|
+
BODY_KINDS: Array[String]
|
|
90
|
+
|
|
91
|
+
def self.load: (Array[Hash[String, untyped]] pairs, fhirpath fhirpath, String dir) -> Array[pair]
|
|
92
|
+
def self.fhirpath: (Hash[String, resource] demo_data, String model) -> fhirpath
|
|
93
|
+
def self.with_dir: (Hash[String, untyped] pair, String dir) -> Hash[String, untyped]
|
|
94
|
+
def self.answer: (Array[pair] pairs, request request) -> [String, response]?
|
|
95
|
+
def self.near_miss: (Array[pair] pairs, request request) -> { nearest_pair: String?, differences: differences }
|
|
96
|
+
def self.candidates: (Array[pair] pairs, Request::key key) -> Array[[String, differences]]
|
|
97
|
+
def self.differences: (Request::key pair_key, Request::key request_key) -> differences
|
|
98
|
+
def self.diff: (Hash[String, Array[String]] expected, Hash[String, Array[String]] actual) -> differences
|
|
99
|
+
def self.build: (Hash[String, untyped] pair, fhirpath fhirpath, String where) -> pair
|
|
100
|
+
def self.request: (Hash[String, untyped] config, String where) -> request
|
|
101
|
+
def self.body: (Hash[String, untyped] config, fhirpath fhirpath, String where) -> [body, Array[empty_select]]
|
|
102
|
+
def self.empty_selects: (Hash[String, untyped] config, Hash[String, Array[resource]] results, String where) -> Array[empty_select]
|
|
103
|
+
def self.literal_body: (Hash[String, untyped] config, fhirpath fhirpath, String where) -> body
|
|
104
|
+
def self.body_kind: (Hash[String, untyped] config, String where) -> String?
|
|
105
|
+
def self.evaluate: (String? expression, fhirpath fhirpath, String where) -> Array[resource]
|
|
106
|
+
def self.resources_only: (Array[untyped] results, String label) -> Array[resource]
|
|
107
|
+
def self.one_resource: (Array[resource] results, String where) -> resource
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
class Includes
|
|
111
|
+
# [pair as written, dir of its file, where it is written]
|
|
112
|
+
type spliced = [untyped, String, String]
|
|
113
|
+
# [file holding the entry (nil: the config itself), index], for each entry leading to a Pair
|
|
114
|
+
type trail = Array[[String?, Integer]]
|
|
115
|
+
|
|
116
|
+
@name: String
|
|
117
|
+
@root: String
|
|
118
|
+
|
|
119
|
+
def self.splice: (Array[untyped] entries, String name, String dir) -> Array[spliced]
|
|
120
|
+
def initialize: (String name, String dir) -> void
|
|
121
|
+
def pairs: (Array[untyped] entries, ?String? file, ?trail trail) -> Array[spliced]
|
|
122
|
+
|
|
123
|
+
private
|
|
124
|
+
|
|
125
|
+
def entry_pairs: (untyped entry, String dir, trail at) -> Array[spliced]
|
|
126
|
+
def from_path: (Hash[String, untyped] include, String dir, trail at) -> String
|
|
127
|
+
def included: (String file, trail at) -> Array[spliced]
|
|
128
|
+
def read: (String file, trail at) -> untyped
|
|
129
|
+
def where: (trail at) -> String
|
|
130
|
+
def relative: (String file) -> String
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
module Request
|
|
134
|
+
# What a request and a Pair must share to match; queries are { name => sorted values }.
|
|
135
|
+
type key = { method: String, path: String, query: Hash[String, Array[String]], form: Hash[String, Array[String]]? }
|
|
136
|
+
|
|
137
|
+
def self.build: (raw_request raw) -> request
|
|
138
|
+
def self.parse_query: (String query) -> Hash[String, Array[String]]
|
|
139
|
+
def self.key: (request request) -> key
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
module Paging
|
|
143
|
+
# The total of all matches, and each page's [matches, includes].
|
|
144
|
+
type pages = { total: Integer, entries: Array[[Array[resource], Array[resource]]] }
|
|
145
|
+
|
|
146
|
+
type page = { number: Integer, path: String }
|
|
147
|
+
|
|
148
|
+
PATH: Regexp
|
|
149
|
+
|
|
150
|
+
def self.locate: (Array[Pairs::pair] pairs, Request::key key) -> [Integer, page]?
|
|
151
|
+
def self.continued: (Request::key key) -> [Integer, page]?
|
|
152
|
+
def self.page: (Integer index, Integer number) -> [Integer, page]
|
|
153
|
+
def self.body: (Hash[String, untyped] config, Hash[String, Array[resource]] results, String where) -> Pairs::body
|
|
154
|
+
def self.size: (Hash[String, untyped] config, Array[resource] matches, String where) -> Integer
|
|
155
|
+
def self.split: (Array[resource] matches, Array[resource] includes, Integer size) -> pages
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
module Responses
|
|
159
|
+
CONTENT_TYPE: String
|
|
160
|
+
|
|
161
|
+
def self.fhir: (Integer status, resource resource) -> response
|
|
162
|
+
def self.raw: (Integer status, String body) -> response
|
|
163
|
+
def self.searchset: (request request, Paging::pages pages, Paging::page page) -> String?
|
|
164
|
+
def self.links: (request request, String? next_url) -> Array[Hash[String, String]]
|
|
165
|
+
def self.entries: (String base_url, Array[resource] resources, String mode) -> Array[Hash[String, untyped]]
|
|
166
|
+
def self.validation: (Array[untyped] issues) -> response
|
|
167
|
+
def self.not_found: (request request) -> response
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
module Sources
|
|
171
|
+
type located = [String, resource]
|
|
172
|
+
# [package path, the FHIR versions its package.json states]
|
|
173
|
+
type stated = [String, Array[untyped]]
|
|
174
|
+
|
|
175
|
+
MODELS: Hash[String, String]
|
|
176
|
+
|
|
177
|
+
def self.load: (Array[Hash[String, String]] sources, String dir) -> [Hash[String, resource], Array[Hash[Symbol, untyped]], String]
|
|
178
|
+
def self.model: (Array[stated] stated) -> String
|
|
179
|
+
def self.no_common_version: (Array[stated] stated) -> Error
|
|
180
|
+
def self.models: (String path, Array[untyped] versions) -> Array[String]
|
|
181
|
+
def self.index: (Array[located] located) -> Hash[String, resource]
|
|
182
|
+
def self.skipped_entries: (Array[located] skipped) -> Array[Hash[Symbol, untyped]]
|
|
183
|
+
def self.reads: (Hash[String, resource] demo_data) -> Hash[String, resource]
|
|
184
|
+
def self.server_capability_statement: (Array[resource] resources) -> resource?
|
|
185
|
+
def self.server?: (resource resource) -> bool
|
|
186
|
+
def self.key: (resource resource) -> String
|
|
187
|
+
def self.located_resources: (Hash[String, String] source, String dir) -> [Array[located], stated?]
|
|
188
|
+
def self.package_resources: (String path) -> [Array[located], stated]
|
|
189
|
+
def self.json_files: (String path) -> Array[[String, Hash[String, untyped]]]
|
|
190
|
+
def self.tar_json_files: (Zlib::GzipReader archive) -> Array[[String, Hash[String, untyped]]]
|
|
191
|
+
def self.json: (Gem::Package::TarReader::Entry entry) -> untyped
|
|
192
|
+
def self.bundle_resources: (String path) -> Array[located]
|
|
193
|
+
def self.no_duplicates: (Array[located] located) -> Array[located]
|
|
194
|
+
def self.duplicate: (Array[located] located) -> [String, Array[located]]?
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
class Validator
|
|
198
|
+
type key = [String?, String?]
|
|
199
|
+
type mismatch = { request: request, key: String, expected: untyped, actual: untyped }
|
|
200
|
+
|
|
201
|
+
@pairs: Array[[key, Array[untyped], String]]
|
|
202
|
+
@expected_context: Hash[String, untyped]
|
|
203
|
+
|
|
204
|
+
def initialize: (Hash[String, untyped] config, String dir) -> void
|
|
205
|
+
def answer: (request request) -> answer
|
|
206
|
+
def pairs: () -> Array[unused_pair]
|
|
207
|
+
def self.call: (request request) -> [key, Hash[String, untyped]]?
|
|
208
|
+
def self.key: (Hash[String, untyped] file) -> key
|
|
209
|
+
def self.miss: (request request, key? key) -> Hash[Symbol, untyped]
|
|
210
|
+
def self.config: (key key) -> Hash[String, String]
|
|
211
|
+
|
|
212
|
+
private
|
|
213
|
+
|
|
214
|
+
def matching_pair: (key? key) -> [key, Array[untyped], String]?
|
|
215
|
+
def mismatches: (Hash[String, untyped]? context, request request) -> Array[mismatch]
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
class RackApp
|
|
219
|
+
@stub: Stub
|
|
220
|
+
@base_paths: Hash[:fhir | :validator, String]
|
|
221
|
+
|
|
222
|
+
def initialize: (Stub stub, ?fhir_base_path: String, ?validator_base_path: String) -> void
|
|
223
|
+
def call: (Hash[String, untyped] env) -> [Integer, Hash[String, String], Array[String]]
|
|
224
|
+
def base_path_for: (String path) -> [:fhir | :validator, String]?
|
|
225
|
+
def self.stub_request: (Hash[String, untyped] env, :fhir | :validator role, String base_path) -> request
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
module Unmatched
|
|
229
|
+
def self.describe: (Hash[Symbol, untyped] miss) -> String
|
|
230
|
+
def self.differences: (Pairs::differences differences) -> String
|
|
231
|
+
def self.suggestion: (Hash[Symbol, untyped] miss) -> String
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
class Replay
|
|
235
|
+
@stub: Stub
|
|
236
|
+
@rack_app: RackApp
|
|
237
|
+
@log: IO
|
|
238
|
+
@lock: Thread::Mutex
|
|
239
|
+
|
|
240
|
+
def initialize: (Stub stub, ?IO log) -> void
|
|
241
|
+
def call: (Hash[String, untyped] env) -> [Integer, Hash[String, String], Array[String]]
|
|
242
|
+
def log_unused_pairs: () -> void
|
|
243
|
+
|
|
244
|
+
private
|
|
245
|
+
|
|
246
|
+
def logging_misses: () { () -> [Integer, Hash[String, String], Array[String]] } -> [Integer, Hash[String, String], Array[String]]
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
# What Puma and HTTPServer need of a Rack app.
|
|
250
|
+
interface _RackApp
|
|
251
|
+
def call: (Hash[String, untyped] env) -> [Integer, Hash[String, String], Array[String]]
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
class HTTPServer
|
|
255
|
+
@server: Puma::Server
|
|
256
|
+
@thread: Thread?
|
|
257
|
+
|
|
258
|
+
def initialize: (Stub | _RackApp stub_or_app, **String rack_app_options) -> void
|
|
259
|
+
def start: () -> String
|
|
260
|
+
def wait: () -> void
|
|
261
|
+
def stop: () -> void
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
module WebMockAdapter
|
|
265
|
+
self.@previous_notation: Symbol?
|
|
266
|
+
|
|
267
|
+
def self.install: (Stub stub, fhir_base_url: String, ?validator_base_url: String?) -> void
|
|
268
|
+
def self.uninstall: () -> void
|
|
269
|
+
def self.keep_repeated_query_parameters: () -> void
|
|
270
|
+
def self.route: (Stub stub, :fhir | :validator role, String base_url) -> void
|
|
271
|
+
def self.stub_request: (untyped request, :fhir | :validator role, String base_url) -> request
|
|
272
|
+
end
|
|
273
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: fhir_stub_server
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Pavel Rozhkov
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-11-25 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: fhirpath-rb
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0.1'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0.1'
|
|
27
|
+
description: Answers only the requests a Scenario declares, serves Demo Data from
|
|
28
|
+
FHIR packages and Bundles, selects responses with FHIRPath, stubs Inferno's validator
|
|
29
|
+
and reports every unmatched request. Runs in process through WebMock or over HTTP.
|
|
30
|
+
email:
|
|
31
|
+
- pavel.r@beda.software
|
|
32
|
+
- prozskov@gmail.com
|
|
33
|
+
executables:
|
|
34
|
+
- fhir-stub-server
|
|
35
|
+
extensions: []
|
|
36
|
+
extra_rdoc_files: []
|
|
37
|
+
files:
|
|
38
|
+
- ".rubocop.yml"
|
|
39
|
+
- ".yardopts"
|
|
40
|
+
- CHANGELOG.md
|
|
41
|
+
- CODE_OF_CONDUCT.md
|
|
42
|
+
- LICENSE.txt
|
|
43
|
+
- README.md
|
|
44
|
+
- Rakefile
|
|
45
|
+
- Steepfile
|
|
46
|
+
- config.ru
|
|
47
|
+
- exe/fhir-stub-server
|
|
48
|
+
- lib/fhir_stub_server.rb
|
|
49
|
+
- lib/fhir_stub_server/fhir_role.rb
|
|
50
|
+
- lib/fhir_stub_server/http_server.rb
|
|
51
|
+
- lib/fhir_stub_server/includes.rb
|
|
52
|
+
- lib/fhir_stub_server/paging.rb
|
|
53
|
+
- lib/fhir_stub_server/pairs.rb
|
|
54
|
+
- lib/fhir_stub_server/rack_app.rb
|
|
55
|
+
- lib/fhir_stub_server/replay.rb
|
|
56
|
+
- lib/fhir_stub_server/request.rb
|
|
57
|
+
- lib/fhir_stub_server/responses.rb
|
|
58
|
+
- lib/fhir_stub_server/sources.rb
|
|
59
|
+
- lib/fhir_stub_server/stub.rb
|
|
60
|
+
- lib/fhir_stub_server/unmatched.rb
|
|
61
|
+
- lib/fhir_stub_server/validator.rb
|
|
62
|
+
- lib/fhir_stub_server/version.rb
|
|
63
|
+
- lib/fhir_stub_server/webmock_adapter.rb
|
|
64
|
+
- sig/fhir_stub_server.rbs
|
|
65
|
+
homepage: https://github.com/projkov/fhir_stub_server
|
|
66
|
+
licenses:
|
|
67
|
+
- Apache-2.0
|
|
68
|
+
metadata:
|
|
69
|
+
homepage_uri: https://github.com/projkov/fhir_stub_server
|
|
70
|
+
source_code_uri: https://github.com/projkov/fhir_stub_server
|
|
71
|
+
documentation_uri: https://rubydoc.info/gems/fhir_stub_server
|
|
72
|
+
rubygems_mfa_required: 'true'
|
|
73
|
+
post_install_message:
|
|
74
|
+
rdoc_options: []
|
|
75
|
+
require_paths:
|
|
76
|
+
- lib
|
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - ">="
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: 3.3.6
|
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
|
+
requirements:
|
|
84
|
+
- - ">="
|
|
85
|
+
- !ruby/object:Gem::Version
|
|
86
|
+
version: '0'
|
|
87
|
+
requirements: []
|
|
88
|
+
rubygems_version: 3.5.22
|
|
89
|
+
signing_key:
|
|
90
|
+
specification_version: 4
|
|
91
|
+
summary: A strict stub for the FHIR server and validator used by FHIR test kits.
|
|
92
|
+
test_files: []
|