Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

put spec validation in script; polish

Markus Kahl20171e3839fe
diff --git a/.github/workflows/test-core.yml b/.github/workflows/test-core.yml
index 872789c58cf..a2a4e31c5fa 100644
--- a/.github/workflows/test-core.yml
+++ b/.github/workflows/test-core.yml
@@ -93,4 +93,4 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: '14'
- - run: npx @redocly/openapi-cli lint docs/api/apiv3/openapi-spec.yml
+ - run: ./script/api/validate_spec
diff --git a/lib/api/open_api.rb b/lib/api/open_api.rb
index 967f4fcbcd8..65289f323fe 100644
--- a/lib/api/open_api.rb
+++ b/lib/api/open_api.rb
@@ -38,7 +38,7 @@ module API
spec
end
end
-
+
def substitute_refs_in_hash(spec, path:, root_path:, root_spec: spec)
if spec.size == 1 && spec.keys.first == "$ref"
ref_path = path.join spec.values.first
@@ -62,20 +62,24 @@ module API
def resolve_refs_in_hash(spec, path:, root_path:, root_spec:)
if spec.size == 1 && spec.keys.first == "$ref"
- ref_path = spec.values.first
+ resolve_ref spec, path: path, root_path: root_path, root_spec: root_spec
+ else
+ spec.transform_values { |v| resolve_refs v, path: path, root_path: root_path, root_spec: root_spec }
+ end
+ end
- if ref_path.start_with?(".")
- schema_file = path.join(ref_path).to_s.sub(root_path.to_s, ".")
- schema_path = path.join(ref_path).parent.to_s.sub(root_path.to_s, "").split("/").drop(1)
- schema_name = root_spec.dig(*schema_path).find { |_k, v| v["$ref"] == schema_file }.first
- schema_ref = path.join(ref_path).parent.join(schema_name).to_s.sub(root_path.to_s, "#")
+ def resolve_ref(spec, path:, root_path:, root_spec:)
+ ref_path = spec.values.first
- { spec.keys.first => schema_ref }
- else
- spec
- end
+ if ref_path.start_with?(".")
+ schema_file = path.join(ref_path).to_s.sub(root_path.to_s, ".")
+ schema_path = path.join(ref_path).parent.to_s.sub(root_path.to_s, "").split("/").drop(1)
+ schema_name = root_spec.dig(*schema_path).find { |_k, v| v["$ref"] == schema_file }.first
+ schema_ref = path.join(ref_path).parent.join(schema_name).to_s.sub(root_path.to_s, "#")
+
+ { spec.keys.first => schema_ref }
else
- spec.transform_values { |v| resolve_refs v, path: path, root_path: root_path, root_spec: root_spec }
+ spec
end
end
end
diff --git a/script/api/spec b/script/api/spec
index 336642f5735..347a0c3ab4c 100644
--- a/script/api/spec
+++ b/script/api/spec
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-if ARGV.join(" ") =~ /((\-h)|(\-\-help))/
+if ARGV.join(" ") =~ /((-h)|(--help))/
puts "Prints the self-contained OpenAPI 3.0 specification of OpenProject's APIv3"
puts
puts "usage: ./scripts/api/spec [--format JSON|yaml]"
@@ -11,11 +11,11 @@ require 'pathname'
require 'yaml'
require 'json'
-require './lib/api/open_api.rb'
+require './lib/api/open_api'
path = Pathname(__dir__).join("../../docs/api/apiv3/openapi-spec.yml")
spec = API::OpenAPI.assemble_spec path
-format = ARGV.join(" ") =~ /((\-\-format)|(\-f))((=)|(\s+))ya?ml/ ? :yaml : :json
+format = ARGV.join(" ") =~ /((--format)|(-f))((=)|(\s+))ya?ml/ ? :yaml : :json
begin
if format == :yaml
diff --git a/script/api/validate_spec b/script/api/validate_spec
new file mode 100644
index 00000000000..a6ab0bc35ff
--- /dev/null
+++ b/script/api/validate_spec
@@ -0,0 +1,7 @@
+#!/usr/bin/env ruby
+
+require 'pathname'
+
+path = Pathname(__dir__).join("../../docs/api/apiv3/openapi-spec.yml")
+
+%x`npx @redocly/openapi-cli lint #{path}`