lutaml-openapi 0.1.1 → 0.1.3

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.
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module Lutaml
6
+ module Openapi
7
+ # Generates a single-file SPA documentation site for an OpenAPI
8
+ # document. The frontend bundle (frontend/dist) is built by the
9
+ # frontend toolchain and is expected to exist at generation time —
10
+ # it enters the gem only immediately before a release.
11
+ module Spa
12
+ DIST = File.expand_path("../../../frontend/dist", __dir__)
13
+
14
+ module_function
15
+
16
+ def generate(document, title: nil)
17
+ app_js = File.read(File.join(DIST, "app.iife.js"))
18
+ style = File.join(DIST, "style.css")
19
+ data = safe_json(document.to_hash)
20
+
21
+ title ||= document.to_hash.dig("info", "title") || "OpenAPI document"
22
+
23
+ build_html(escape(title), data, app_js, style_content(style))
24
+ end
25
+
26
+ # JSON embedded in a <script> element: escape "<" so payload
27
+ # strings containing "</script>" (or any markup) cannot break out
28
+ def safe_json(obj)
29
+ JSON.generate(obj).gsub("<", "\\u003c")
30
+ end
31
+
32
+ def build_html(title, data, app_script, css)
33
+ <<~HTML
34
+ <!DOCTYPE html>
35
+ <html lang="en">
36
+ <head>
37
+ <meta charset="UTF-8">
38
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
39
+ <title>#{title}</title>
40
+ <style>#{css}</style>
41
+ </head>
42
+ <body>
43
+ <div id="app"></div>
44
+ <script>window.OPENAPI_DATA = #{data};</script>
45
+ <script>#{app_script}</script>
46
+ </body>
47
+ </html>
48
+ HTML
49
+ end
50
+
51
+ def style_content(path)
52
+ File.exist?(path) ? File.read(path) : ""
53
+ end
54
+
55
+ def escape(text)
56
+ text.to_s.gsub("&", "&amp;").gsub("<", "&lt;")
57
+ end
58
+ end
59
+ end
60
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lutaml
4
4
  module Openapi
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.3"
6
6
  end
7
7
  end
@@ -8,13 +8,16 @@ require "json"
8
8
  module Lutaml
9
9
  # OpenAPI 3.0/3.1 as a lossless lutaml-model.
10
10
  #
11
- # The 3.1 shape is the model (its Schema objects are JSON Schema
12
- # 2020-12, carried by lutaml-jsonschema); 3.0 documents are
13
- # normalized into it by the 3.0 frontend while `source_dialect` is
14
- # kept, so serialization re-emits 3.0 semantics for 3.0 sources.
11
+ # The document is stored verbatim — what was parsed is what the wire
12
+ # re-emits, so losslessness is structural rather than an emit-time
13
+ # transform. The 3.1 shape is the typed view: `source_dialect` tracks
14
+ # the frontend, and 3.0 schema nodes are normalized into JSON Schema
15
+ # 2020-12 by the 3.0 frontend when the typed layer materializes them.
15
16
  # Anything unmodeled rides the extensions catch-all — documents
16
17
  # round-trip verbatim.
17
18
  module Openapi
19
+ autoload :CorpusAudit, "lutaml/openapi/corpus_audit"
20
+ autoload :Spa, "lutaml/openapi/spa"
18
21
  autoload :VERSION, "lutaml/openapi/version"
19
22
  autoload :Document, "lutaml/openapi/document"
20
23
  autoload :Oas30, "lutaml/openapi/oas30"
@@ -24,7 +27,6 @@ module Lutaml
24
27
  def self.parse(string)
25
28
  data = parse_raw(string)
26
29
  dialect = data["openapi"].to_s.start_with?("3.0") ? "3.0" : "3.1"
27
- data = Oas30.normalize(data) if dialect == "3.0"
28
30
 
29
31
  Document.from_json(JSON.generate(data)).tap do |doc|
