put spec validation in script; polish

pull/9421/head
Markus Kahl 3 years ago
parent d39609a41d
commit 20171e3839
  1. 2
      .github/workflows/test-core.yml
  2. 28
      lib/api/open_api.rb
  3. 6
      script/api/spec
  4. 7
      script/api/validate_spec

@ -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

@ -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

@ -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

@ -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}`
Loading…
Cancel
Save