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

addressed review (including code climate) remarks

Markus Kahl31588fa25a59
diff --git a/app/controllers/api_docs_controller.rb b/app/controllers/api_docs_controller.rb
index d1519638e92..d6767e3c44e 100644
--- a/app/controllers/api_docs_controller.rb
+++ b/app/controllers/api_docs_controller.rb
@@ -31,9 +31,9 @@
class APIDocsController < ApplicationController
before_action :require_login
- layout 'angular'
-
def index
render_404 unless Setting.apiv3_docs_enabled?
+
+ render layout: 'angular', inline: ''
end
end
diff --git a/app/views/api_docs/index.html.erb b/app/views/api_docs/index.html.erb
deleted file mode 100644
index 3104da20a09..00000000000
--- a/app/views/api_docs/index.html.erb
+++ /dev/null
@@ -1 +0,0 @@
-FOOBAR
diff --git a/frontend/src/app/features/api-docs/swagger-ui/swagger-ui.component.html b/frontend/src/app/features/api-docs/swagger-ui/swagger-ui.component.html
index 555d1f0a9d8..cd062fdd0ea 100644
--- a/frontend/src/app/features/api-docs/swagger-ui/swagger-ui.component.html
+++ b/frontend/src/app/features/api-docs/swagger-ui/swagger-ui.component.html
@@ -1,3 +1 @@
-<div id="docs-wrapper">
- <div id="swagger"></div>
-</div>
+<div id="swagger"></div>
diff --git a/lib/api/open_api.rb b/lib/api/open_api.rb
index 948afc2af35..967f4fcbcd8 100644
--- a/lib/api/open_api.rb
+++ b/lib/api/open_api.rb
@@ -9,7 +9,7 @@ module API
if spec_path.exist?
assemble_spec spec_path
else
- raise "Could not find openapi-spec.yml uner #{spec_path.to_s}"
+ raise "Could not find openapi-spec.yml uner #{spec_path}"
end
end
@@ -24,50 +24,58 @@ module API
end
def assemble_spec(file_path)
- spec = YAML.load File.read(file_path.to_s)
+ spec = YAML.safe_load File.read(file_path.to_s)
substitute_refs(spec, path: file_path.parent, root_path: file_path.parent)
end
def substitute_refs(spec, path:, root_path:, root_spec: spec)
if spec.is_a?(Hash)
- if spec.size == 1 && spec.keys.first == "$ref"
- ref_path = path.join spec.values.first
- ref_value = YAML.load File.read(ref_path.to_s)
-
- resolve_refs ref_value, path: ref_path.parent, root_path: root_path, root_spec: root_spec
- else
- spec.map { |k, v| [k, substitute_refs(v, path: path, root_path: root_path, root_spec: root_spec)] }.to_h
- end
+ substitute_refs_in_hash spec, path: path, root_path: root_path, root_spec: root_spec
elsif spec.is_a?(Array)
spec.map { |s| substitute_refs s, path: path, root_path: root_path, root_spec: root_spec }
else
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
+ ref_value = YAML.safe_load File.read(ref_path.to_s)
+
+ resolve_refs ref_value, path: ref_path.parent, root_path: root_path, root_spec: root_spec
+ else
+ spec.transform_values { |v| substitute_refs(v, path: path, root_path: root_path, root_spec: root_spec) }
+ end
+ end
def resolve_refs(spec, path:, root_path:, root_spec:)
if spec.is_a?(Hash)
- if spec.size == 1 && spec.keys.first == "$ref"
- ref_path = spec.values.first
+ resolve_refs_in_hash spec, path: path, root_path: root_path, root_spec: root_spec
+ elsif spec.is_a?(Array)
+ spec.map { |v| resolve_refs v, path: path, root_path: root_path, root_spec: root_spec }
+ else
+ 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_refs_in_hash(spec, path:, root_path:, root_spec:)
+ if spec.size == 1 && spec.keys.first == "$ref"
+ 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.map { |k, v| [k, resolve_refs(v, path: path, root_path: root_path, root_spec: root_spec)] }.to_h
+ spec
end
- elsif spec.is_a?(Array)
- spec.map { |v| resolve_refs(v, path: path, root_path: root_path, root_spec: root_spec) }
else
- spec
+ spec.transform_values { |v| resolve_refs v, path: path, root_path: root_path, root_spec: root_spec }
end
end
end