30
32
  doc.source_dialect = dialect
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/openapi/corpus_audit"
4
+
5
+ namespace :corpus do
6
+ desc "Audit the vendored OGC corpus: lossless round-trip + coverage matrix"
7
+ task :audit do
8
+ rows = Lutaml::Openapi::CorpusAudit.matrix
9
+ format = "%-46s %-7s lossless=%-5s schemas=%-4d " \
10
+ "documented=%-4d ops=%-3d ops_text=%d"
11
+ rows.each do |r|
12
+ puts format(format, r[:file], r[:openapi], r[:lossless], r[:schemas],
13
+ r[:schemas_documented], r[:operations],
14
+ r[:operations_with_text])
15
+ end
16
+ failures = rows.reject { |r| r[:lossless] }
17
+ unless failures.empty?
18
+ abort "corpus:audit: lossless round-trip failed for " \
19
+ "#{failures.map { |r| r[:file] }.join(', ')}"
20
+ end
21
+ end
22
+ end
23
+
24
+ namespace :frontend do
25
+ File.expand_path("frontend/dist", __dir__)
26
+ node_modules = File.expand_path("frontend/node_modules", __dir__)
27
+
28
+ task :install do
29
+ unless File.directory?(node_modules)
30
+ Dir.chdir("frontend") do
31
+ sh "npm install"
32
+ end
33
+ end
34
+ end
35
+
36
+ task build: :install do
37
+ Dir.chdir("frontend") { sh "npm run build" }
38
+ end
39
+ end
data/script/axe_audit ADDED
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ # axe-core accessibility audit of the generated SPA. Uses the axe-core
4
+ # copy vendored by the frontend's npm devDependencies (sovereign: no CDN
5
+ # fetch). Exits non-zero when violations are found; skips cleanly when
6
+ # no Chrome binary or no built frontend exists, so `rake` stays green on
7
+ # browser-less lanes (windows CI) while the browser-equipped lanes
8
+ # (ubuntu/macos) always run it.
9
+
10
+ require "json"
11
+ require "open3"
12
+ require "fileutils"
13
+ require "tmpdir"
14
+ require "lutaml/openapi"
15
+
16
+ CHROME_CANDIDATES = [
17
+ ENV.fetch("CHROME_BIN", nil),
18
+ "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
19
+ "/usr/bin/chromium",
20
+ "/usr/bin/chromium-browser",
21
+ "/usr/bin/google-chrome",
22
+ ].freeze
23
+
24
+ ROOT = File.expand_path("..", __dir__)
25
+ DOCUMENT = ARGV.first ||
26
+ File.join(ROOT, "spec", "fixtures", "ogcapi-features-1-oas31.yaml")
27
+
28
+ chrome = CHROME_CANDIDATES.find { |path| path && File.executable?(path) }
29
+ unless chrome
30
+ warn "axe audit: SKIP (no Chrome binary; set CHROME_BIN to enable)"
31
+ exit 0
32
+ end
33
+
34
+ dist = File.join(ROOT, "frontend", "dist")
35
+ unless File.exist?(File.join(dist, "app.iife.js"))
36
+ warn "axe audit: SKIP (frontend/dist missing; run `rake frontend:build`)"
37
+ exit 0
38
+ end
39
+
40
+ axe = File.join(ROOT, "frontend", "node_modules", "axe-core", "axe.min.js")
41
+ unless File.exist?(axe)
42
+ abort "axe audit: frontend/node_modules/axe-core missing; " \
43
+ "run `npm install` in frontend/"
44
+ end
45
+
46
+ INJECT = <<~SCRIPT
47
+ <script src="file://#{axe}"></script>
48
+ <script>
49
+ window.addEventListener('load', () => setTimeout(() => {
50
+ axe.run().then((r) => {
51
+ document.body.setAttribute('data-axe', JSON.stringify({
52
+ violations: r.violations.map((v) => ({ id: v.id, impact: v.impact,
53
+ nodes: v.nodes.length,
54
+ targets: v.nodes.map((n) => n.target.join(' ')) })),
55
+ passes: r.passes.length,
56
+ }));
57
+ document.title = 'AXE-DONE';
58
+ }).catch((e) => {
59
+ document.body.setAttribute('data-axe', JSON.stringify({ error: String(e) }));
60
+ document.title = 'AXE-ERROR';
61
+ });
62
+ }, 4000));
63
+ </script>
64
+ SCRIPT
65
+
66
+ dir = Dir.mktmpdir("axe-audit")
67
+ document = Lutaml::Openapi.parse(File.read(DOCUMENT))
68
+ File.write(File.join(dir, "index.html"), Lutaml::Openapi::Spa.generate(document))
69
+
70
+ page = File.join(dir, "index.html")
71
+ File.write(File.join(dir, "audit.html"),
72
+ File.read(page).sub("</body>", "#{INJECT}\n</body>"))
73
+
74
+ # both locales gate: the default LTR render and the Arabic RTL render
75
+ # (the mirrored layout must stay accessible)
76
+ VARIANTS = [
77
+ { label: "en", query: "" },
78
+ { label: "ar (rtl)", query: "?locale=ar" },
79
+ ].freeze
80
+
81
+ failed = false
82
+
83
+ VARIANTS.each do |variant|
84
+ dom, err, status = Open3.capture3(
85
+ chrome, "--headless=new", "--disable-gpu", "--virtual-time-budget=20000",
86
+ "--dump-dom", "file://#{File.join(dir, 'audit.html')}#{variant[:query]}"
87
+ )
88
+ abort "axe audit: Chrome failed: #{err[0, 400]}" unless status.success?
89
+
90
+ match = dom[/data-axe="([^"]*)"/, 1]
91
+ abort "axe audit (#{variant[:label]}): no result captured" unless match
92
+
93
+ result = JSON.parse(match.gsub("&quot;", '"'))
94
+ abort "axe audit: axe failed: #{result['error']}" if result["error"]
95
+
96
+ if result["violations"].empty?
97
+ puts "axe audit (#{variant[:label]}): PASS (#{result['passes']} rule groups)"
98
+ else
99
+ failed = true
100
+ puts "axe audit (#{variant[:label]}): " \
101
+ "#{result['violations'].sum { |v| v['nodes'] }} violations"
102
+ result["violations"].each do |violation|
103
+ puts " [#{violation['impact']}] #{violation['id']} x#{violation['nodes']}"
104
+ violation["targets"].each { |target| puts " #{target}" }
105
+ end
106
+ end
107
+ end
108
+
109
+ exit 1 if failed
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lutaml-openapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2026-10-31 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: json
@@ -57,14 +58,14 @@ dependencies:
57
58
  requirements:
