octri-openapi-parser 0.1.2-aarch64-linux
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/lib/exact_json.rb +55 -0
- data/lib/octri_parser/native/LICENSE +202 -0
- data/lib/octri_parser/native/OAI-LICENSE +201 -0
- data/lib/octri_parser/native/THIRD_PARTY_NOTICES.md +47397 -0
- data/lib/octri_parser/native/liboctri_parser_ffi.so +0 -0
- data/lib/octri_parser.rb +111 -0
- metadata +74 -0
|
Binary file
|
data/lib/octri_parser.rb
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'fiddle'
|
|
4
|
+
require 'json'
|
|
5
|
+
require_relative 'exact_json'
|
|
6
|
+
require 'pathname'
|
|
7
|
+
|
|
8
|
+
module OctriParser
|
|
9
|
+
# Native diagnostics retain physical source positions and related locations.
|
|
10
|
+
class ParserError < StandardError
|
|
11
|
+
attr_reader :diagnostics
|
|
12
|
+
|
|
13
|
+
def initialize(error)
|
|
14
|
+
super(error.fetch('message'))
|
|
15
|
+
@diagnostics = error.fetch('diagnostics')
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Explicit sources avoid guessing whether a string is a path or a document.
|
|
20
|
+
class Source
|
|
21
|
+
def self.text(content, uri: 'memory://octri/openapi.yaml')
|
|
22
|
+
{ 'uri' => uri, 'content' => content, 'generated' => false }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.path(path)
|
|
26
|
+
{ 'uri' => Pathname.new(path).expand_path.to_s, 'content' => nil, 'generated' => false }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.object(document, uri: 'memory://octri/openapi.json')
|
|
30
|
+
{ 'uri' => uri, 'content' => OctriExactJSON.generate(document), 'generated' => true }
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Stateless synchronous binding. Fiddle borrows input only during the call;
|
|
35
|
+
# every native response is copied and freed before returning to Ruby.
|
|
36
|
+
class Parser
|
|
37
|
+
MAX_REQUEST_BYTES = 128 * 1024 * 1024
|
|
38
|
+
# Platform gems carry the native library under lib/octri_parser/native.
|
|
39
|
+
BUNDLED_LIBRARY = File.join(__dir__, 'octri_parser', 'native',
|
|
40
|
+
RUBY_PLATFORM.include?('darwin') ? 'liboctri_parser_ffi.dylib' : 'liboctri_parser_ffi.so')
|
|
41
|
+
|
|
42
|
+
def initialize(library = BUNDLED_LIBRARY)
|
|
43
|
+
@library = Fiddle.dlopen(File.realpath(library))
|
|
44
|
+
version = function('abi_version', [], Fiddle::TYPE_INT)
|
|
45
|
+
raise LoadError, 'Expected Octri native ABI version 1' unless version.call == 1
|
|
46
|
+
|
|
47
|
+
@call = function('call', [Fiddle::TYPE_VOIDP, Fiddle::TYPE_SIZE_T], Fiddle::TYPE_VOIDP)
|
|
48
|
+
@data = function('buffer_data', [Fiddle::TYPE_VOIDP], Fiddle::TYPE_VOIDP)
|
|
49
|
+
@length = function('buffer_len', [Fiddle::TYPE_VOIDP], Fiddle::TYPE_SIZE_T)
|
|
50
|
+
@free = function('buffer_free', [Fiddle::TYPE_VOIDP], Fiddle::TYPE_VOID)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Returns the complete Ok/Err transport envelope for parity tooling.
|
|
54
|
+
def call(envelope)
|
|
55
|
+
input = OctriExactJSON.generate(envelope).encode(Encoding::UTF_8)
|
|
56
|
+
raise ArgumentError, 'Binding request exceeds 128 MiB' if input.bytesize > MAX_REQUEST_BYTES
|
|
57
|
+
|
|
58
|
+
result = @call.call(Fiddle::Pointer[input], input.bytesize)
|
|
59
|
+
raise NoMemoryError, 'Native parser returned a null buffer' if result.null?
|
|
60
|
+
|
|
61
|
+
begin
|
|
62
|
+
OctriExactJSON.parse(@data.call(result).to_s(@length.call(result)).force_encoding(Encoding::UTF_8))
|
|
63
|
+
ensure
|
|
64
|
+
@free.call(result)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def execute(operation, source, options = {})
|
|
69
|
+
result('abiVersion' => 1, 'action' => 'report',
|
|
70
|
+
'request' => { 'operation' => operation, 'input' => source, 'options' => options })
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def document(operation, source, options = {})
|
|
74
|
+
result('abiVersion' => 1, 'action' => 'document',
|
|
75
|
+
'request' => { 'operation' => operation, 'input' => source, 'options' => options })
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def parse(source, options = {}) = execute('parse', source, options)
|
|
79
|
+
def resolve(source, options = {}) = execute('resolve', source, options)
|
|
80
|
+
def bundle(source, options = {}) = execute('bundle', source, options)
|
|
81
|
+
def dereference(source, options = {}) = execute('dereference', source, options)
|
|
82
|
+
def validate(source, options = {}) = execute('validate', source, options)
|
|
83
|
+
|
|
84
|
+
def inspect(source = nil, options = {})
|
|
85
|
+
return super() if source.nil?
|
|
86
|
+
|
|
87
|
+
execute('inspect', source, options)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def analyze(source, options = {}) = execute('analyze', source, options)
|
|
91
|
+
|
|
92
|
+
def serialize(document, format: 'json', limits: {})
|
|
93
|
+
encoded = OctriExactJSON.generate(document)
|
|
94
|
+
result('abiVersion' => 1, 'action' => 'serialize', 'document' => encoded, 'format' => format,
|
|
95
|
+
'limits' => limits)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
private
|
|
99
|
+
|
|
100
|
+
def result(envelope)
|
|
101
|
+
response = call(envelope)
|
|
102
|
+
raise ParserError, response.fetch('Err') if response.key?('Err')
|
|
103
|
+
|
|
104
|
+
response.fetch('Ok')
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def function(name, arguments, result)
|
|
108
|
+
Fiddle::Function.new(@library["octri_parser_#{name}"], arguments, result)
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: octri-openapi-parser
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.2
|
|
5
|
+
platform: aarch64-linux
|
|
6
|
+
authors:
|
|
7
|
+
- Octri contributors
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: bigdecimal
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: fiddle
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
description: Validate, parse, bundle and dereference Swagger 2.0 and OpenAPI 3.x documents
|
|
41
|
+
with the bundled Octri Rust parser.
|
|
42
|
+
executables: []
|
|
43
|
+
extensions: []
|
|
44
|
+
extra_rdoc_files: []
|
|
45
|
+
files:
|
|
46
|
+
- lib/exact_json.rb
|
|
47
|
+
- lib/octri_parser.rb
|
|
48
|
+
- lib/octri_parser/native/LICENSE
|
|
49
|
+
- lib/octri_parser/native/OAI-LICENSE
|
|
50
|
+
- lib/octri_parser/native/THIRD_PARTY_NOTICES.md
|
|
51
|
+
- lib/octri_parser/native/liboctri_parser_ffi.so
|
|
52
|
+
homepage: https://github.com/octridev/octri-openapi-parser
|
|
53
|
+
licenses:
|
|
54
|
+
- Apache-2.0
|
|
55
|
+
metadata:
|
|
56
|
+
rubygems_mfa_required: 'true'
|
|
57
|
+
rdoc_options: []
|
|
58
|
+
require_paths:
|
|
59
|
+
- lib
|
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
61
|
+
requirements:
|
|
62
|
+
- - ">="
|
|
63
|
+
- !ruby/object:Gem::Version
|
|
64
|
+
version: '3.1'
|
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
|
+
requirements:
|
|
67
|
+
- - ">="
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '0'
|
|
70
|
+
requirements: []
|
|
71
|
+
rubygems_version: 3.6.9
|
|
72
|
+
specification_version: 4
|
|
73
|
+
summary: Ruby bindings for the Octri Rust OpenAPI parser
|
|
74
|
+
test_files: []
|