debian-mirror-gitlab/lib/tasks/gitlab/openapi.rake

33 lines
950 B
Ruby
Raw Normal View History

2022-11-25 23:54:43 +05:30
# frozen_string_literal: true
if Rails.env.development?
require 'grape-swagger/rake/oapi_tasks'
GrapeSwagger::Rake::OapiTasks.new('::API::API')
end
namespace :gitlab do
2023-05-27 22:25:52 +05:30
require 'logger'
2022-11-25 23:54:43 +05:30
namespace :openapi do
2023-01-13 00:05:48 +05:30
task :validate do
raise 'This task can only be run in the development environment' unless Rails.env.development?
success = system('yarn swagger:validate doc/api/openapi/openapi_v2.yaml')
abort('Validation of swagger document failed') unless success
end
2022-11-25 23:54:43 +05:30
task :generate do
raise 'This task can only be run in the development environment' unless Rails.env.development?
ENV['store'] = 'tmp/openapi.json'
Rake::Task["oapi:fetch"].invoke(['openapi.json'])
yaml_content = Gitlab::Json.parse(File.read('tmp/openapi_swagger_doc.json')).to_yaml
File.write("doc/api/openapi/openapi_v2.yaml", yaml_content)
end
2023-01-13 00:05:48 +05:30
task generate_and_check: [:generate, :validate]
2022-11-25 23:54:43 +05:30
end
end