require_relative '../common_errors' namespace :ci do desc 'Verify all pages to make sure that no exceptions are thrown' task verify_pages: :environment do puts 'ci/verify_pages - Verify all pages to make sure that no exceptions are thrown' document_paths = [ "#{Rails.configuration.docs_base_path}/_documentation/en/**/*.md", "#{Rails.configuration.docs_base_path}/_api/**/*.md", "#{Rails.configuration.docs_base_path}/_tutorials/**/*.md", ] document_paths.each do |path| Dir.glob(path).each do |filename| document = File.read(filename) begin Nexmo::Markdown::Renderer.new.call(document) rescue StandardError => e puts "Error whilst processing #{filename}" raise e end end end end desc 'Verify side navigation to make sure every page has valid YAML metadata' task verify_navigation: :environment do puts 'ci/verify_navigation - Verify side navigation to make sure every page has valid YAML metadata' session = ActionDispatch::Integration::Session.new(Rails.application) res = session.get '/documentation' # Check for migration pending error CommonErrors.check_for_migration_error(session.body) raise 'Error rendering documentation index page' if res == 500 end desc 'Render all OAS based API references' task verify_oas_reference: :environment do puts 'ci/verify_oas_reference - Render all OAS based API references' session = ActionDispatch::Integration::Session.new(Rails.application) OpenApiConstraint.list.each do |name| res = session.get "/api/#{name}" # Check for migration pending error CommonErrors.check_for_migration_error(session.body) raise "Error rendering /api/#{name} OAS page" if res == 500 end end desc 'Ensure all OAS error URLS resolve' task verify_error_urls_resolve: :environment do puts 'ci/verify_error_urls_resolve - Ensure all OAS error URLS resolve' session = ActionDispatch::Integration::Session.new(Rails.application) session.host! 'localhost' unless Rails.env.test? errors = [] OpenApiConstraint.list.each do |name| puts " - Checking #{name}" definition = OpenApiDefinitionResolver.find(name) definition.endpoints.each do |endpoint| puts " - #{endpoint.method} #{endpoint.path.path}" endpoint.responses.each do |response| puts " - #{response.code}" next if response.code[0] == '2' # Successes don't have error messages response.formats.each do |format| puts " - #{format}" schema = response.schema(format) # Turn everything in to an array to simplify things if schema['oneOf'] properties = schema['oneOf'] else properties = [schema['properties']] end properties.each do |property| # Workaround for issue when referencing from common errors # eg: 10DLC: - $ref: "common/common_errors.yml#/components/responses/DefaultError/content/application~1json/schema" next if property.blank? type = property['type'] # Skip if it's an old-style error next unless type # Grab the example URL example = type['example'] # If it has an example field, and it's a link to NDP if example&.starts_with?('https://developer.nexmo.com/api-errors') # Extract the error error = example.split('#')[1] # Remove the production prefix path = example.gsub('https://developer.nexmo.com', '') # Get the page session.get path next if path.include?('/subaccounts') # Check for migration pending error CommonErrors.check_for_migration_error(session.body) # Make sure it includes the correct ID errors.push({ 'document' => name, 'path' => path }) unless session.response.body.include?("