From 9056ee870cde0fdd990ca724c17cbda1f68f7067 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Thu, 6 Feb 2025 16:08:28 +0100 Subject: [PATCH 1/2] require at least Ruby 3.2 --- prmd.gemspec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/prmd.gemspec b/prmd.gemspec index 7cd612f..3eefc3e 100644 --- a/prmd.gemspec +++ b/prmd.gemspec @@ -18,6 +18,8 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(/^(test|spec|features)\//) spec.require_paths = ['lib'] + spec.required_ruby_version = ">= 3.2" + spec.add_dependency 'erubis', '~> 2.7' spec.add_dependency 'json_schema', '~> 0.3', '>= 0.3.1' From 66446dc5ddd6035e6a6ff2a290b4a4a91dafe75c Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Thu, 6 Feb 2025 16:21:13 +0100 Subject: [PATCH 2/2] all safe rubocop corrections --- .rubocop_todo.yml | 430 +----------------- Gemfile | 2 +- Rakefile | 6 +- bin/prmd | 6 +- lib/prmd.rb | 18 +- lib/prmd/cli.rb | 34 +- lib/prmd/cli/base.rb | 20 +- lib/prmd/cli/combine.rb | 12 +- lib/prmd/cli/doc.rb | 18 +- lib/prmd/cli/generate.rb | 14 +- lib/prmd/cli/render.rb | 14 +- lib/prmd/cli/stub.rb | 4 +- lib/prmd/cli/verify.rb | 14 +- lib/prmd/commands.rb | 8 +- lib/prmd/commands/combine.rb | 36 +- lib/prmd/commands/init.rb | 16 +- lib/prmd/commands/render.rb | 12 +- lib/prmd/commands/verify.rb | 14 +- lib/prmd/core/combiner.rb | 20 +- lib/prmd/core/generator.rb | 4 +- lib/prmd/core/reference_localizer.rb | 18 +- lib/prmd/core/renderer.rb | 10 +- lib/prmd/core/schema_hash.rb | 4 +- lib/prmd/core_ext/optparse.rb | 4 +- lib/prmd/link.rb | 17 +- lib/prmd/load_schema_file.rb | 8 +- lib/prmd/multi_loader.rb | 4 +- lib/prmd/multi_loader/json.rb | 10 +- lib/prmd/multi_loader/loader.rb | 8 +- lib/prmd/multi_loader/toml.rb | 10 +- lib/prmd/multi_loader/yajl.rb | 10 +- lib/prmd/multi_loader/yaml.rb | 10 +- lib/prmd/multi_loader/yml.rb | 2 +- lib/prmd/rake_tasks/base.rb | 10 +- lib/prmd/rake_tasks/combine.rb | 16 +- lib/prmd/rake_tasks/doc.rb | 30 +- lib/prmd/rake_tasks/verify.rb | 16 +- lib/prmd/schema.rb | 89 ++-- lib/prmd/template.rb | 14 +- lib/prmd/url_generator.rb | 10 +- lib/prmd/url_generators/generators/default.rb | 12 +- lib/prmd/url_generators/generators/json.rb | 8 +- lib/prmd/version.rb | 2 +- prmd.gemspec | 40 +- test/cli/combine_test.rb | 16 +- test/cli/doc_test.rb | 20 +- test/cli/generate_test.rb | 14 +- test/cli/render_test.rb | 20 +- test/cli/verify_test.rb | 12 +- test/commands/combine_test.rb | 62 ++- test/commands/init_test.rb | 4 +- test/commands/render_test.rb | 284 ++++++------ test/commands/verify_test.rb | 137 +++--- test/core/reference_localizer_test.rb | 8 +- test/helpers.rb | 157 ++++--- test/link_test.rb | 26 +- test/multi_loader/common.rb | 12 +- test/multi_loader/json_test.rb | 6 +- test/multi_loader/toml_test.rb | 23 +- test/multi_loader/yajl_test.rb | 23 +- test/multi_loader/yaml_test.rb | 6 +- test/rake_tasks/combine_test.rb | 36 +- test/rake_tasks/doc_test.rb | 28 +- test/rake_tasks/verify_test.rb | 16 +- test/schema_test.rb | 30 +- test/utils_test.rb | 2 +- 66 files changed, 784 insertions(+), 1222 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 0ede127..3bfbf75 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,256 +1,11 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2025-02-06 14:33:18 UTC using RuboCop version 1.71.2. +# on 2025-02-06 15:17:15 UTC using RuboCop version 1.71.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: Severity, Include. -# Include: **/*.gemspec -Gemspec/DeprecatedAttributeAssignment: - Exclude: - - 'prmd.gemspec' - -# Offense count: 10 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: with_first_argument, with_fixed_indentation -Layout/ArgumentAlignment: - Exclude: - - 'lib/prmd/core/reference_localizer.rb' - - 'test/core/reference_localizer_test.rb' - - 'test/helpers.rb' - - 'test/rake_tasks/combine_test.rb' - - 'test/rake_tasks/doc_test.rb' - - 'test/rake_tasks/verify_test.rb' - -# Offense count: 11 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: with_first_element, with_fixed_indentation -Layout/ArrayAlignment: - Exclude: - - 'test/cli/combine_test.rb' - - 'test/cli/doc_test.rb' - - 'test/cli/generate_test.rb' - - 'test/cli/render_test.rb' - - 'test/cli/verify_test.rb' - -# Offense count: 8 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AutoCorrect, AllowBorderComment, AllowMarginComment. -Layout/EmptyComment: - Exclude: - - 'lib/prmd/cli/base.rb' - - 'test/helpers.rb' - - 'test/multi_loader/common.rb' - - 'test/multi_loader/toml_test.rb' - - 'test/multi_loader/yajl_test.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Layout/EmptyLineAfterMagicComment: - Exclude: - - 'prmd.gemspec' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EmptyLineBetweenMethodDefs, EmptyLineBetweenClassDefs, EmptyLineBetweenModuleDefs, DefLikeMacros, AllowAdjacentOneLineDefs, NumberOfEmptyLines. -Layout/EmptyLineBetweenDefs: - Exclude: - - 'test/commands/render_test.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Layout/EmptyLines: - Exclude: - - 'test/commands/render_test.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty_lines, no_empty_lines -Layout/EmptyLinesAroundBlockBody: - Exclude: - - 'test/link_test.rb' - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only -Layout/EmptyLinesAroundClassBody: - Exclude: - - 'test/commands/combine_test.rb' - - 'test/link_test.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Layout/EmptyLinesAroundMethodBody: - Exclude: - - 'test/helpers.rb' - -# Offense count: 13 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment. -Layout/ExtraSpacing: - Exclude: - - 'lib/prmd/commands/init.rb' - - 'lib/prmd/link.rb' - - 'prmd.gemspec' - -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: special_inside_parentheses, consistent, align_braces -Layout/FirstHashElementIndentation: - Exclude: - - 'test/commands/render_test.rb' - -# Offense count: 83 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. -# SupportedHashRocketStyles: key, separator, table -# SupportedColonStyles: key, separator, table -# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit -Layout/HashAlignment: - Exclude: - - 'lib/prmd/cli.rb' - - 'lib/prmd/schema.rb' - - 'test/commands/combine_test.rb' - - 'test/commands/render_test.rb' - - 'test/commands/verify_test.rb' - - 'test/helpers.rb' - - 'test/schema_test.rb' - -# Offense count: 15 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowDoxygenCommentStyle, AllowGemfileRubyComment, AllowRBSInlineAnnotation, AllowSteepAnnotation. -Layout/LeadingCommentSpace: - Exclude: - - 'lib/prmd/load_schema_file.rb' - - 'lib/prmd/multi_loader/json.rb' - - 'lib/prmd/multi_loader/loader.rb' - - 'lib/prmd/multi_loader/toml.rb' - - 'lib/prmd/multi_loader/yajl.rb' - - 'lib/prmd/multi_loader/yaml.rb' - - 'test/rake_tasks/combine_test.rb' - - 'test/rake_tasks/doc_test.rb' - -Security/YAMLLoad: - Exclude: - - 'lib/prmd/multi_loader/yaml.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Layout/MultilineBlockLayout: - Exclude: - - 'lib/prmd/commands/combine.rb' - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: symmetrical, new_line, same_line -Layout/MultilineHashBraceLayout: - Exclude: - - 'test/helpers.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: aligned, indented, indented_relative_to_receiver -Layout/MultilineMethodCallIndentation: - Exclude: - - 'lib/prmd/core/reference_localizer.rb' - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: aligned, indented -Layout/MultilineOperationIndentation: - Exclude: - - 'lib/prmd/commands/render.rb' - -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -Layout/SpaceAfterComma: - Exclude: - - 'lib/prmd/commands/combine.rb' - - 'lib/prmd/url_generators/generators/default.rb' - - 'lib/prmd/url_generators/generators/json.rb' - -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: space, no_space -Layout/SpaceAroundEqualsInParameterDefault: - Exclude: - - 'lib/prmd/link.rb' - -# Offense count: 58 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator, EnforcedStyleForRationalLiterals. -# SupportedStylesForExponentOperator: space, no_space -# SupportedStylesForRationalLiterals: space, no_space -Layout/SpaceAroundOperators: - Exclude: - - 'test/commands/render_test.rb' - - 'test/helpers.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Layout/SpaceBeforeComma: - Exclude: - - 'test/link_test.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. -# SupportedStyles: space, no_space -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceInsideBlockBraces: - Exclude: - - 'lib/prmd/url_generators/generators/json.rb' - -# Offense count: 23 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. -# SupportedStyles: space, no_space, compact -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceInsideHashLiteralBraces: - Exclude: - - 'lib/prmd/link.rb' - - 'test/commands/combine_test.rb' - - 'test/commands/render_test.rb' - - 'test/commands/verify_test.rb' - - 'test/helpers.rb' - - 'test/link_test.rb' - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: space, compact, no_space -Layout/SpaceInsideParens: - Exclude: - - 'lib/prmd/link.rb' - - 'test/link_test.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowInHeredoc. -Layout/TrailingWhitespace: - Exclude: - - 'lib/prmd/link.rb' - -# Offense count: 12 -# This cop supports safe autocorrection (--autocorrect). -Lint/AmbiguousRegexpLiteral: - Exclude: - - 'test/commands/render_test.rb' - - 'test/commands/verify_test.rb' - # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: AllowSafeAssignment. @@ -258,6 +13,10 @@ Lint/AssignmentInCondition: Exclude: - 'lib/prmd/core/combiner.rb' +Security/YAMLLoad: + Exclude: + - 'lib/prmd/multi_loader/yaml.rb' + # Offense count: 1 Naming/ConstantName: Exclude: @@ -270,188 +29,9 @@ Security/JSONLoad: - 'lib/prmd/cli/base.rb' - 'lib/prmd/multi_loader/json.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: prefer_alias, prefer_alias_method -Style/Alias: - Exclude: - - 'lib/prmd/core_ext/optparse.rb' - -# Offense count: 30 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowOnlyRestArgument, UseAnonymousForwarding, RedundantRestArgumentNames, RedundantKeywordRestArgumentNames, RedundantBlockArgumentNames. -# RedundantRestArgumentNames: args, arguments -# RedundantKeywordRestArgumentNames: kwargs, options, opts -# RedundantBlockArgumentNames: blk, block, proc -Style/ArgumentsForwarding: - Exclude: - - 'lib/prmd/rake_tasks/combine.rb' - - 'lib/prmd/rake_tasks/doc.rb' - - 'lib/prmd/rake_tasks/verify.rb' - - 'lib/prmd/template.rb' - - 'test/helpers.rb' - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions. -# SupportedStyles: assign_to_condition, assign_inside_condition -Style/ConditionalAssignment: - Exclude: - - 'lib/prmd/schema.rb' - - 'lib/prmd/url_generator.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Style/EmptyCaseCondition: - Exclude: - - 'lib/prmd/link.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Style/Encoding: - Exclude: - - 'prmd.gemspec' - -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -Style/FileWrite: - Exclude: - - 'lib/prmd/cli/base.rb' - - 'lib/prmd/rake_tasks/combine.rb' - - 'lib/prmd/rake_tasks/doc.rb' - # Offense count: 67 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle. # SupportedStyles: always, always_true, never Style/FrozenStringLiteralComment: Enabled: false - -# Offense count: 4 -# This cop supports safe autocorrection (--autocorrect). -Style/IfUnlessModifierOfIfUnless: - Exclude: - - 'test/rake_tasks/combine_test.rb' - - 'test/rake_tasks/doc_test.rb' - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -Style/MultilineIfModifier: - Exclude: - - 'test/multi_loader/toml_test.rb' - - 'test/multi_loader/yajl_test.rb' - -# Offense count: 4 -# This cop supports safe autocorrection (--autocorrect). -Style/NestedModifier: - Exclude: - - 'test/rake_tasks/combine_test.rb' - - 'test/rake_tasks/doc_test.rb' - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantAssignment: - Exclude: - - 'lib/prmd/cli.rb' - - 'lib/prmd/schema.rb' - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantBegin: - Exclude: - - 'lib/prmd/commands/combine.rb' - - 'lib/prmd/schema.rb' - -# Offense count: 9 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantRegexpEscape: - Exclude: - - 'test/commands/render_test.rb' - -# Offense count: 6 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowMultipleReturnValues. -Style/RedundantReturn: - Exclude: - - 'lib/prmd/cli/base.rb' - - 'lib/prmd/link.rb' - - 'lib/prmd/rake_tasks/base.rb' - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantSelf: - Exclude: - - 'lib/prmd/link.rb' - -# Offense count: 6 -# This cop supports safe autocorrection (--autocorrect). -Style/StderrPuts: - Exclude: - - 'lib/prmd/cli/base.rb' - - 'lib/prmd/cli/verify.rb' - - 'lib/prmd/commands/combine.rb' - - 'lib/prmd/core/combiner.rb' - - 'lib/prmd/rake_tasks/verify.rb' - - 'lib/prmd/schema.rb' - -# Offense count: 733 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. -# SupportedStyles: single_quotes, double_quotes -Style/StringLiterals: - Enabled: false - -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -Style/SuperWithArgsParentheses: - Exclude: - - 'lib/prmd/rake_tasks/combine.rb' - - 'lib/prmd/rake_tasks/doc.rb' - - 'lib/prmd/rake_tasks/verify.rb' - -# Offense count: 9 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInArguments: - Exclude: - - 'lib/prmd/core/reference_localizer.rb' - - 'test/helpers.rb' - - 'test/rake_tasks/combine_test.rb' - - 'test/rake_tasks/doc_test.rb' - - 'test/rake_tasks/verify_test.rb' - - 'test/schema_test.rb' - -# Offense count: 20 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInArrayLiteral: - Exclude: - - 'lib/prmd/commands/verify.rb' - - 'lib/prmd/schema.rb' - - 'test/cli/combine_test.rb' - - 'test/cli/doc_test.rb' - - 'test/cli/generate_test.rb' - - 'test/cli/render_test.rb' - - 'test/cli/verify_test.rb' - - 'test/commands/combine_test.rb' - - 'test/commands/render_test.rb' - - 'test/commands/verify_test.rb' - - 'test/link_test.rb' - -# Offense count: 94 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInHashLiteral: - Exclude: - - 'lib/prmd/cli.rb' - - 'lib/prmd/core/renderer.rb' - - 'test/commands/combine_test.rb' - - 'test/commands/render_test.rb' - - 'test/commands/verify_test.rb' - - 'test/helpers.rb' - - 'test/link_test.rb' - - 'test/rake_tasks/combine_test.rb' diff --git a/Gemfile b/Gemfile index 82c4129..1b5e8b4 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source 'https://rubygems.org' +source "https://rubygems.org" # Specify your gem's dependencies in prmd.gemspec gemspec diff --git a/Rakefile b/Rakefile index cad4825..b79e6d5 100644 --- a/Rakefile +++ b/Rakefile @@ -1,8 +1,8 @@ -require 'bundler/gem_tasks' -require 'rake/testtask' +require "bundler/gem_tasks" +require "rake/testtask" Rake::TestTask.new do |t| - t.pattern = 'test/**/*_test.rb' + t.pattern = "test/**/*_test.rb" end task default: :test diff --git a/bin/prmd b/bin/prmd index c06e883..5cef8aa 100755 --- a/bin/prmd +++ b/bin/prmd @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require 'optparse' -require_relative '../lib/prmd' -require_relative '../lib/prmd/cli' +require "optparse" +require_relative "../lib/prmd" +require_relative "../lib/prmd/cli" Prmd::CLI.run(ARGV.dup, bin: File.basename(__FILE__)) diff --git a/lib/prmd.rb b/lib/prmd.rb index f699701..814dc36 100644 --- a/lib/prmd.rb +++ b/lib/prmd.rb @@ -1,9 +1,9 @@ -require_relative 'prmd/version' -require_relative 'prmd/load_schema_file' -require_relative 'prmd/commands' -require_relative 'prmd/schema' -require_relative 'prmd/link' -require_relative 'prmd/utils' -require_relative 'prmd/template' -require_relative 'prmd/url_generator' -require_relative 'prmd/hash_helpers' +require_relative "prmd/version" +require_relative "prmd/load_schema_file" +require_relative "prmd/commands" +require_relative "prmd/schema" +require_relative "prmd/link" +require_relative "prmd/utils" +require_relative "prmd/template" +require_relative "prmd/url_generator" +require_relative "prmd/hash_helpers" diff --git a/lib/prmd/cli.rb b/lib/prmd/cli.rb index 043f284..04bfe47 100644 --- a/lib/prmd/cli.rb +++ b/lib/prmd/cli.rb @@ -1,10 +1,10 @@ -require_relative 'core_ext/optparse' -require_relative 'cli/combine' -require_relative 'cli/doc' -require_relative 'cli/generate' -require_relative 'cli/render' -require_relative 'cli/stub' -require_relative 'cli/verify' +require_relative "core_ext/optparse" +require_relative "cli/combine" +require_relative "cli/doc" +require_relative "cli/generate" +require_relative "cli/render" +require_relative "cli/stub" +require_relative "cli/verify" # :nodoc: module Prmd @@ -15,11 +15,11 @@ module CLI def self.make_command_parsers(props = {}) { combine: CLI::Combine.make_parser(props), - doc: CLI::Doc.make_parser(props), - init: CLI::Generate.make_parser(props), - render: CLI::Render.make_parser(props), - stub: CLI::Stub.make_parser(props), - verify: CLI::Verify.make_parser(props) + doc: CLI::Doc.make_parser(props), + init: CLI::Generate.make_parser(props), + render: CLI::Render.make_parser(props), + stub: CLI::Stub.make_parser(props), + verify: CLI::Verify.make_parser(props), } end @@ -35,7 +35,7 @@ def self.commands # @param [Hash] options # @param [Hash] props def self.make_parser(options, props = {}) - binname = props.fetch(:bin, 'prmd') + binname = props.fetch(:bin, "prmd") # This is only used to attain the help commands commands = make_command_parsers(props) @@ -43,21 +43,19 @@ def self.make_parser(options, props = {}) " #{command.banner}" end.join("\n") - global = OptionParser.new do |opts| + OptionParser.new do |opts| opts.banner = "Usage: #{binname} [options] [command [options]]" opts.separator "\nAvailable options:" - opts.on('--version', 'Return version') do + opts.on("--version", "Return version") do puts "prmd #{Prmd::VERSION}" exit(0) end - opts.on('--noop', 'Commands will not execute') do |v| + opts.on("--noop", "Commands will not execute") do |v| options[:noop] = v end opts.separator "\nAvailable commands:" opts.separator help_text end - - global end # Parse top level CLI options from argv diff --git a/lib/prmd/cli/base.rb b/lib/prmd/cli/base.rb index 045dab0..af0cbb1 100644 --- a/lib/prmd/cli/base.rb +++ b/lib/prmd/cli/base.rb @@ -1,6 +1,6 @@ -require 'json' -require_relative '../core_ext/optparse' -require_relative '../load_schema_file' +require "json" +require_relative "../core_ext/optparse" +require_relative "../load_schema_file" module Prmd module CLI @@ -23,7 +23,6 @@ module Base # @return [OptionParser] newly created parser # @abstract def make_parser(options = {}) - # end # Runs the provided parser with the provided argv. @@ -82,9 +81,7 @@ def parse_options(argv, options = {}) def write_result(data, options = {}) output_file = options[:output_file] if output_file - File.open(output_file, 'w') do |f| - f.write(data) - end + File.write(output_file, data) else $stdout.puts data end @@ -96,11 +93,11 @@ def write_result(data, options = {}) # @return [Array[Symbol, String]] source, data def try_read(filename = nil) if filename && !filename.empty? - return :file, Prmd.load_schema_file(filename) + [:file, Prmd.load_schema_file(filename)] elsif !$stdin.tty? - return :io, JSON.load($stdin.read) + [:io, JSON.load($stdin.read)] else - abort 'Nothing to read' + abort "Nothing to read" end end @@ -111,7 +108,6 @@ def try_read(filename = nil) # @return [void] # @abstract def execute(options = {}) - # end # Method called when the command is ran with the :noop option enabled. @@ -120,7 +116,7 @@ def execute(options = {}) # @param [Hash] options # @return [void] def noop_execute(options = {}) - $stderr.puts options + warn options end # Run this command given a argv and optional options Hash. diff --git a/lib/prmd/cli/combine.rb b/lib/prmd/cli/combine.rb index acda470..9a7fe1b 100644 --- a/lib/prmd/cli/combine.rb +++ b/lib/prmd/cli/combine.rb @@ -1,5 +1,5 @@ -require_relative 'base' -require_relative '../commands/combine' +require_relative "base" +require_relative "../commands/combine" module Prmd module CLI @@ -12,17 +12,17 @@ module Combine # @param (see Prmd::CLI::Base#make_parser) # @return (see Prmd::CLI::Base#make_parser) def self.make_parser(options = {}) - binname = options.fetch(:bin, 'prmd') + binname = options.fetch(:bin, "prmd") OptionParser.new do |opts| opts.banner = "#{binname} combine [options] " - opts.on('-m', '--meta FILENAME', String, 'Set defaults for schemata') do |m| + opts.on("-m", "--meta FILENAME", String, "Set defaults for schemata") do |m| yield :meta, m end - opts.on('-o', '--output-file FILENAME', String, 'File to write result to') do |n| + opts.on("-o", "--output-file FILENAME", String, "File to write result to") do |n| yield :output_file, n end - opts.on('-t', '--type-as-string', 'Allow type as string') do |t| + opts.on("-t", "--type-as-string", "Allow type as string") do |t| options[:type_as_string] = t end end diff --git a/lib/prmd/cli/doc.rb b/lib/prmd/cli/doc.rb index 7f32cb4..640de8d 100644 --- a/lib/prmd/cli/doc.rb +++ b/lib/prmd/cli/doc.rb @@ -1,6 +1,6 @@ -require_relative 'base' -require_relative '../commands/render' -require_relative '../hash_helpers' +require_relative "base" +require_relative "../commands/render" +require_relative "../hash_helpers" module Prmd module CLI @@ -13,22 +13,22 @@ module Doc # @param (see Prmd::CLI::Base#make_parser) # @return (see Prmd::CLI::Base#make_parser) def self.make_parser(options = {}) - binname = options.fetch(:bin, 'prmd') + binname = options.fetch(:bin, "prmd") OptionParser.new do |opts| opts.banner = "#{binname} doc [options] " - opts.on('-s', '--settings FILENAME', String, 'Config file to use') do |s| + opts.on("-s", "--settings FILENAME", String, "Config file to use") do |s| settings = Prmd.load_schema_file(s) || {} options = HashHelpers.deep_symbolize_keys(settings) yield :settings, options end - opts.on('-c', '--content-type application/json', String, 'Content-Type header') do |c| + opts.on("-c", "--content-type application/json", String, "Content-Type header") do |c| yield :content_type, c end - opts.on('-o', '--output-file FILENAME', String, 'File to write result to') do |n| + opts.on("-o", "--output-file FILENAME", String, "File to write result to") do |n| yield :output_file, n end - opts.on('-p', '--prepend header,overview', Array, 'Prepend files to output') do |p| + opts.on("-p", "--prepend header,overview", Array, "Prepend files to output") do |p| yield :prepend, p end end @@ -58,7 +58,7 @@ def self.set_option(options, key, value) # @return (see Prmd::CLI::Base#execute) def self.execute(options = {}) filename = options.fetch(:argv).first - template = File.expand_path('templates', File.dirname(__FILE__)) + template = File.expand_path("templates", File.dirname(__FILE__)) _, data = try_read(filename) schema = Prmd::Schema.new(data) opts = options.merge(template: template) diff --git a/lib/prmd/cli/generate.rb b/lib/prmd/cli/generate.rb index ba53e80..925d394 100644 --- a/lib/prmd/cli/generate.rb +++ b/lib/prmd/cli/generate.rb @@ -1,6 +1,6 @@ -require_relative 'base' -require_relative '../commands/init' -require_relative '../utils' +require_relative "base" +require_relative "../commands/init" +require_relative "../utils" module Prmd module CLI @@ -15,17 +15,17 @@ module Generate # @param (see Prmd::CLI::Base#make_parser) # @return (see Prmd::CLI::Base#make_parser) def self.make_parser(options = {}) - binname = options.fetch(:bin, 'prmd') + binname = options.fetch(:bin, "prmd") OptionParser.new do |opts| opts.banner = "#{binname} init [options] " - opts.on('-t', '--template templates', String, 'Use alternate template') do |t| + opts.on("-t", "--template templates", String, "Use alternate template") do |t| yield :template, t end - opts.on('-y', '--yaml', 'Generate YAML') do |y| + opts.on("-y", "--yaml", "Generate YAML") do |y| yield :yaml, y end - opts.on('-o', '--output-file FILENAME', String, 'File to write result to') do |n| + opts.on("-o", "--output-file FILENAME", String, "File to write result to") do |n| yield :output_file, n end end diff --git a/lib/prmd/cli/render.rb b/lib/prmd/cli/render.rb index c739748..883ecf4 100644 --- a/lib/prmd/cli/render.rb +++ b/lib/prmd/cli/render.rb @@ -1,5 +1,5 @@ -require_relative 'base' -require_relative '../commands/render' +require_relative "base" +require_relative "../commands/render" module Prmd module CLI @@ -12,20 +12,20 @@ module Render # @param (see Prmd::CLI::Base#make_parser) # @return (see Prmd::CLI::Base#make_parser) def self.make_parser(options = {}) - binname = options.fetch(:bin, 'prmd') + binname = options.fetch(:bin, "prmd") OptionParser.new do |opts| opts.banner = "#{binname} render [options] " - opts.on('-c', '--content-type application/json', String, 'Content-Type header') do |c| + opts.on("-c", "--content-type application/json", String, "Content-Type header") do |c| yield :content_type, c end - opts.on('-o', '--output-file FILENAME', String, 'File to write result to') do |n| + opts.on("-o", "--output-file FILENAME", String, "File to write result to") do |n| yield :output_file, n end - opts.on('-p', '--prepend header,overview', Array, 'Prepend files to output') do |p| + opts.on("-p", "--prepend header,overview", Array, "Prepend files to output") do |p| yield :prepend, p end - opts.on('-t', '--template templates', String, 'Use alternate template') do |t| + opts.on("-t", "--template templates", String, "Use alternate template") do |t| yield :template, t end end diff --git a/lib/prmd/cli/stub.rb b/lib/prmd/cli/stub.rb index 15aea80..c82713d 100644 --- a/lib/prmd/cli/stub.rb +++ b/lib/prmd/cli/stub.rb @@ -1,4 +1,4 @@ -require_relative 'base' +require_relative "base" module Prmd module CLI @@ -11,7 +11,7 @@ module Stub # @param (see Prmd::CLI::Base#make_parser) # @return (see Prmd::CLI::Base#make_parser) def self.make_parser(options = {}) - binname = options.fetch(:bin, 'prmd') + binname = options.fetch(:bin, "prmd") OptionParser.new do |opts| opts.banner = "#{binname} stub [options] " diff --git a/lib/prmd/cli/verify.rb b/lib/prmd/cli/verify.rb index 4af9f4c..04db73d 100644 --- a/lib/prmd/cli/verify.rb +++ b/lib/prmd/cli/verify.rb @@ -1,5 +1,5 @@ -require_relative 'base' -require_relative '../commands/verify' +require_relative "base" +require_relative "../commands/verify" module Prmd module CLI @@ -12,17 +12,17 @@ module Verify # @param (see Prmd::CLI::Base#make_parser) # @return (see Prmd::CLI::Base#make_parser) def self.make_parser(options = {}) - binname = options.fetch(:bin, 'prmd') + binname = options.fetch(:bin, "prmd") OptionParser.new do |opts| opts.banner = "#{binname} verify [options] " - opts.on('-y', '--yaml', 'Generate YAML') do |y| + opts.on("-y", "--yaml", "Generate YAML") do |y| yield :yaml, y end - opts.on('-o', '--output-file FILENAME', String, 'File to write result to') do |n| + opts.on("-o", "--output-file FILENAME", String, "File to write result to") do |n| yield :output_file, n end - opts.on('-s', '--custom-schema FILENAME', String, 'Path to custom schema') do |n| + opts.on("-s", "--custom-schema FILENAME", String, "Path to custom schema") do |n| yield :custom_schema, n end end @@ -42,7 +42,7 @@ def self.execute(options = {}) errors = Prmd.verify(data, custom_schema: custom_schema) unless errors.empty? errors.map! { |error| "#{filename}: #{error}" } if filename - errors.each { |error| $stderr.puts(error) } + errors.each { |error| warn(error) } exit(1) end result = options[:yaml] ? data.to_yaml : JSON.pretty_generate(data) diff --git a/lib/prmd/commands.rb b/lib/prmd/commands.rb index ebc440f..c76cd0a 100644 --- a/lib/prmd/commands.rb +++ b/lib/prmd/commands.rb @@ -1,4 +1,4 @@ -require_relative 'commands/combine' -require_relative 'commands/init' -require_relative 'commands/render' -require_relative 'commands/verify' +require_relative "commands/combine" +require_relative "commands/init" +require_relative "commands/render" +require_relative "commands/verify" diff --git a/lib/prmd/commands/combine.rb b/lib/prmd/commands/combine.rb index e518db0..d16b8a6 100644 --- a/lib/prmd/commands/combine.rb +++ b/lib/prmd/commands/combine.rb @@ -1,6 +1,6 @@ -require_relative '../load_schema_file' -require_relative '../core/schema_hash' -require_relative '../core/combiner' +require_relative "../load_schema_file" +require_relative "../core/schema_hash" +require_relative "../core/combiner" # :nodoc: module Prmd @@ -12,9 +12,9 @@ module Combine # @return [void] def self.handle_faulty_load(given, expected) unless given.size == expected.size - abort 'Somes files have failed to parse. ' \ - 'If you wish to continue without them,' \ - 'please enable faulty_load using --faulty-load' + abort "Somes files have failed to parse. " \ + "If you wish to continue without them," \ + "please enable faulty_load using --faulty-load" end end @@ -25,7 +25,7 @@ def self.handle_faulty_load(given, expected) def self.crawl_map(paths, options = {}) files = [*paths].map do |path| if File.directory?(path) - Dir.glob(File.join(path, '**', '*.{json,yml,yaml}')) + Dir.glob(File.join(path, "**", "*.{json,yml,yaml}")) else path end @@ -49,11 +49,9 @@ def self.load_schema_hash(filename) # @return [Array] schema hashes def self.load_files(files, options = {}) files.each_with_object([]) do |filename, result| - begin - result << load_schema_hash(filename) - rescue JSON::ParserError, Psych::SyntaxError => ex - $stderr.puts "unable to parse #{filename} (#{ex.inspect})" - end + result << load_schema_hash(filename) + rescue JSON::ParserError, Psych::SyntaxError => ex + warn "unable to parse #{filename} (#{ex.inspect})" end end @@ -79,15 +77,15 @@ def self.load_schemas(paths, options = {}) # @return [Array] schema hashes def self.escape_hrefs(data) if data.is_a? Array - data.map! { - |x| escape_hrefs(x) + data.map! { |x| + escape_hrefs(x) } elsif data.is_a?(Hash) || data.is_a?(Prmd::SchemaHash) - data.each { |k,v| - if k == 'href' + data.each { |k, v| + if k == "href" if v.is_a? String v = v.gsub(/\{\(.*?\)\}/) { |x| - x.gsub('#', '%23').gsub('/', '%2F') + x.gsub("#", "%23").gsub("/", "%2F") } end else @@ -106,8 +104,8 @@ def self.escape_hrefs(data) # @return (see Prmd::Combiner#combine) def self.combine(paths, options = {}) schemata = escape_hrefs(load_schemas(paths)) - base = Prmd::Template.load_json('combine_head.json') - schema = base['$schema'] + base = Prmd::Template.load_json("combine_head.json") + schema = base["$schema"] meta = {} filename = options[:meta] meta = Prmd.load_schema_file(filename) if filename diff --git a/lib/prmd/commands/init.rb b/lib/prmd/commands/init.rb index 681cc64..873a110 100644 --- a/lib/prmd/commands/init.rb +++ b/lib/prmd/commands/init.rb @@ -1,6 +1,6 @@ -require 'json' -require_relative '../template' -require_relative '../core/generator' +require "json" +require_relative "../template" +require_relative "../core/generator" # :nodoc: module Prmd @@ -10,9 +10,9 @@ module Generate # # @return [Prmd::Generator] def self.make_generator(options) - base = Prmd::Template.load_json('init_default.json') + base = Prmd::Template.load_json("init_default.json") template_name = options.fetch(:template) do - abort 'render: Template was not provided' + abort "render: Template was not provided" end if template_name && !template_name.empty? template_dir = File.expand_path(template_name) @@ -20,8 +20,8 @@ def self.make_generator(options) template_dir = File.dirname(template_name) unless File.directory?(template_dir) template_name = File.basename(template_name) else - template_name = 'init_resource.json.erb' - template_dir = '' + template_name = "init_resource.json.erb" + template_dir = "" end template = Prmd::Template.load_template(template_name, template_dir) Prmd::Generator.new(base: base, template: template) @@ -39,7 +39,7 @@ def self.init(resource, options = {}) generator_options = { resource: nil, parent: nil } if resource parent = nil - parent, resource = resource.split('/') if resource.include?('/') + parent, resource = resource.split("/") if resource.include?("/") generator_options[:parent] = parent generator_options[:resource] = resource end diff --git a/lib/prmd/commands/render.rb b/lib/prmd/commands/render.rb index 60f3c72..b842902 100644 --- a/lib/prmd/commands/render.rb +++ b/lib/prmd/commands/render.rb @@ -1,4 +1,4 @@ -require_relative '../core/renderer' +require_relative "../core/renderer" # :nodoc: module Prmd @@ -10,12 +10,12 @@ module Render # @return (see Prmd::Template.load_template) def self.get_template(options) template = options.fetch(:template) do - abort 'render: Template was not provided' + abort "render: Template was not provided" end template_dir = File.expand_path(template) # to keep backward compatibility template_dir = File.dirname(template) unless File.directory?(template_dir) - Prmd::Template.load_template('schema.erb', template_dir) + Prmd::Template.load_template("schema.erb", template_dir) end end @@ -25,11 +25,11 @@ def self.get_template(options) # @return [String] rendered schema in Markdown def self.render(schema, options = {}) renderer = Prmd::Renderer.new(template: Render.get_template(options)) - doc = '' + doc = "" if options[:prepend] doc << - options[:prepend].map { |path| File.read(path) }.join("\n") << - "\n" + options[:prepend].map { |path| File.read(path) }.join("\n") << + "\n" end doc << renderer.render(schema, options) doc diff --git a/lib/prmd/commands/verify.rb b/lib/prmd/commands/verify.rb index 21acfc5..01b039f 100644 --- a/lib/prmd/commands/verify.rb +++ b/lib/prmd/commands/verify.rb @@ -1,5 +1,5 @@ -require 'json' -require 'json_schema' +require "json" +require "json_schema" # :nodoc: module Prmd @@ -8,9 +8,9 @@ module Verification # These schemas are listed manually and in order because they reference each # other. SCHEMAS = [ - 'schema.json', - 'hyper-schema.json', - 'interagent-hyper-schema.json' + "schema.json", + "hyper-schema.json", + "interagent-hyper-schema.json", ] # @return [JsonSchema::DocumentStore] @@ -62,8 +62,8 @@ def self.verify_meta_schema(meta_schema, schema_data) # @param [Hash] schema_data # @return [Array] errors from failed verfication def self.verify_schema(schema_data) - schema_uri = schema_data['$schema'] - return ['Missing $schema key.'] unless schema_uri + schema_uri = schema_data["$schema"] + return ["Missing $schema key."] unless schema_uri meta_schema = document_store.lookup_schema(schema_uri) return ["Unknown $schema: #{schema_uri}."] unless meta_schema diff --git a/lib/prmd/core/combiner.rb b/lib/prmd/core/combiner.rb index 80c069c..c793c4e 100644 --- a/lib/prmd/core/combiner.rb +++ b/lib/prmd/core/combiner.rb @@ -1,6 +1,6 @@ -require_relative '../schema' -require_relative 'schema_hash' -require_relative 'reference_localizer' +require_relative "../schema" +require_relative "schema_hash" +require_relative "reference_localizer" # :nodoc: module Prmd @@ -34,24 +34,24 @@ def combine(*schemata) data.merge!(@meta) schemata.each do |schema| - id = schema.fetch('id') - id_ary = id.split('/').last + id = schema.fetch("id") + id_ary = id.split("/").last if s = schemata_map[id] - $stderr.puts "`#{id}` (from #{schema.filename}) was already defined " \ + warn "`#{id}` (from #{schema.filename}) was already defined " \ "in `#{s.filename}` and will overwrite the first " \ "definition" end # avoinding damaging the original schema embedded_schema = schema.dup # schemas are now in a single scope by combine - embedded_schema.delete('id') + embedded_schema.delete("id") schemata_map[id] = embedded_schema - data['definitions'][id_ary] = embedded_schema.to_h - data['properties'][id_ary] = { '$ref' => "#/definitions/#{id_ary}" } + data["definitions"][id_ary] = embedded_schema.to_h + data["properties"][id_ary] = { "$ref" => "#/definitions/#{id_ary}" } - reference_localizer(data['definitions'][id_ary]) + reference_localizer(data["definitions"][id_ary]) end Prmd::Schema.new(data, @options) diff --git a/lib/prmd/core/generator.rb b/lib/prmd/core/generator.rb index c07e8fe..51ebd51 100644 --- a/lib/prmd/core/generator.rb +++ b/lib/prmd/core/generator.rb @@ -1,5 +1,5 @@ -require 'json' -require_relative '../schema' +require "json" +require_relative "../schema" # :nodoc: module Prmd diff --git a/lib/prmd/core/reference_localizer.rb b/lib/prmd/core/reference_localizer.rb index 4f512cd..b2fc0c1 100644 --- a/lib/prmd/core/reference_localizer.rb +++ b/lib/prmd/core/reference_localizer.rb @@ -60,15 +60,15 @@ def localize end def localize_ref - return unless hash.key?('$ref') - hash['$ref'] = '#/definitions' + local_reference + return unless hash.key?("$ref") + hash["$ref"] = "#/definitions" + local_reference end def localize_href - return unless hash.key?('href') && hash['href'].is_a?(String) - hash['href'] = hash['href'].gsub('%23', '') - .gsub(/%2Fschemata(%2F[^%]*%2F)/, - '%23%2Fdefinitions\1') + return unless hash.key?("href") && hash["href"].is_a?(String) + hash["href"] = hash["href"].gsub("%23", "") + .gsub(/%2Fschemata(%2F[^%]*%2F)/, + '%23%2Fdefinitions\1',) end # @return [Hash] @@ -78,10 +78,10 @@ def localize_values # @return [String] def local_reference - ref = hash['$ref'] + ref = hash["$ref"] # clean out leading #/definitions to not create a duplicate one - ref = ref.gsub(/^#\/definitions\//, '#/') while ref.match(/^#\/definitions\//) - ref.gsub('#', '').gsub('/schemata', '') + ref = ref.gsub(/^#\/definitions\//, "#/") while ref.match(/^#\/definitions\//) + ref.gsub("#", "").gsub("/schemata", "") end private :localize_ref diff --git a/lib/prmd/core/renderer.rb b/lib/prmd/core/renderer.rb index c577ef4..92c0098 100644 --- a/lib/prmd/core/renderer.rb +++ b/lib/prmd/core/renderer.rb @@ -1,4 +1,4 @@ -require_relative '../template' +require_relative "../template" # :nodoc: module Prmd @@ -16,9 +16,9 @@ def initialize(properties = {}) def default_options { http_header: {}, - content_type: 'application/json', + content_type: "application/json", doc: {}, - prepend: nil + prepend: nil, } end @@ -27,9 +27,9 @@ def default_options # @return [void] def append_default_options(options) options[:doc] = { - url_style: 'default', + url_style: "default", disable_title_and_description: false, - toc: false + toc: false, }.merge(options[:doc]) end diff --git a/lib/prmd/core/schema_hash.rb b/lib/prmd/core/schema_hash.rb index aa171e7..5e1863b 100644 --- a/lib/prmd/core/schema_hash.rb +++ b/lib/prmd/core/schema_hash.rb @@ -1,4 +1,4 @@ -require 'forwardable' +require "forwardable" # :nodoc: module Prmd @@ -20,7 +20,7 @@ class SchemaHash # @param [Hash] options def initialize(data, options = {}) @data = data - @filename = options.fetch(:filename, '') + @filename = options.fetch(:filename, "") end # @param [Prmd::SchemaHash] other diff --git a/lib/prmd/core_ext/optparse.rb b/lib/prmd/core_ext/optparse.rb index b3d8dae..47c30f8 100644 --- a/lib/prmd/core_ext/optparse.rb +++ b/lib/prmd/core_ext/optparse.rb @@ -1,6 +1,6 @@ -require 'optparse' +require "optparse" # Extension of the standard library OptionParser class OptionParser - alias :to_str :to_s + alias_method :to_str, :to_s end diff --git a/lib/prmd/link.rb b/lib/prmd/link.rb index 4a3721f..cacec0d 100644 --- a/lib/prmd/link.rb +++ b/lib/prmd/link.rb @@ -1,20 +1,20 @@ -require 'ostruct' +require "ostruct" module Prmd class Link def initialize(link_schema) - @link_schema = link_schema + @link_schema = link_schema end def required_and_optional_parameters - @params = {required: {}, optional: {} } + @params = { required: {}, optional: {} } recurse_properties(Schema.new(@link_schema["schema"]), "") [@params[:required], @params[:optional]] end private - def recurse_properties(schema, prefix ="", parent_required= false ) + def recurse_properties(schema, prefix = "", parent_required = false) return unless schema.has_properties? schema.properties.keys.each do |prop_name| @@ -27,8 +27,7 @@ def recurse_properties(schema, prefix ="", parent_required= false ) end def handle_property(property, prefix, required = false) - case - when property_is_object?(property["type"]) + if property_is_object?(property["type"]) recurse_properties(Schema.new(property), "#{prefix}:", required) else categorize_parameter(prefix, property, required) @@ -40,18 +39,18 @@ def property_is_object?(type) type == "object" || type.include?("object") end - def categorize_parameter(name, param, required=false) + def categorize_parameter(name, param, required = false) @params[(required ? :required : :optional)][name] = param end class Schema < OpenStruct def has_properties? - self.properties && !self.properties.empty? + properties && !properties.empty? end def property_is_required?(property_name) return false unless required - return required.include?(property_name) + required.include?(property_name) end end end diff --git a/lib/prmd/load_schema_file.rb b/lib/prmd/load_schema_file.rb index 3e7dacb..0edf93a 100644 --- a/lib/prmd/load_schema_file.rb +++ b/lib/prmd/load_schema_file.rb @@ -1,8 +1,8 @@ -require 'yaml' -require 'json' -require_relative 'multi_loader' +require "yaml" +require "json" +require_relative "multi_loader" -module Prmd #:nodoc: +module Prmd # :nodoc: # Attempts to load either a json or yaml file, the type is determined by # filename extension. # diff --git a/lib/prmd/multi_loader.rb b/lib/prmd/multi_loader.rb index 4685383..1d40530 100644 --- a/lib/prmd/multi_loader.rb +++ b/lib/prmd/multi_loader.rb @@ -1,2 +1,2 @@ -require_relative 'multi_loader/json' -require_relative 'multi_loader/yaml' +require_relative "multi_loader/json" +require_relative "multi_loader/yaml" diff --git a/lib/prmd/multi_loader/json.rb b/lib/prmd/multi_loader/json.rb index ac4b326..20f469b 100644 --- a/lib/prmd/multi_loader/json.rb +++ b/lib/prmd/multi_loader/json.rb @@ -1,8 +1,8 @@ -require_relative 'loader' -require 'json' +require_relative "loader" +require "json" -module Prmd #:nodoc: - module MultiLoader #:nodoc: +module Prmd # :nodoc: + module MultiLoader # :nodoc: # JSON MultiLoader module Json extend Prmd::MultiLoader::Loader @@ -13,7 +13,7 @@ def self.load_data(data) end # register this loader for all .json files - extensions '.json' + extensions ".json" end end end diff --git a/lib/prmd/multi_loader/loader.rb b/lib/prmd/multi_loader/loader.rb index f729c9f..65e9295 100644 --- a/lib/prmd/multi_loader/loader.rb +++ b/lib/prmd/multi_loader/loader.rb @@ -1,5 +1,5 @@ -module Prmd #:nodoc: - module MultiLoader #:nodoc: +module Prmd # :nodoc: + module MultiLoader # :nodoc: # Exception raised when a extension loader cannot be found. class LoaderNotFound < StandardError end @@ -18,7 +18,7 @@ class << self def self.autoload_loader(name) # extension names are preceeded with a . # TODO. probably just remove the first . - loader_name = name.gsub('.', '') + loader_name = name.gsub(".", "") require "prmd/multi_loader/#{loader_name}" true rescue @@ -109,7 +109,7 @@ def load_stream(stream) # @eg # my_loader.load_file('my_file.ext') def load_file(filename) - File.open(filename, 'r') { |f| return load_stream(f) } + File.open(filename, "r") { |f| return load_stream(f) } end # Register the loader to the +args+ extensions diff --git a/lib/prmd/multi_loader/toml.rb b/lib/prmd/multi_loader/toml.rb index ac2a3bf..d60d2cb 100644 --- a/lib/prmd/multi_loader/toml.rb +++ b/lib/prmd/multi_loader/toml.rb @@ -1,8 +1,8 @@ -require_relative 'loader' -require 'toml' +require_relative "loader" +require "toml" -module Prmd #:nodoc: - module MultiLoader #:nodoc: +module Prmd # :nodoc: + module MultiLoader # :nodoc: # TOML MultiLoader module Toml extend Prmd::MultiLoader::Loader @@ -13,7 +13,7 @@ def self.load_data(data) end # register this loader for all .toml files - extensions '.toml' + extensions ".toml" end end end diff --git a/lib/prmd/multi_loader/yajl.rb b/lib/prmd/multi_loader/yajl.rb index eeb9f7c..1ca0dd5 100644 --- a/lib/prmd/multi_loader/yajl.rb +++ b/lib/prmd/multi_loader/yajl.rb @@ -1,8 +1,8 @@ -require_relative 'loader' -require 'yajl' +require_relative "loader" +require "yajl" -module Prmd #:nodoc: - module MultiLoader #:nodoc: +module Prmd # :nodoc: + module MultiLoader # :nodoc: # JSON MultiLoader using Yajl module Yajl extend Prmd::MultiLoader::Loader @@ -13,7 +13,7 @@ def self.load_data(data) end # register this loader for all .json files - extensions '.json' + extensions ".json" end end end diff --git a/lib/prmd/multi_loader/yaml.rb b/lib/prmd/multi_loader/yaml.rb index 6f7445e..7e31dda 100644 --- a/lib/prmd/multi_loader/yaml.rb +++ b/lib/prmd/multi_loader/yaml.rb @@ -1,8 +1,8 @@ -require_relative 'loader' -require 'yaml' +require_relative "loader" +require "yaml" -module Prmd #:nodoc: - module MultiLoader #:nodoc: +module Prmd # :nodoc: + module MultiLoader # :nodoc: # YAML MultiLoader module Yaml extend Prmd::MultiLoader::Loader @@ -13,7 +13,7 @@ def self.load_data(data) end # register this loader for all .yaml and .yml files - extensions '.yaml', '.yml' + extensions ".yaml", ".yml" end end end diff --git a/lib/prmd/multi_loader/yml.rb b/lib/prmd/multi_loader/yml.rb index a25730e..085f6e1 100644 --- a/lib/prmd/multi_loader/yml.rb +++ b/lib/prmd/multi_loader/yml.rb @@ -1,2 +1,2 @@ # alias for yaml -require_relative 'yaml' +require_relative "yaml" diff --git a/lib/prmd/rake_tasks/base.rb b/lib/prmd/rake_tasks/base.rb index 87f0726..3f9a0e2 100644 --- a/lib/prmd/rake_tasks/base.rb +++ b/lib/prmd/rake_tasks/base.rb @@ -1,5 +1,5 @@ -require 'rake' -require 'rake/tasklib' +require "rake" +require "rake/tasklib" # :nodoc: module Prmd @@ -37,15 +37,15 @@ def initialize(options = {}) # @api private def legacy_parameters(*args) if args.size == 0 - return {} + {} else arg, = *args case arg when String, Symbol warn "#{self.class}.new(name) has been deprecated, use .new(name: name) instead" - return { name: arg } + { name: arg } else - return arg + arg end end end diff --git a/lib/prmd/rake_tasks/combine.rb b/lib/prmd/rake_tasks/combine.rb index 8591366..b957357 100644 --- a/lib/prmd/rake_tasks/combine.rb +++ b/lib/prmd/rake_tasks/combine.rb @@ -1,5 +1,5 @@ -require 'prmd/commands/combine' -require 'prmd/rake_tasks/base' +require "prmd/commands/combine" +require "prmd/rake_tasks/base" # :nodoc: module Prmd @@ -30,11 +30,11 @@ class Combine < Base # @param [Hash] options # .option [String] output_file # .option [Array] paths - def initialize(*args, &block) - options = legacy_parameters(*args) + def initialize(*, &) + options = legacy_parameters(*) @paths = options.fetch(:paths) { [] } @output_file = options[:output_file] - super options, &block + super(options, &) end private @@ -51,13 +51,11 @@ def default_name # Defines the rake task # @return [void] def define - desc 'Combine schemas' unless Rake.application.last_description + desc "Combine schemas" unless Rake.application.last_description task(name) do result = Prmd.combine(paths, options) if output_file - File.open(output_file, 'w') do |file| - file.write(result) - end + File.write(output_file, result) end end end diff --git a/lib/prmd/rake_tasks/doc.rb b/lib/prmd/rake_tasks/doc.rb index 0257f9e..0d41ab2 100644 --- a/lib/prmd/rake_tasks/doc.rb +++ b/lib/prmd/rake_tasks/doc.rb @@ -1,11 +1,11 @@ -require 'prmd/commands/render' -require 'prmd/rake_tasks/base' -require 'prmd/load_schema_file' -require 'prmd/url_generator' -require 'prmd/template' -require 'prmd/schema' -require 'prmd/link' -require_relative '../hash_helpers' +require "prmd/commands/render" +require "prmd/rake_tasks/base" +require "prmd/load_schema_file" +require "prmd/url_generator" +require "prmd/template" +require "prmd/schema" +require "prmd/link" +require_relative "../hash_helpers" # :nodoc: module Prmd @@ -31,10 +31,10 @@ class Doc < Base # @overload initialize(options) # @param [Hash] options # .option [Array, Hash] files schema files - def initialize(*args, &block) - options = legacy_parameters(*args) + def initialize(*, &) + options = legacy_parameters(*) @files = options.fetch(:files) { [] } - super options, &block + super(options, &) if @options[:settings].is_a? String settings = Prmd.load_schema_file(@options[:settings]) @options.merge! HashHelpers.deep_symbolize_keys(settings) @@ -69,9 +69,7 @@ def render_file(filename) def render_to_file(infile, outfile) result = render_file(infile) if outfile - File.open(outfile, 'w') do |file| - file.write(result) - end + File.write(outfile, result) end end @@ -80,7 +78,7 @@ def render_to_file(infile, outfile) # Defines the rake task # @return [void] def define - desc 'Generate documentation' unless Rake.application.last_description + desc "Generate documentation" unless Rake.application.last_description task(name) do if files.is_a?(Hash) files.each do |infile, outfile| @@ -88,7 +86,7 @@ def define end else files.each do |infile| - render_to_file(infile, infile.ext('md')) + render_to_file(infile, infile.ext("md")) end end end diff --git a/lib/prmd/rake_tasks/verify.rb b/lib/prmd/rake_tasks/verify.rb index 64a43bc..10741fb 100644 --- a/lib/prmd/rake_tasks/verify.rb +++ b/lib/prmd/rake_tasks/verify.rb @@ -1,6 +1,6 @@ -require 'prmd/commands/verify' -require 'prmd/rake_tasks/base' -require 'prmd/load_schema_file' +require "prmd/commands/verify" +require "prmd/rake_tasks/base" +require "prmd/load_schema_file" # :nodoc: module Prmd @@ -24,10 +24,10 @@ class Verify < Base # @overload initialize(options) # @param [Hash] options # .option [Array] files schema files to verify - def initialize(*args, &block) - options = legacy_parameters(*args) + def initialize(*, &) + options = legacy_parameters(*) @files = options.fetch(:files) { [] } - super options, &block + super(options, &) end private @@ -48,7 +48,7 @@ def verify_file(filename) errors = Prmd.verify(data) unless errors.empty? errors.map! { |error| "#{filename}: #{error}" } if filename - errors.each { |error| $stderr.puts(error) } + errors.each { |error| warn(error) } end errors end @@ -58,7 +58,7 @@ def verify_file(filename) # Defines the rake task # @return [void] def define - desc 'Verify schemas' unless Rake.application.last_description + desc "Verify schemas" unless Rake.application.last_description task(name) do all_errors = [] files.each do |filename| diff --git a/lib/prmd/schema.rb b/lib/prmd/schema.rb index ab4ed34..432722e 100644 --- a/lib/prmd/schema.rb +++ b/lib/prmd/schema.rb @@ -1,5 +1,5 @@ -require 'json' -require 'yaml' +require "json" +require "yaml" # :nodoc: module Prmd @@ -7,16 +7,16 @@ module Prmd DefaultExamples = { "boolean" => true, "integer" => 42, - "number" => 42.0, - "string" => "example", + "number" => 42.0, + "string" => "example", - "date" => "2015-01-01", + "date" => "2015-01-01", "date-time" => "2015-01-01T12:00:00Z", - "email" => "username@example.com", - "hostname" => "example.com", - "ipv4" => "192.0.2.1", - "ipv6" => "2001:DB8::1", - "uuid" => "01234567-89ab-cdef-0123-456789abcdef", + "email" => "username@example.com", + "hostname" => "example.com", + "ipv4" => "192.0.2.1", + "ipv6" => "2001:DB8::1", + "uuid" => "01234567-89ab-cdef-0123-456789abcdef", } # Schema object @@ -38,14 +38,14 @@ def convert_type_to_array(datum, options) when Array datum.map { |element| convert_type_to_array(element, options) } when Hash - if datum.key?('type') && datum['type'].is_a?(String) && !options[:type_as_string] - datum['type'] = [*datum['type']] + if datum.key?("type") && datum["type"].is_a?(String) && !options[:type_as_string] + datum["type"] = [*datum["type"]] end datum.each_with_object({}) do |(k, v), hash| - if k != 'example' - hash[k] = convert_type_to_array(v, options) + hash[k] = if k != "example" + convert_type_to_array(v, options) else - hash[k] = v + v end end else @@ -81,9 +81,9 @@ def merge!(schema) # @param [Hash, String] reference def dereference(reference) if reference.is_a?(Hash) - if reference.key?('$ref') + if reference.key?("$ref") value = reference.dup - key = value.delete('$ref') + key = value.delete("$ref") else return [nil, reference] # no dereference needed end @@ -92,7 +92,7 @@ def dereference(reference) end begin datum = @data - key.gsub(/[^#]*#\//, '').split('/').each do |fragment| + key.gsub(/[^#]*#\//, "").split("/").each do |fragment| datum = datum[fragment] end # last dereference will have nil key, so compact it out @@ -100,41 +100,41 @@ def dereference(reference) dereferenced_key, dereferenced_value = dereference(datum) [ [key, dereferenced_key].compact.last, - [dereferenced_value, value].inject({}, &:merge) + [dereferenced_value, value].inject({}, &:merge), ] rescue => error - $stderr.puts("Failed to dereference `#{key}`") + warn("Failed to dereference `#{key}`") raise error end end # @param [Hash] value def schema_value_example(value) - if value.key?('example') - value['example'] - elsif value.key?('anyOf') - id_ref = value['anyOf'].find do |ref| - ref['$ref'] && ref['$ref'].split('/').last == 'id' + if value.key?("example") + value["example"] + elsif value.key?("anyOf") + id_ref = value["anyOf"].find do |ref| + ref["$ref"] && ref["$ref"].split("/").last == "id" end - ref = id_ref || value['anyOf'].first + ref = id_ref || value["anyOf"].first schema_example(ref) - elsif value.key?('allOf') - value['allOf'].map { |ref| schema_example(ref) }.reduce({}, &:merge) - elsif value.key?('properties') # nested properties + elsif value.key?("allOf") + value["allOf"].map { |ref| schema_example(ref) }.reduce({}, &:merge) + elsif value.key?("properties") # nested properties schema_example(value) - elsif value.key?('items') # array of objects - _, items = dereference(value['items']) - if value['items'].key?('example') + elsif value.key?("items") # array of objects + _, items = dereference(value["items"]) + if value["items"].key?("example") if items["example"].is_a?(Array) items["example"] else - [items['example']] + [items["example"]] end else [schema_example(items)] end - elsif value.key?('enum') - value['enum'][0] + elsif value.key?("enum") + value["enum"][0] elsif DefaultExamples.key?(value["format"]) DefaultExamples[value["format"]] elsif DefaultExamples.key?(value["type"][0]) @@ -146,16 +146,16 @@ def schema_value_example(value) def schema_example(schema) _, dff_schema = dereference(schema) - if dff_schema.key?('example') - dff_schema['example'] - elsif dff_schema.key?('properties') + if dff_schema.key?("example") + dff_schema["example"] + elsif dff_schema.key?("properties") example = {} - dff_schema['properties'].each do |key, value| + dff_schema["properties"].each do |key, value| _, value = dereference(value) example[key] = schema_value_example(value) end example - elsif dff_schema.key?('items') + elsif dff_schema.key?("items") schema_value_example(dff_schema) end end @@ -163,16 +163,14 @@ def schema_example(schema) # @param [String] schemata_id def schemata_example(schemata_id) _, schema = dereference("#/definitions/#{schemata_id}") - @schemata_examples[schemata_id] ||= begin - schema_example(schema) - end + @schemata_examples[schemata_id] ||= schema_example(schema) end # Retrieve this schema's href # # @return [String, nil] def href - (@data['links'] && @data['links'].find { |link| link['rel'] == 'self' } || {})['href'] + (@data["links"] && @data["links"].find { |link| link["rel"] == "self" } || {})["href"] end # Convert Schema to JSON @@ -181,8 +179,7 @@ def href def to_json new_json = JSON.pretty_generate(@data) # nuke empty lines - new_json = new_json.split("\n").reject(&:empty?).join("\n") + "\n" - new_json + new_json.split("\n").reject(&:empty?).join("\n") + "\n" end # Convert Schema to YAML diff --git a/lib/prmd/template.rb b/lib/prmd/template.rb index bc19022..eab43de 100644 --- a/lib/prmd/template.rb +++ b/lib/prmd/template.rb @@ -1,5 +1,5 @@ -require 'erubis' -require 'json' +require "erubis" +require "json" # :nodoc: module Prmd @@ -11,13 +11,13 @@ class Template # @return [String] location of the prmd templates directory def self.template_dirname - File.join(File.dirname(__FILE__), 'templates') + File.join(File.dirname(__FILE__), "templates") end # @param [String] args # @return [String] path in prmd's template directory - def self.template_path(*args) - File.expand_path(File.join(*args), template_dirname) + def self.template_path(*) + File.expand_path(File.join(*), template_dirname) end # Clear internal template cache @@ -60,8 +60,8 @@ def self.load_template(path, base) # @param [String] path # @param [String] base # @return [String] result from template render - def self.render(path, base, *args, &block) - load_template(path, base).result(*args, &block) + def self.render(path, base, *, &) + load_template(path, base).result(*, &) end # Load a JSON file from prmd's templates directory. diff --git a/lib/prmd/url_generator.rb b/lib/prmd/url_generator.rb index 27b0e69..2f84e72 100644 --- a/lib/prmd/url_generator.rb +++ b/lib/prmd/url_generator.rb @@ -1,5 +1,5 @@ -require_relative 'url_generators/generators/default' -require_relative 'url_generators/generators/json' +require_relative "url_generators/generators/default" +require_relative "url_generators/generators/json" # :nodoc: module Prmd @@ -15,10 +15,10 @@ def initialize(params) # @return [Array] def url_params - if @options[:doc][:url_style].downcase == 'json' - klass = Generators::JSON + klass = if @options[:doc][:url_style].downcase == "json" + Generators::JSON else - klass = Generators::Default + Generators::Default end klass.generate(schema: @schema, link: @link) diff --git a/lib/prmd/url_generators/generators/default.rb b/lib/prmd/url_generators/generators/default.rb index 4f6200d..97e5e46 100644 --- a/lib/prmd/url_generators/generators/default.rb +++ b/lib/prmd/url_generators/generators/default.rb @@ -1,4 +1,4 @@ -require 'cgi' +require "cgi" # :nodoc: module Prmd @@ -13,7 +13,7 @@ class Default # @param [Hash] params def self.generate(params) data = {} - data.merge!(params[:schema].schema_example(params[:link]['schema'])) + data.merge!(params[:schema].schema_example(params[:link]["schema"])) generate_params(data) end @@ -27,7 +27,7 @@ def self.param_name(key, prefix, array = false) key end - result += '[]' if array + result += "[]" if array result end @@ -36,7 +36,7 @@ def self.param_name(key, prefix, array = false) # @return [String] def self.generate_params(obj, prefix = nil) result = [] - obj.each do |key,value| + obj.each do |key, value| if value.is_a?(Hash) newprefix = if prefix "#{prefix}[#{key}]" @@ -46,11 +46,11 @@ def self.generate_params(obj, prefix = nil) result << generate_params(value, newprefix) elsif value.is_a?(Array) value.each do |val| - result << [param_name(key, prefix, true), CGI.escape(val.to_s)].join('=') + result << [param_name(key, prefix, true), CGI.escape(val.to_s)].join("=") end else next unless value # ignores parameters with empty examples - result << [param_name(key, prefix), CGI.escape(value.to_s)].join('=') + result << [param_name(key, prefix), CGI.escape(value.to_s)].join("=") end end result.flatten diff --git a/lib/prmd/url_generators/generators/json.rb b/lib/prmd/url_generators/generators/json.rb index e8f596e..360568e 100644 --- a/lib/prmd/url_generators/generators/json.rb +++ b/lib/prmd/url_generators/generators/json.rb @@ -1,4 +1,4 @@ -require 'cgi' +require "cgi" # :nodoc: module Prmd @@ -13,12 +13,12 @@ class JSON # @param [Hash] params def self.generate(params) data = {} - data.merge!(params[:schema].schema_example(params[:link]['schema'])) + data.merge!(params[:schema].schema_example(params[:link]["schema"])) result = [] - data.sort_by {|k,_| k.to_s }.each do |key, values| + data.sort_by { |k, _| k.to_s }.each do |key, values| [values].flatten.each do |value| - result << [key.to_s, CGI.escape(value.to_s)].join('=') + result << [key.to_s, CGI.escape(value.to_s)].join("=") end end diff --git a/lib/prmd/version.rb b/lib/prmd/version.rb index 21d21e5..25a52a8 100644 --- a/lib/prmd/version.rb +++ b/lib/prmd/version.rb @@ -5,7 +5,7 @@ module Version MAJOR, MINOR, TEENY, PATCH = 0, 14, 0, nil # version string # @return [String] - STRING = [MAJOR, MINOR, TEENY, PATCH].compact.join('.').freeze + STRING = [MAJOR, MINOR, TEENY, PATCH].compact.join(".").freeze end # @return [String] VERSION = Version::STRING diff --git a/prmd.gemspec b/prmd.gemspec index 3eefc3e..efe292f 100644 --- a/prmd.gemspec +++ b/prmd.gemspec @@ -1,30 +1,28 @@ -# coding: utf-8 -lib = File.expand_path('../lib', __FILE__) +lib = File.expand_path("../lib", __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'prmd/version' +require "prmd/version" Gem::Specification.new do |spec| - spec.name = 'prmd' - spec.version = Prmd::VERSION - spec.authors = ['geemus'] - spec.email = ['geemus@gmail.com'] - spec.description = 'scaffold, verify and generate docs from JSON Schema' - spec.summary = 'JSON Schema tooling' - spec.homepage = 'https://github.com/heroku/prmd' - spec.license = 'MIT' + spec.name = "prmd" + spec.version = Prmd::VERSION + spec.authors = ["geemus"] + spec.email = ["geemus@gmail.com"] + spec.description = "scaffold, verify and generate docs from JSON Schema" + spec.summary = "JSON Schema tooling" + spec.homepage = "https://github.com/heroku/prmd" + spec.license = "MIT" - spec.files = `git ls-files`.split($/) - spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) } - spec.test_files = spec.files.grep(/^(test|spec|features)\//) - spec.require_paths = ['lib'] + spec.files = `git ls-files`.split($/) + spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) } + spec.require_paths = ["lib"] spec.required_ruby_version = ">= 3.2" - spec.add_dependency 'erubis', '~> 2.7' - spec.add_dependency 'json_schema', '~> 0.3', '>= 0.3.1' + spec.add_dependency "erubis", "~> 2.7" + spec.add_dependency "json_schema", "~> 0.3", ">= 0.3.1" - spec.add_development_dependency 'bundler', '~> 2.0' - spec.add_development_dependency 'rake', '>= 12.3.3' - spec.add_development_dependency 'minitest', '~> 5.25' - spec.add_development_dependency 'rubocop', '~> 1.71' + spec.add_development_dependency "bundler", "~> 2.0" + spec.add_development_dependency "rake", ">= 12.3.3" + spec.add_development_dependency "minitest", "~> 5.25" + spec.add_development_dependency "rubocop", "~> 1.71" end diff --git a/test/cli/combine_test.rb b/test/cli/combine_test.rb index 9cdefd9..dc36d50 100644 --- a/test/cli/combine_test.rb +++ b/test/cli/combine_test.rb @@ -1,5 +1,5 @@ -require_relative '../helpers' -require 'prmd/cli/combine' +require_relative "../helpers" +require "prmd/cli/combine" class PrmdCliCombineTest < Minitest::Test include CliBaseTestHelpers @@ -9,15 +9,15 @@ def command_module end def argv_for_test_run - ['-m', 'schema/meta.json', - 'schema/schemata', - '-o', 'schema/api.json'] + ["-m", "schema/meta.json", + "schema/schemata", + "-o", "schema/api.json",] end def validate_parse_options(options) - assert_equal 'schema/meta.json', options[:meta] - assert_equal 'schema/api.json', options[:output_file] - assert_equal ['schema/schemata'], options[:argv] + assert_equal "schema/meta.json", options[:meta] + assert_equal "schema/api.json", options[:output_file] + assert_equal ["schema/schemata"], options[:argv] super end end diff --git a/test/cli/doc_test.rb b/test/cli/doc_test.rb index d250ad0..9db692c 100644 --- a/test/cli/doc_test.rb +++ b/test/cli/doc_test.rb @@ -1,5 +1,5 @@ -require_relative '../helpers' -require 'prmd/cli/doc' +require_relative "../helpers" +require "prmd/cli/doc" class PrmdCliDocTest < Minitest::Test include CliBaseTestHelpers @@ -9,17 +9,17 @@ def command_module end def argv_for_test_run - ['-s', input_schemas_path('doc-settings.json'), - '-p', 'overview.txt', - 'schema/api.json', - '-o', 'schema/verified-api.json'] + ["-s", input_schemas_path("doc-settings.json"), + "-p", "overview.txt", + "schema/api.json", + "-o", "schema/verified-api.json",] end def validate_parse_options(options) - assert_equal 'application/bread', options[:content_type] - assert_equal ['overview.txt'], options[:prepend] - assert_equal 'schema/verified-api.json', options[:output_file] - assert_equal ['schema/api.json'], options[:argv] + assert_equal "application/bread", options[:content_type] + assert_equal ["overview.txt"], options[:prepend] + assert_equal "schema/verified-api.json", options[:output_file] + assert_equal ["schema/api.json"], options[:argv] super end end diff --git a/test/cli/generate_test.rb b/test/cli/generate_test.rb index e40c3bf..5db57b6 100644 --- a/test/cli/generate_test.rb +++ b/test/cli/generate_test.rb @@ -1,5 +1,5 @@ -require_relative '../helpers' -require 'prmd/cli/generate' +require_relative "../helpers" +require "prmd/cli/generate" class PrmdCliGenerateTest < Minitest::Test include CliBaseTestHelpers @@ -9,15 +9,15 @@ def command_module end def argv_for_test_run - ['-y', - 'bread', - '-o', 'schema/bread.yml'] + ["-y", + "bread", + "-o", "schema/bread.yml",] end def validate_parse_options(options) assert_equal true, options[:yaml] - assert_equal ['bread'], options[:argv] - assert_equal 'schema/bread.yml', options[:output_file] + assert_equal ["bread"], options[:argv] + assert_equal "schema/bread.yml", options[:output_file] super end end diff --git a/test/cli/render_test.rb b/test/cli/render_test.rb index 52ddab9..57cb42e 100644 --- a/test/cli/render_test.rb +++ b/test/cli/render_test.rb @@ -1,5 +1,5 @@ -require_relative '../helpers' -require 'prmd/cli/render' +require_relative "../helpers" +require "prmd/cli/render" class PrmdCliRenderTest < Minitest::Test include CliBaseTestHelpers @@ -9,17 +9,17 @@ def command_module end def argv_for_test_run - ['-p', 'overview.txt,somethin.txt', - '-t', 'templates', - '-o', 'schema/bread.md', - 'schema/bread.json'] + ["-p", "overview.txt,somethin.txt", + "-t", "templates", + "-o", "schema/bread.md", + "schema/bread.json",] end def validate_parse_options(options) - assert_equal ['overview.txt', 'somethin.txt'], options[:prepend] - assert_equal 'templates', options[:template] - assert_equal 'schema/bread.md', options[:output_file] - assert_equal ['schema/bread.json'], options[:argv] + assert_equal ["overview.txt", "somethin.txt"], options[:prepend] + assert_equal "templates", options[:template] + assert_equal "schema/bread.md", options[:output_file] + assert_equal ["schema/bread.json"], options[:argv] super end end diff --git a/test/cli/verify_test.rb b/test/cli/verify_test.rb index eb3fa25..cab6a1a 100644 --- a/test/cli/verify_test.rb +++ b/test/cli/verify_test.rb @@ -1,5 +1,5 @@ -require_relative '../helpers' -require 'prmd/cli/verify' +require_relative "../helpers" +require "prmd/cli/verify" class PrmdCliVerifyTest < Minitest::Test include CliBaseTestHelpers @@ -9,13 +9,13 @@ def command_module end def argv_for_test_run - ['-o', 'schema/buttered-bread.json', - 'schema/bread.json'] + ["-o", "schema/buttered-bread.json", + "schema/bread.json",] end def validate_parse_options(options) - assert_equal 'schema/buttered-bread.json', options[:output_file] - assert_equal ['schema/bread.json'], options[:argv] + assert_equal "schema/buttered-bread.json", options[:output_file] + assert_equal ["schema/bread.json"], options[:argv] super end end diff --git a/test/commands/combine_test.rb b/test/commands/combine_test.rb index 3e71e60..50fd5c5 100644 --- a/test/commands/combine_test.rb +++ b/test/commands/combine_test.rb @@ -1,30 +1,29 @@ -require_relative '../helpers' +require_relative "../helpers" -require 'json_pointer' +require "json_pointer" class InteragentHyperSchemaCombineTest < Minitest::Test - # # resource link readable href # def test_resource_link_href_escaping - pointer('#/definitions/app/links/0').merge!({ - 'href' => '/apps/{(#/definitions/app)}' + pointer("#/definitions/app/links/0").merge!({ + "href" => "/apps/{(#/definitions/app)}", }) assert_equal "/apps/{(%23%2Fdefinitions%2Fapp)}", escaped_href end def test_resource_link_href_no_double_escaping - pointer('#/definitions/app/links/0').merge!({ - 'href' => '/apps/{(%23%2Fdefinitions%2Fapp)}' + pointer("#/definitions/app/links/0").merge!({ + "href" => "/apps/{(%23%2Fdefinitions%2Fapp)}", }) assert_equal "/apps/{(%23%2Fdefinitions%2Fapp)}", escaped_href end def test_resource_link_href_no_side_effects - pointer('#/definitions/app/links/0').merge!({ - 'href' => '/apps/foo#bar' + pointer("#/definitions/app/links/0").merge!({ + "href" => "/apps/foo#bar", }) assert_equal "/apps/foo#bar", escaped_href end @@ -33,32 +32,31 @@ def test_resource_link_href_no_side_effects def data @data ||= { - '$schema' => 'http://interagent.github.io/interagent-hyper-schema', - 'description' => 'My simple example API.', - 'id' => 'http://example.com/schema', - 'title' => 'Example API', - 'definitions' => { - 'app' => { - 'description' => 'An app in our PaaS ecosystem.', - 'title' => 'App', - 'type' => 'object', - 'definitions' => {}, - 'links' => [ + "$schema" => "http://interagent.github.io/interagent-hyper-schema", + "description" => "My simple example API.", + "id" => "http://example.com/schema", + "title" => "Example API", + "definitions" => { + "app" => { + "description" => "An app in our PaaS ecosystem.", + "title" => "App", + "type" => "object", + "definitions" => {}, + "links" => [ { - 'description' => 'Create a new app.', - 'href' => '/apps', - 'method' => 'POST', - 'rel' => 'create', - 'title' => 'Create App' - } + "description" => "Create a new app.", + "href" => "/apps", + "method" => "POST", + "rel" => "create", + "title" => "Create App", + }, ], - 'properties' => { - } - } + "properties" => {}, + }, }, - 'links' => [], - 'properties' => {}, - 'type' => 'object' + "links" => [], + "properties" => {}, + "type" => "object", } end diff --git a/test/commands/init_test.rb b/test/commands/init_test.rb index 09294af..41b1869 100644 --- a/test/commands/init_test.rb +++ b/test/commands/init_test.rb @@ -1,7 +1,7 @@ -require_relative '../helpers' +require_relative "../helpers" class PrmdInitTest < Minitest::Test def test_init - Prmd.init('Cake') + Prmd.init("Cake") end end diff --git a/test/commands/render_test.rb b/test/commands/render_test.rb index bda3bf2..b52cf08 100644 --- a/test/commands/render_test.rb +++ b/test/commands/render_test.rb @@ -1,6 +1,6 @@ -require_relative '../helpers' +require_relative "../helpers" -require 'json_pointer' +require "json_pointer" class InteragentRenderTest < Minitest::Test def test_render_for_valid_schema @@ -10,21 +10,20 @@ def test_render_for_valid_schema end def test_render_for_schema_with_property_defined_with_anyOf - pointer('#/definitions/app').merge!({ - 'properties' => { - 'version' => { - 'anyOf' => [ - { 'type' => 'string', 'example' => 'v10.9.rc1', 'minLength' => 1 }, - { 'type' => 'number', 'minimum' => 0 } - ] - } - } + pointer("#/definitions/app").merge!({ + "properties" => { + "version" => { + "anyOf" => [ + { "type" => "string", "example" => "v10.9.rc1", "minLength" => 1 }, + { "type" => "number", "minimum" => 0 }, + ], + }, + }, }) markdown = render assert_match(/version.*v10\.9\.rc1/, markdown) end - def test_render_for_schema_with_property_defined_with_oneOf markdown = render @@ -34,10 +33,10 @@ def test_render_for_schema_with_property_defined_with_oneOf def test_render_for_toc schema = Prmd::Schema.new(data) - template = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'prmd', 'templates')) + template = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "lib", "prmd", "templates")) markdown = Prmd.render(schema, template: template, doc: { toc: true }) - assert_match /^## The table of contents/, markdown + assert_match(/^## The table of contents/, markdown) assert_match 'POST /apps', markdown assert_match '', markdown @@ -45,13 +44,13 @@ def test_render_for_toc def test_render_for_example_as_an_array # matches -d '[{...}]' taking into account line breaks and spacing - expression = /-d '\[[\s\n]+\{[\n\s]+\"name\": \"EXAMPLE\",[\n\s]+\"value\": \"example\"[\s\n]+\}[\n\s]+\]/ + expression = /-d '\[[\s\n]+\{[\n\s]+"name": "EXAMPLE",[\n\s]+"value": "example"[\s\n]+\}[\n\s]+\]/ markdown = render assert_match expression, markdown end def test_render_for_regex_patterns_with_pipes - expression = /
\^[a-z\]\(\?:[a|b\]\)\*[a-z]*\$/
+    expression = /
\^[a-z\]\(\?:[a|b\]\)*[a-z]*\$/
     markdown = render
     assert_match expression, markdown
   end
@@ -60,155 +59,154 @@ def test_render_for_regex_patterns_with_pipes
 
   def data
     @data ||= {
-      '$schema'     => 'http://interagent.github.io/interagent-hyper-schema',
-      'description' => 'My simple example API.',
-      'id'          => 'http://example.com/schema',
-      'title'       => 'Example API',
-      'definitions' => {
-        'app' => {
-          'description' => 'An app in our PaaS ecosystem.',
-          'title' => 'App',
-          'type' => 'object',
-          'definitions' => {
-            'identity' => {
-              'anyOf' => [
+      "$schema" => "http://interagent.github.io/interagent-hyper-schema",
+      "description" => "My simple example API.",
+      "id" => "http://example.com/schema",
+      "title" => "Example API",
+      "definitions" => {
+        "app" => {
+          "description" => "An app in our PaaS ecosystem.",
+          "title" => "App",
+          "type" => "object",
+          "definitions" => {
+            "identity" => {
+              "anyOf" => [
                 {
-                  '$ref' => '#/definitions/app/definitions/name'
-                }
-              ]
-            },
-            'name' => {
-              'description' => 'The app\'s name.',
-              'type'        => 'string'
-            }
+                  "$ref" => "#/definitions/app/definitions/name",
+                },
+              ],
+            },
+            "name" => {
+              "description" => "The app's name.",
+              "type" => "string",
+            },
           },
-          'links' => [
+          "links" => [
             {
-              'description' => 'Create a new app.',
-              'href' => '/apps',
-              'method' => 'POST',
-              'rel' => 'create',
-              'title' => 'Create App'
-            }
+              "description" => "Create a new app.",
+              "href" => "/apps",
+              "method" => "POST",
+              "rel" => "create",
+              "title" => "Create App",
+            },
           ],
-          'properties' => {
-          }
+          "properties" => {},
         },
-        'config-var' => {
-          'description' => 'A configuration variable for an app.',
-          'title' => 'Config-var',
-          'type' => 'object',
-          'definitions' => {
-            'name' => {
-              'description' => 'The config-var\'s name.',
-              'type'        => 'string',
-              'example'     => 'EXAMPLE'
-            },
-            'value' => {
-              'description' => 'The config-var\'s value.',
-              'type'        => 'string',
-              'example'     => 'example'
-            },
-            'option-type1' => {
-              'type' => 'string',
-              'example' => 'OPTION1',
-              'enum' => 'OPTION1'
-            },
-            'option-type2' => {
-              'type' => 'string',
-              'example' => 'OPTION2',
-              'enum' => 'OPTION2'
-            },
-            'patterned-string' => {
-              'description' => 'A string with a regex pattern applied to it.',
-              'type' => 'string',
-              'example' => 'second',
-              'pattern' => '^[a-z](?:[a|b])*[a-z]*$'
-            },
-            'option1' => {
-              'properties' => {
-                'type' => {
-                    '$ref' => '#/definitions/config-var/definitions/option-type1'
-                }
-              }
-            },
-            'option2' => {
-              'properties' => {
-                'type' => {
-                    '$ref' => '#/definitions/config-var/definitions/option-type2'
-                }
-              }
-            },
-            'options' => {
-              'items' => {
-                'example'=> 'CHOICE1',
-                'oneOf' => [
+        "config-var" => {
+          "description" => "A configuration variable for an app.",
+          "title" => "Config-var",
+          "type" => "object",
+          "definitions" => {
+            "name" => {
+              "description" => "The config-var's name.",
+              "type" => "string",
+              "example" => "EXAMPLE",
+            },
+            "value" => {
+              "description" => "The config-var's value.",
+              "type" => "string",
+              "example" => "example",
+            },
+            "option-type1" => {
+              "type" => "string",
+              "example" => "OPTION1",
+              "enum" => "OPTION1",
+            },
+            "option-type2" => {
+              "type" => "string",
+              "example" => "OPTION2",
+              "enum" => "OPTION2",
+            },
+            "patterned-string" => {
+              "description" => "A string with a regex pattern applied to it.",
+              "type" => "string",
+              "example" => "second",
+              "pattern" => "^[a-z](?:[a|b])*[a-z]*$",
+            },
+            "option1" => {
+              "properties" => {
+                "type" => {
+                  "$ref" => "#/definitions/config-var/definitions/option-type1",
+                },
+              },
+            },
+            "option2" => {
+              "properties" => {
+                "type" => {
+                  "$ref" => "#/definitions/config-var/definitions/option-type2",
+                },
+              },
+            },
+            "options" => {
+              "items" => {
+                "example" => "CHOICE1",
+                "oneOf" => [
                   {
-                    '$ref' => '#/definitions/config-var/definitions/option1'
+                    "$ref" => "#/definitions/config-var/definitions/option1",
                   },
                   {
-                   '$ref' => '#/definitions/config-var/definitions/option2'
-                  }
-                ]
-              }
-            }
+                    "$ref" => "#/definitions/config-var/definitions/option2",
+                  },
+                ],
+              },
+            },
           },
-          'links' => [
+          "links" => [
             {
-              'description' => 'Create many config-vars.',
-              'href' => '/config-vars',
-              'method' => 'PATCH',
-              'rel' => 'instances',
-              'title' => 'Create Config-var',
-              'schema' => {
-                'type' => [
-                  'array'
+              "description" => "Create many config-vars.",
+              "href" => "/config-vars",
+              "method" => "PATCH",
+              "rel" => "instances",
+              "title" => "Create Config-var",
+              "schema" => {
+                "type" => [
+                  "array",
                 ],
-                'items' => {
-                  'name' => {
-                    '$ref' => '#/definitions/config-var/definitions/name'
+                "items" => {
+                  "name" => {
+                    "$ref" => "#/definitions/config-var/definitions/name",
                   },
-                  'value' => {
-                    '$ref' => '#/definitions/config-var/definitions/value'
+                  "value" => {
+                    "$ref" => "#/definitions/config-var/definitions/value",
                   },
-                  'example' => [
-                    { 'name' => 'EXAMPLE', 'value' => 'example' }
-                  ]
-                }
-              }
-            }
+                  "example" => [
+                    { "name" => "EXAMPLE", "value" => "example" },
+                  ],
+                },
+              },
+            },
           ],
-          'properties' => {
-            'name' => {
-              '$ref' => '#/definitions/config-var/definitions/name'
+          "properties" => {
+            "name" => {
+              "$ref" => "#/definitions/config-var/definitions/name",
             },
-            'value' => {
-              '$ref' => '#/definitions/config-var/definitions/value'
+            "value" => {
+              "$ref" => "#/definitions/config-var/definitions/value",
             },
-            'options' => {
-              '$ref' => '#/definitions/config-var/definitions/options'
+            "options" => {
+              "$ref" => "#/definitions/config-var/definitions/options",
             },
-            'patterned-string' => {
-              '$ref' => '#/definitions/config-var/definitions/patterned-string'
+            "patterned-string" => {
+              "$ref" => "#/definitions/config-var/definitions/patterned-string",
             },
-          }
-        }
+          },
+        },
       },
-      'links' => [
+      "links" => [
         {
-          'href' => 'https://example.com',
-          'rel' => 'self'
-        }
+          "href" => "https://example.com",
+          "rel" => "self",
+        },
       ],
-      'properties' => {
-        'app' => {
-          '$ref' => '#/definitions/app'
+      "properties" => {
+        "app" => {
+          "$ref" => "#/definitions/app",
+        },
+        "config-var" => {
+          "$ref" => "#/definitions/config-var",
         },
-        'config-var' => {
-          '$ref' => '#/definitions/config-var'
-        }
       },
-      'type' => 'object'
+      "type" => "object",
     }
   end
 
@@ -219,7 +217,7 @@ def pointer(path)
   def render
     schema = Prmd::Schema.new(data)
 
-    template = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'prmd', 'templates'))
+    template = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "lib", "prmd", "templates"))
 
     Prmd.render(schema, template: template)
   end
diff --git a/test/commands/verify_test.rb b/test/commands/verify_test.rb
index a2edb03..9d3b659 100644
--- a/test/commands/verify_test.rb
+++ b/test/commands/verify_test.rb
@@ -1,6 +1,6 @@
-require_relative '../helpers'
+require_relative "../helpers"
 
-require 'json_pointer'
+require "json_pointer"
 
 class InteragentHyperSchemaVerifyTest < Minitest::Test
   def test_verifies
@@ -12,20 +12,20 @@ def test_verifies
   #
 
   def test_api_required
-    data.delete('title')
+    data.delete("title")
     errors = verify
     assert_equal 1, errors.count
-    assert_match /^#: /, errors[0]
-    assert_match /"title" wasn't supplied\./, errors[0]
+    assert_match(/^#: /, errors[0])
+    assert_match(/"title" wasn't supplied\./, errors[0])
   end
 
   def test_api_property_format
-    pointer('#/properties').merge!({
-      'app' => {}
+    pointer("#/properties").merge!({
+      "app" => {},
     })
     errors = verify
     assert_match %r{^#/properties/app: }, errors[0]
-    assert_match /"\$ref" wasn't supplied\./, errors[0]
+    assert_match(/"\$ref" wasn't supplied\./, errors[0])
   end
 
   #
@@ -33,50 +33,50 @@ def test_api_property_format
   #
 
   def test_resource_required
-    pointer('#/definitions/app').delete('title')
+    pointer("#/definitions/app").delete("title")
     errors = verify
     assert_equal 1, errors.count
     assert_match %r{^#/definitions/app: }, errors[0]
-    assert_match /"title" wasn't supplied\./, errors[0]
+    assert_match(/"title" wasn't supplied\./, errors[0])
   end
 
   def test_resource_identity_format
-    pointer('#/definitions/app/definitions/identity').merge!({
-      'type' => 'string'
+    pointer("#/definitions/app/definitions/identity").merge!({
+      "type" => "string",
     })
     errors = verify
     assert_equal 1, errors.count
     assert_match %r{^#/definitions/app/definitions/identity: }, errors[0]
-    assert_match /No subschema in "anyOf" matched\./, errors[0]
+    assert_match(/No subschema in "anyOf" matched\./, errors[0])
   end
 
   # an empty schema can be specified to bypass the identity check
   def test_resource_identity_format_empty
-    pointer('#/definitions/app/definitions').merge!({
-      'identity' => {}
+    pointer("#/definitions/app/definitions").merge!({
+      "identity" => {},
     })
     assert_equal [], verify
   end
 
   # "my-property" does match fit our regex of lowercase letters and underscores only
   def test_resource_property_format
-    pointer('#/definitions/app/properties').merge!({
-      'my-property' => {}
+    pointer("#/definitions/app/properties").merge!({
+      "my-property" => {},
     })
     errors = verify
     assert_equal 1, errors.count
     assert_match %r{^#/definitions/app/properties: }, errors[0]
-    assert_match /"my-property" is not a permitted key\./, errors[0]
+    assert_match(/"my-property" is not a permitted key\./, errors[0])
   end
 
   def test_resource_strict_properties
-    pointer('#/definitions/app').merge!({
-      'strictProperties' => false
+    pointer("#/definitions/app").merge!({
+      "strictProperties" => false,
     })
     errors = verify
     assert_equal 1, errors.count
     assert_match %r{^#/definitions/app/strictProperties: }, errors[0]
-    assert_match /false is not a member of \[true\]/, errors[0]
+    assert_match(/false is not a member of \[true\]/, errors[0])
   end
 
   #
@@ -84,21 +84,21 @@ def test_resource_strict_properties
   #
 
   def test_resource_definition_no_links
-    pointer('#/definitions/app/definitions/name').merge!({
-      'links' => []
+    pointer("#/definitions/app/definitions/name").merge!({
+      "links" => [],
     })
     errors = verify
     assert_equal 1, errors.count
     assert_match %r{^#/definitions/app/definitions/name: }, errors[0]
-    assert_match /Matched "not" subschema/, errors[0]
+    assert_match(/Matched "not" subschema/, errors[0])
   end
 
   def test_resource_definition_required
-    pointer('#/definitions/app/definitions/name').delete('description')
+    pointer("#/definitions/app/definitions/name").delete("description")
     errors = verify
     assert_equal 1, errors.count
     assert_match %r{^#/definitions/app/definitions/name: }, errors[0]
-    assert_match /"description" wasn't supplied\./, errors[0]
+    assert_match(/"description" wasn't supplied\./, errors[0])
   end
 
   #
@@ -106,74 +106,73 @@ def test_resource_definition_required
   #
 
   def test_resource_link_href_format
-    pointer('#/definitions/app/links/0').merge!({
-      'href' => '/my~apps'
+    pointer("#/definitions/app/links/0").merge!({
+      "href" => "/my~apps",
     })
     errors = verify
     assert_equal 1, errors.count
     assert_match %r{^#/definitions/app/links/0/href: }, errors[0]
-    assert_match /\/my~apps does not match /, errors[0]
+    assert_match(/\/my~apps does not match /, errors[0])
   end
 
   def test_resource_link_required
-    pointer('#/definitions/app/links/0').delete('method')
+    pointer("#/definitions/app/links/0").delete("method")
     errors = verify
     assert_equal 1, errors.count
     assert_match %r{^#/definitions/app/links/0: }, errors[0]
-    assert_match /"method" wasn't supplied\./, errors[0]
+    assert_match(/"method" wasn't supplied\./, errors[0])
   end
 
   private
 
   def data
     @data ||= {
-      '$schema'     => 'http://interagent.github.io/interagent-hyper-schema',
-      'description' => 'My simple example API.',
-      'id'          => 'http://example.com/schema',
-      'title'       => 'Example API',
-      'definitions' => {
-        'app' => {
-          'description' => 'An app in our PaaS ecosystem.',
-          'title' => 'App',
-          'type' => 'object',
-          'definitions' => {
-            'identity' => {
-              'anyOf' => [
+      "$schema" => "http://interagent.github.io/interagent-hyper-schema",
+      "description" => "My simple example API.",
+      "id" => "http://example.com/schema",
+      "title" => "Example API",
+      "definitions" => {
+        "app" => {
+          "description" => "An app in our PaaS ecosystem.",
+          "title" => "App",
+          "type" => "object",
+          "definitions" => {
+            "identity" => {
+              "anyOf" => [
                 {
-                  '$ref' => '#/definitions/app/definitions/name'
-                }
-              ]
+                  "$ref" => "#/definitions/app/definitions/name",
+                },
+              ],
+            },
+            "name" => {
+              "description" => "The app's name.",
+              "type" => "string",
             },
-            'name' => {
-              'description' => 'The app\'s name.',
-              'type'        => 'string'
-            }
           },
-          'links' => [
+          "links" => [
             {
-              'description' => 'Create a new app.',
-              'href' => '/apps',
-              'method' => 'POST',
-              'rel' => 'create',
-              'title' => 'Create App'
-            }
+              "description" => "Create a new app.",
+              "href" => "/apps",
+              "method" => "POST",
+              "rel" => "create",
+              "title" => "Create App",
+            },
           ],
-          'properties' => {
-          }
-        }
+          "properties" => {},
+        },
       },
-      'links' => [
+      "links" => [
         {
-          'href' => 'https://example.com',
-          'rel' => 'self'
-        }
+          "href" => "https://example.com",
+          "rel" => "self",
+        },
       ],
-      'properties' => {
-        'app' => {
-          '$ref' => '#/definitions/app'
-        }
+      "properties" => {
+        "app" => {
+          "$ref" => "#/definitions/app",
+        },
       },
-      'type' => 'object'
+      "type" => "object",
     }
   end
 
diff --git a/test/core/reference_localizer_test.rb b/test/core/reference_localizer_test.rb
index 6ec8eb9..8a10af3 100644
--- a/test/core/reference_localizer_test.rb
+++ b/test/core/reference_localizer_test.rb
@@ -1,4 +1,4 @@
-require_relative '../helpers'
+require_relative "../helpers"
 
 module Prmd
   class ReferenceLocalizerTest < Minitest::Test
@@ -32,7 +32,7 @@ def test_simple_ref
 
       new_object = ReferenceLocalizer.localize(object)
       assert_equal "#/definitions/attributes/definitions/name",
-                   new_object["properties"]["name"]["$ref"]
+        new_object["properties"]["name"]["$ref"]
     end
 
     def test_simple_href
@@ -56,10 +56,10 @@ def test_aliases
       new_object = ReferenceLocalizer.localize(object)
 
       assert_equal "#/definitions/attributes/definitions/name",
-                   new_object["properties"]["name"]["$ref"]
+        new_object["properties"]["name"]["$ref"]
 
       assert_equal "#/definitions/attributes/definitions/name",
-                   new_object["properties"]["translated_name"]["$ref"]
+        new_object["properties"]["translated_name"]["$ref"]
     end
   end
 end
diff --git a/test/helpers.rb b/test/helpers.rb
index 4f5a60c..65fa858 100644
--- a/test/helpers.rb
+++ b/test/helpers.rb
@@ -1,7 +1,7 @@
-require 'minitest'
-require 'minitest/autorun'
-require 'prmd'
-require 'prmd/cli/base'
+require "minitest"
+require "minitest/autorun"
+require "prmd"
+require "prmd/cli/base"
 
 module Prmd
   module CLI
@@ -20,11 +20,10 @@ def argv_for_test_run
   end
 
   def options_for_test_run
-    { }
+    {}
   end
 
   def validate_parse_options(options)
-    #
   end
 
   def validate_run_options(options)
@@ -33,7 +32,6 @@ def validate_run_options(options)
   end
 
   def command_module
-    #
   end
 
   def test_make_parser
@@ -49,7 +47,7 @@ def test_parse_options
 
   def test_run
     opts = command_module.run(argv_for_test_run,
-                              options_for_test_run.merge(noop: true))
+      options_for_test_run.merge(noop: true),)
 
     validate_run_options opts
   end
@@ -57,124 +55,125 @@ def test_run
 
 module PrmdTestHelpers
   module Paths
-    def self.schemas(*args)
-      File.join(File.expand_path('schemata', File.dirname(__FILE__)), *args)
+    def self.schemas(*)
+      File.join(File.expand_path("schemata", File.dirname(__FILE__)), *)
     end
 
-    def self.input_schemas(*args)
-      schemas('input', *args)
+    def self.input_schemas(*)
+      schemas("input", *)
     end
 
-    def self.output_schemas(*args)
-      schemas('output', *args)
+    def self.output_schemas(*)
+      schemas("output", *)
     end
   end
 end
 
-def schemas_path(*args)
-  PrmdTestHelpers::Paths.schemas(*args)
+def schemas_path(*)
+  PrmdTestHelpers::Paths.schemas(*)
 end
 
-def input_schemas_path(*args)
-  PrmdTestHelpers::Paths.input_schemas(*args)
+def input_schemas_path(*)
+  PrmdTestHelpers::Paths.input_schemas(*)
 end
 
-def output_schemas_path(*args)
-  PrmdTestHelpers::Paths.output_schemas(*args)
+def output_schemas_path(*)
+  PrmdTestHelpers::Paths.output_schemas(*)
 end
 
 def user_input_schema
-  @user_input_schema ||= Prmd.combine(input_schemas_path('user.json'))
+  @user_input_schema ||= Prmd.combine(input_schemas_path("user.json"))
 end
 
 module PrmdLinkTestHelpers
   def link_parent_required
     {
-      "description"=>"Create User",
-      "href"=>"/users",
-      "method"=>"POST",
-      "rel"=>"create",
-      "schema"=> {
-        "properties"=>{
-          "user"=>{
-            "type"=>["object"], "properties"=>{"email"=>"string", "name"=>"string"}}
+      "description" => "Create User",
+      "href" => "/users",
+      "method" => "POST",
+      "rel" => "create",
+      "schema" => {
+        "properties" => {
+          "user" => {
+            "type" => ["object"], "properties" => { "email" => "string", "name" => "string" },
+          },
         },
-        "type"=>["object"],
-        "required"=>["user"]
+        "type" => ["object"],
+        "required" => ["user"],
       },
-      "title"=>"Create"
+      "title" => "Create",
     }
   end
 
   def link_no_required
     {
-      "description"=>"Create User",
-      "href"=>"/users",
-      "method"=>"POST",
-      "rel"=>"create",
-      "schema"=> {
-        "properties"=>{
-          "user"=>{
-            "type"=>["object"], "properties"=>{"email"=>"string", "name"=>"string"}}
+      "description" => "Create User",
+      "href" => "/users",
+      "method" => "POST",
+      "rel" => "create",
+      "schema" => {
+        "properties" => {
+          "user" => {
+            "type" => ["object"], "properties" => { "email" => "string", "name" => "string" },
+          },
         },
-        "type"=>["object"]
+        "type" => ["object"],
       },
-      "title"=>"Create"
+      "title" => "Create",
     }
   end
 
   def link_child_required
     {
-      "description"=>"Create user",
-      "href"=>"/users",
-      "method"=>"POST",
-      "rel"=>"create",
-      "schema"=> {
-        "properties"=>{
-          "user"=>{
-            "type"=>["object"],
-            "properties"=>{
-              "email"=>"string",
-              "name"=>"string"
+      "description" => "Create user",
+      "href" => "/users",
+      "method" => "POST",
+      "rel" => "create",
+      "schema" => {
+        "properties" => {
+          "user" => {
+            "type" => ["object"],
+            "properties" => {
+              "email" => "string",
+              "name" => "string",
             },
-            "required" =>  ["email"]
-          }
+            "required" => ["email"],
+          },
         },
-        "type"=>["object"]
+        "type" => ["object"],
       },
-      "title"=>"Create"
+      "title" => "Create",
     }
   end
 
   def link_multiple_nested_required
     {
-      "description"=>"Create user",
-      "href"=>"/users",
-      "method"=>"POST",
-      "rel"=>"create",
-      "schema"=> {
-        "properties"=>{
-          "user"=>{
-            "type"=>["object"],
-            "properties"=>{
-              "email"=>"string",
-              "name"=>"string"
+      "description" => "Create user",
+      "href" => "/users",
+      "method" => "POST",
+      "rel" => "create",
+      "schema" => {
+        "properties" => {
+          "user" => {
+            "type" => ["object"],
+            "properties" => {
+              "email" => "string",
+              "name" => "string",
             },
-            "required" =>  ["email"]
+            "required" => ["email"],
           },
           "address" => {
-            "type"=>["object"],
-            "properties"=>{
-              "street"=>"string",
-              "zip"=>"string"
-            }
-          }
+            "type" => ["object"],
+            "properties" => {
+              "street" => "string",
+              "zip" => "string",
+            },
+          },
         },
-        "type"=>["object"],
-        "required" => ["address"]
+        "type" => ["object"],
+        "required" => ["address"],
       },
-      "title"=>"Create"
+      "title" => "Create",
     }
-
   end
 end
diff --git a/test/link_test.rb b/test/link_test.rb
index 7801b73..af54872 100644
--- a/test/link_test.rb
+++ b/test/link_test.rb
@@ -1,4 +1,4 @@
-require_relative 'helpers'
+require_relative "helpers"
 
 module Prmd
   class LinkTest < Minitest::Test
@@ -8,35 +8,33 @@ class LinkTest < Minitest::Test
       {
         title: "no_required",
         required: {},
-        optional: {"user:email" => "string", "user:name" => "string"}
+        optional: { "user:email" => "string", "user:name" => "string" },
       },
       {
         title: "parent_required",
         optional: {},
-        required: {"user:email" => "string", "user:name" => "string"}
+        required: { "user:email" => "string", "user:name" => "string" },
       },
       {
         title: "child_required",
-        optional: {"user:name" => "string"},
-        required: {"user:email" => "string"}
+        optional: { "user:name" => "string" },
+        required: { "user:email" => "string" },
       },
       {
-        title: "multiple_nested_required" ,
-        optional: {"user:name" => "string"},
-        required: {"user:email" => "string",
-                   "address:street" => "string",
-                   "address:zip" => "string"}
-      }
+        title: "multiple_nested_required",
+        optional: { "user:name" => "string" },
+        required: { "user:email" => "string",
+                    "address:street" => "string",
+                    "address:zip" => "string", },
+      },
     ].each do |test_hash|
-
       define_method "test_#{test_hash[:title]}" do
-        subject = Prmd::Link.new( send("link_#{test_hash[:title]}"))
+        subject = Prmd::Link.new(send("link_#{test_hash[:title]}"))
         required, optional = subject.required_and_optional_parameters
 
         assert_equal required, test_hash[:required]
         assert_equal optional, test_hash[:optional]
       end
     end
-
   end
 end
diff --git a/test/multi_loader/common.rb b/test/multi_loader/common.rb
index e6a02b7..7b7c48e 100644
--- a/test/multi_loader/common.rb
+++ b/test/multi_loader/common.rb
@@ -1,21 +1,19 @@
-require_relative '../helpers'
+require_relative "../helpers"
 
 module PrmdLoaderTests
   # @abstrac
   def testing_filename
-    #
   end
 
   # @abstract
   def loader_module
-    #
   end
 
   def assert_test_data(data)
     assert_kind_of Hash, data
-    assert_equal 'yes', data['test']
-    assert_kind_of Hash, data['object']
-    assert_equal 'Object', data['object']['is_a']
+    assert_equal "yes", data["test"]
+    assert_kind_of Hash, data["object"]
+    assert_equal "Object", data["object"]["is_a"]
   end
 
   def test_load_data
@@ -24,7 +22,7 @@ def test_load_data
   end
 
   def test_load_stream
-    File.open(testing_filename, 'r') do |f|
+    File.open(testing_filename, "r") do |f|
       assert_test_data loader_module.load_stream(f)
     end
   end
diff --git a/test/multi_loader/json_test.rb b/test/multi_loader/json_test.rb
index 85e50ef..c7361f6 100644
--- a/test/multi_loader/json_test.rb
+++ b/test/multi_loader/json_test.rb
@@ -1,5 +1,5 @@
-require_relative 'common'
-require 'prmd/multi_loader/json'
+require_relative "common"
+require "prmd/multi_loader/json"
 
 class PrmdMultiLoaderJsonTest < Minitest::Test
   include PrmdLoaderTests
@@ -9,6 +9,6 @@ def loader_module
   end
 
   def testing_filename
-    schemas_path('data/test.json')
+    schemas_path("data/test.json")
   end
 end
diff --git a/test/multi_loader/toml_test.rb b/test/multi_loader/toml_test.rb
index 71e83b1..8bbd69b 100644
--- a/test/multi_loader/toml_test.rb
+++ b/test/multi_loader/toml_test.rb
@@ -1,18 +1,19 @@
-require_relative 'common'
+require_relative "common"
 begin
-  require 'prmd/multi_loader/toml'
+  require "prmd/multi_loader/toml"
 rescue LoadError
-  #
 end
 
-class PrmdMultiLoaderTomlTest < Minitest::Test
-  include PrmdLoaderTests
+if defined?(TOML)
+  class PrmdMultiLoaderTomlTest < Minitest::Test
+    include PrmdLoaderTests
 
-  def loader_module
-    Prmd::MultiLoader::Toml
-  end
+    def loader_module
+      Prmd::MultiLoader::Toml
+    end
 
-  def testing_filename
-    schemas_path('data/test.toml')
+    def testing_filename
+      schemas_path("data/test.toml")
+    end
   end
-end if defined?(TOML)
+end
diff --git a/test/multi_loader/yajl_test.rb b/test/multi_loader/yajl_test.rb
index a8a6529..5760675 100644
--- a/test/multi_loader/yajl_test.rb
+++ b/test/multi_loader/yajl_test.rb
@@ -1,18 +1,19 @@
-require_relative 'common'
+require_relative "common"
 begin
-  require 'prmd/multi_loader/yajl'
+  require "prmd/multi_loader/yajl"
 rescue LoadError
-  #
 end
 
-class PrmdMultiLoaderYajlTest < Minitest::Test
-  include PrmdLoaderTests
+if defined?(Yajl)
+  class PrmdMultiLoaderYajlTest < Minitest::Test
+    include PrmdLoaderTests
 
-  def loader_module
-    Prmd::MultiLoader::Yajl
-  end
+    def loader_module
+      Prmd::MultiLoader::Yajl
+    end
 
-  def testing_filename
-    schemas_path('data/test.json')
+    def testing_filename
+      schemas_path("data/test.json")
+    end
   end
-end if defined?(Yajl)
+end
diff --git a/test/multi_loader/yaml_test.rb b/test/multi_loader/yaml_test.rb
index b848373..0275e92 100644
--- a/test/multi_loader/yaml_test.rb
+++ b/test/multi_loader/yaml_test.rb
@@ -1,5 +1,5 @@
-require_relative 'common'
-require 'prmd/multi_loader/yaml'
+require_relative "common"
+require "prmd/multi_loader/yaml"
 
 class PrmdMultiLoaderYamlTest < Minitest::Test
   include PrmdLoaderTests
@@ -9,6 +9,6 @@ def loader_module
   end
 
   def testing_filename
-    schemas_path('data/test.yaml')
+    schemas_path("data/test.yaml")
   end
 end
diff --git a/test/rake_tasks/combine_test.rb b/test/rake_tasks/combine_test.rb
index c00c9ae..7a05864 100644
--- a/test/rake_tasks/combine_test.rb
+++ b/test/rake_tasks/combine_test.rb
@@ -1,38 +1,42 @@
-require_relative '../helpers'
-require 'prmd/rake_tasks/combine'
-require 'rake'
+require_relative "../helpers"
+require "prmd/rake_tasks/combine"
+require "rake"
 
 # due to the nature of these Rake Tests, this should not be executed in a
 # read-only filesystem or directory.
 class PrmdRakeTaskCombineTest < Minitest::Test
   def test_define_wo_options
-    paths = [input_schemas_path('rake_combine')]
-    #output_file = output_schemas_path('rake_combine_with_options.json')
+    paths = [input_schemas_path("rake_combine")]
+    # output_file = output_schemas_path('rake_combine_with_options.json')
     output_file = nil
-    File.delete(output_file) if File.exist?(output_file) if output_file
+    if output_file
+      File.delete(output_file) if File.exist?(output_file)
+    end
     Prmd::RakeTasks::Combine.new do |t|
       t.name = :combine_wo_options
-      t.options[:meta] = input_schemas_path('rake-meta.json')
+      t.options[:meta] = input_schemas_path("rake-meta.json")
       t.paths.concat(paths)
       t.output_file = output_file
     end
-    Rake::Task['combine_wo_options'].invoke
+    Rake::Task["combine_wo_options"].invoke
     assert File.exist?(output_file) if output_file
   end
 
   def test_define_with_options
-    paths = [input_schemas_path('rake_combine')]
-    #output_file = output_schemas_path('rake_combine_with_options.json')
+    paths = [input_schemas_path("rake_combine")]
+    # output_file = output_schemas_path('rake_combine_with_options.json')
     output_file = nil
     options = {
-      meta: input_schemas_path('rake-meta.json')
+      meta: input_schemas_path("rake-meta.json"),
     }
-    File.delete(output_file) if File.exist?(output_file) if output_file
+    if output_file
+      File.delete(output_file) if File.exist?(output_file)
+    end
     Prmd::RakeTasks::Combine.new(name: :combine_with_options,
-                                 paths: paths,
-                                 output_file: output_file,
-                                 options: options)
-    Rake::Task['combine_with_options'].invoke
+      paths: paths,
+      output_file: output_file,
+      options: options,)
+    Rake::Task["combine_with_options"].invoke
     assert File.exist?(output_file) if output_file
   end
 end
diff --git a/test/rake_tasks/doc_test.rb b/test/rake_tasks/doc_test.rb
index 16ff66c..a684647 100644
--- a/test/rake_tasks/doc_test.rb
+++ b/test/rake_tasks/doc_test.rb
@@ -1,31 +1,35 @@
-require_relative '../helpers'
-require 'prmd/rake_tasks/doc'
-require 'rake'
+require_relative "../helpers"
+require "prmd/rake_tasks/doc"
+require "rake"
 
 # due to the nature of these Rake Tests, this should not be executed in a
 # read-only filesystem or directory.
 class PrmdRakeTaskDocTest < Minitest::Test
   def test_define_wo_options
-    input_file = input_schemas_path('rake_doc.json')
-    #output_file = output_schemas_path('rake_doc_with_options.md')
+    input_file = input_schemas_path("rake_doc.json")
+    # output_file = output_schemas_path('rake_doc_with_options.md')
     output_file = nil
-    File.delete(output_file) if File.exist?(output_file) if output_file
+    if output_file
+      File.delete(output_file) if File.exist?(output_file)
+    end
     Prmd::RakeTasks::Doc.new do |t|
       t.name = :doc_wo_options
       t.files = { input_file => output_file }
     end
-    Rake::Task['doc_wo_options'].invoke
+    Rake::Task["doc_wo_options"].invoke
     assert File.exist?(output_file) if output_file
   end
 
   def test_define_with_options
-    input_file = input_schemas_path('rake_doc.json')
-    #output_file = output_schemas_path('rake_doc_with_options.md')
+    input_file = input_schemas_path("rake_doc.json")
+    # output_file = output_schemas_path('rake_doc_with_options.md')
     output_file = nil
-    File.delete(output_file) if File.exist?(output_file) if output_file
+    if output_file
+      File.delete(output_file) if File.exist?(output_file)
+    end
     Prmd::RakeTasks::Doc.new(name: :doc_with_options,
-                             files: { input_file => output_file })
-    Rake::Task['doc_with_options'].invoke
+      files: { input_file => output_file },)
+    Rake::Task["doc_with_options"].invoke
     assert File.exist?(output_file) if output_file
   end
 end
diff --git a/test/rake_tasks/verify_test.rb b/test/rake_tasks/verify_test.rb
index 6ab5df2..eee8e54 100644
--- a/test/rake_tasks/verify_test.rb
+++ b/test/rake_tasks/verify_test.rb
@@ -1,23 +1,23 @@
-require_relative '../helpers'
-require 'prmd/rake_tasks/verify'
-require 'rake'
+require_relative "../helpers"
+require "prmd/rake_tasks/verify"
+require "rake"
 
 # due to the nature of these Rake Tests, this should not be executed in a
 # read-only filesystem or directory.
 class PrmdRakeTaskVerifyTest < Minitest::Test
   def test_define_wo_options
-    input_file = input_schemas_path('rake_verify.json')
+    input_file = input_schemas_path("rake_verify.json")
     Prmd::RakeTasks::Verify.new do |t|
       t.name = :verify_wo_options
       t.files = [input_file]
     end
-    Rake::Task['verify_wo_options'].invoke
+    Rake::Task["verify_wo_options"].invoke
   end
 
   def test_define_with_options
-    input_file = input_schemas_path('rake_verify.json')
+    input_file = input_schemas_path("rake_verify.json")
     Prmd::RakeTasks::Verify.new(name: :verify_with_options,
-                                files: [input_file])
-    Rake::Task['verify_with_options'].invoke
+      files: [input_file],)
+    Rake::Task["verify_with_options"].invoke
   end
 end
diff --git a/test/schema_test.rb b/test/schema_test.rb
index 34d0f1a..1da87cb 100644
--- a/test/schema_test.rb
+++ b/test/schema_test.rb
@@ -1,40 +1,40 @@
-require_relative 'helpers'
+require_relative "helpers"
 
 class SchemaTest < Minitest::Test
   def test_dereference_with_ref
     key, value = user_input_schema.dereference(
-      '$ref' => '#/definitions/user/definitions/id'
+      "$ref" => "#/definitions/user/definitions/id",
     )
-    assert_equal(key,   '#/definitions/user/definitions/id')
-    user_id = user_input_schema['definitions']['user']['definitions']['id']
+    assert_equal(key,   "#/definitions/user/definitions/id")
+    user_id = user_input_schema["definitions"]["user"]["definitions"]["id"]
     assert_equal(value, user_id)
   end
 
   def test_dereference_without_ref
     key, value = user_input_schema.dereference(
-      '#/definitions/user/definitions/id'
+      "#/definitions/user/definitions/id",
     )
-    assert_equal(key,   '#/definitions/user/definitions/id')
-    user_id = user_input_schema['definitions']['user']['definitions']['id']
+    assert_equal(key,   "#/definitions/user/definitions/id")
+    user_id = user_input_schema["definitions"]["user"]["definitions"]["id"]
     assert_equal(value, user_id)
   end
 
   def test_dereference_with_nested_ref
     key, value = user_input_schema.dereference(
-      '$ref' => '#/definitions/user/definitions/identity'
+      "$ref" => "#/definitions/user/definitions/identity",
     )
-    assert_equal(key,   '#/definitions/user/definitions/id')
-    user_id = user_input_schema['definitions']['user']['definitions']['id']
+    assert_equal(key,   "#/definitions/user/definitions/id")
+    user_id = user_input_schema["definitions"]["user"]["definitions"]["id"]
     assert_equal(value, user_id)
   end
 
   def test_dereference_with_local_context
     key, value = user_input_schema.dereference(
-      '$ref'     => '#/definitions/user/properties/id',
-      'override' => true
+      "$ref" => "#/definitions/user/properties/id",
+      "override" => true,
     )
-    assert_equal(key,   '#/definitions/user/definitions/id')
-    user_id = user_input_schema['definitions']['user']['definitions']['id']
-    assert_equal(value, { 'override' => true }.merge(user_id))
+    assert_equal(key,   "#/definitions/user/definitions/id")
+    user_id = user_input_schema["definitions"]["user"]["definitions"]["id"]
+    assert_equal(value, { "override" => true }.merge(user_id))
   end
 end
diff --git a/test/utils_test.rb b/test/utils_test.rb
index 46a9f1b..520c36c 100644
--- a/test/utils_test.rb
+++ b/test/utils_test.rb
@@ -1,4 +1,4 @@
-require_relative 'helpers'
+require_relative "helpers"
 
 class UtilsTest < Minitest::Test
   def test_blank?