58
59
  - - "~>"
59
60
  - !ruby/object:Gem::Version
60
- version: 0.6.34
61
+ version: 0.6.51
61
62
  type: :runtime
62
63
  prerelease: false
63
64
  version_requirements: !ruby/object:Gem::Requirement
64
65
  requirements:
65
66
  - - "~>"
66
67
  - !ruby/object:Gem::Version
67
- version: 0.6.34
68
+ version: 0.6.51
68
69
  description: Parse OpenAPI 3.0/3.1 documents into lossless LutaML model objects; the
69
70
  model layer for model-based OpenAPI standards
70
71
  email:
@@ -80,10 +81,30 @@ files:
80
81
  - PLAN.md
81
82
  - README.md
82
83
  - Rakefile
84
+ - frontend/dist/app.iife.js
85
+ - frontend/dist/style.css
86
+ - frontend/index.html
87
+ - frontend/package-lock.json
88
+ - frontend/package.json
89
+ - frontend/src/App.vue
90
+ - frontend/src/__tests__/i18n.test.ts
91
+ - frontend/src/app.ts
92
+ - frontend/src/components/OverviewView.vue
93
+ - frontend/src/components/PathsView.vue
94
+ - frontend/src/components/SchemasView.vue
95
+ - frontend/src/i18n/index.ts
96
+ - frontend/src/i18n/messages.ts
97
+ - frontend/src/style.css
98
+ - frontend/tsconfig.json
99
+ - frontend/vite.config.ts
83
100
  - lib/lutaml/openapi.rb
101
+ - lib/lutaml/openapi/corpus_audit.rb
84
102
  - lib/lutaml/openapi/document.rb
85
103
  - lib/lutaml/openapi/oas30.rb
104
+ - lib/lutaml/openapi/spa.rb
86
105
  - lib/lutaml/openapi/version.rb
106
+ - rakelib/corpus.rake
107
+ - script/axe_audit
87
108
  homepage: https://github.com/lutaml/lutaml-openapi
88
109
  licenses:
89
110
  - BSD-2-Clause
@@ -91,6 +112,7 @@ metadata:
91
112
  homepage_uri: https://github.com/lutaml/lutaml-openapi
92
113
  source_code_uri: https://github.com/lutaml/lutaml-openapi
93
114
  changelog_uri: https://github.com/lutaml/lutaml-openapi/blob/main/CHANGELOG.md
115
+ post_install_message:
94
116
  rdoc_options: []
95
117
  require_paths:
96
118
  - lib
@@ -105,7 +127,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
127
  - !ruby/object:Gem::Version
106
128
  version: '0'
107
129
  requirements: []
108
- rubygems_version: 3.6.9
130
+ rubygems_version: 3.5.22
131
+ signing_key:
109
132
  specification_version: 4
110
133
  summary: OpenAPI 3.0/3.1 as a lossless lutaml-model
111
134
  test_files: []