explicit 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +75 -67
- data/app/helpers/explicit/application_helper.rb +32 -0
- data/app/views/explicit/documentation/_attribute.html.erb +38 -0
- data/app/views/explicit/documentation/_page.html.erb +166 -0
- data/app/views/explicit/documentation/_request.html.erb +87 -0
- data/app/views/explicit/documentation/request/_examples.html.erb +50 -0
- data/app/views/explicit/documentation/type/_agreement.html.erb +7 -0
- data/app/views/explicit/documentation/type/_array.html.erb +3 -0
- data/app/views/explicit/documentation/type/_big_decimal.html.erb +4 -0
- data/app/views/explicit/documentation/type/_boolean.html.erb +7 -0
- data/app/views/explicit/documentation/type/_date_time_iso8601.html.erb +3 -0
- data/app/views/explicit/documentation/type/_date_time_posix.html.erb +3 -0
- data/app/views/explicit/documentation/type/_enum.html.erb +7 -0
- data/app/views/explicit/documentation/type/_file.html.erb +9 -0
- data/app/views/explicit/documentation/type/_hash.html.erb +4 -0
- data/app/views/explicit/documentation/type/_integer.html.erb +25 -0
- data/app/views/explicit/documentation/type/_one_of.html.erb +11 -0
- data/app/views/explicit/documentation/type/_record.html.erb +9 -0
- data/app/views/explicit/documentation/type/_string.html.erb +21 -0
- data/config/locales/en.yml +27 -11
- data/lib/explicit/configuration.rb +1 -1
- data/lib/explicit/documentation/builder.rb +80 -0
- data/lib/explicit/documentation/markdown.rb +2 -13
- data/lib/explicit/documentation/output/swagger.rb +176 -0
- data/lib/explicit/documentation/output/webpage.rb +31 -0
- data/lib/explicit/documentation/page/partial.rb +20 -0
- data/lib/explicit/documentation/page/request.rb +27 -0
- data/lib/explicit/documentation/section.rb +9 -0
- data/lib/explicit/documentation.rb +12 -145
- data/lib/explicit/request/example.rb +50 -1
- data/lib/explicit/request/invalid_params_error.rb +1 -3
- data/lib/explicit/request/invalid_response_error.rb +2 -15
- data/lib/explicit/request/route.rb +18 -0
- data/lib/explicit/request.rb +43 -24
- data/lib/explicit/test_helper/example_recorder.rb +7 -2
- data/lib/explicit/test_helper.rb +25 -7
- data/lib/explicit/type/agreement.rb +39 -0
- data/lib/explicit/type/array.rb +56 -0
- data/lib/explicit/type/big_decimal.rb +58 -0
- data/lib/explicit/type/boolean.rb +47 -0
- data/lib/explicit/type/date_time_iso8601.rb +41 -0
- data/lib/explicit/type/date_time_posix.rb +44 -0
- data/lib/explicit/type/enum.rb +41 -0
- data/lib/explicit/type/file.rb +60 -0
- data/lib/explicit/type/hash.rb +57 -0
- data/lib/explicit/type/integer.rb +79 -0
- data/lib/explicit/type/literal.rb +45 -0
- data/lib/explicit/type/modifiers/default.rb +24 -0
- data/lib/explicit/type/modifiers/description.rb +11 -0
- data/lib/explicit/type/modifiers/nilable.rb +19 -0
- data/lib/explicit/type/modifiers/param_location.rb +11 -0
- data/lib/explicit/type/one_of.rb +46 -0
- data/lib/explicit/type/record.rb +96 -0
- data/lib/explicit/type/string.rb +68 -0
- data/lib/explicit/type.rb +112 -0
- data/lib/explicit/version.rb +1 -1
- data/lib/explicit.rb +28 -18
- metadata +47 -25
- data/app/views/explicit/application/_documentation.html.erb +0 -136
- data/app/views/explicit/application/_request.html.erb +0 -37
- data/lib/explicit/documentation/property.rb +0 -19
- data/lib/explicit/spec/agreement.rb +0 -17
- data/lib/explicit/spec/array.rb +0 -28
- data/lib/explicit/spec/bigdecimal.rb +0 -27
- data/lib/explicit/spec/boolean.rb +0 -30
- data/lib/explicit/spec/date_time_iso8601.rb +0 -17
- data/lib/explicit/spec/date_time_posix.rb +0 -21
- data/lib/explicit/spec/default.rb +0 -20
- data/lib/explicit/spec/error.rb +0 -63
- data/lib/explicit/spec/hash.rb +0 -30
- data/lib/explicit/spec/inclusion.rb +0 -15
- data/lib/explicit/spec/integer.rb +0 -53
- data/lib/explicit/spec/literal.rb +0 -15
- data/lib/explicit/spec/nilable.rb +0 -15
- data/lib/explicit/spec/one_of.rb +0 -40
- data/lib/explicit/spec/record.rb +0 -33
- data/lib/explicit/spec/string.rb +0 -50
- data/lib/explicit/spec.rb +0 -72
| @@ -0,0 +1,68 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class Explicit::Type::String < Explicit::Type
         | 
| 4 | 
            +
              attr_reader :empty, :strip, :format, :minlength, :maxlength, :downcase
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              def initialize(empty: nil, strip: nil, format: nil, minlength: nil, maxlength: nil, downcase: false)
         | 
| 7 | 
            +
                @empty = empty
         | 
| 8 | 
            +
                @strip = strip
         | 
| 9 | 
            +
                @format = format
         | 
| 10 | 
            +
                @minlength = minlength
         | 
| 11 | 
            +
                @maxlength = maxlength
         | 
| 12 | 
            +
                @downcase = downcase
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              def validate(value)
         | 
| 16 | 
            +
                return [:error, error_i18n("string")] if !value.is_a?(::String)
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                value = value.strip if strip
         | 
| 19 | 
            +
                value = value.downcase if downcase
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                if empty == false && value.empty?
         | 
| 22 | 
            +
                  return [:error, error_i18n("empty")]
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                if minlength && value.length < minlength
         | 
| 26 | 
            +
                  return [:error, error_i18n("minlength", minlength:)]
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                if maxlength && value.length > maxlength
         | 
| 30 | 
            +
                  return [:error, error_i18n("maxlength", maxlength:)]
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                if format && !format.match?(value)
         | 
| 34 | 
            +
                  return [:error, error_i18n("format", regex: format.inspect)]
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                [:ok, value]
         | 
| 38 | 
            +
              end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
              concerning :Webpage do
         | 
| 41 | 
            +
                def summary
         | 
| 42 | 
            +
                  "string"
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                def partial
         | 
| 46 | 
            +
                  "explicit/documentation/type/string"
         | 
| 47 | 
            +
                end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                def has_details?
         | 
| 50 | 
            +
                  !empty.nil? || format.present? || minlength.present? || maxlength.present?
         | 
| 51 | 
            +
                end
         | 
| 52 | 
            +
              end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
              concerning :Swagger do
         | 
| 55 | 
            +
                def swagger_schema
         | 
| 56 | 
            +
                  {
         | 
| 57 | 
            +
                    type: "string",
         | 
| 58 | 
            +
                    pattern: format&.inspect,
         | 
| 59 | 
            +
                    minLength: minlength || (empty == false ? 1 : nil),
         | 
| 60 | 
            +
                    maxLength: maxlength,
         | 
| 61 | 
            +
                    description: swagger_description([
         | 
| 62 | 
            +
                      empty == false ? swagger_i18n("string_not_empty") : nil,
         | 
| 63 | 
            +
                      downcase == true ? swagger_i18n("string_downcase") : nil
         | 
| 64 | 
            +
                    ])
         | 
| 65 | 
            +
                  }.compact_blank
         | 
| 66 | 
            +
                end
         | 
| 67 | 
            +
              end
         | 
| 68 | 
            +
            end
         | 
| @@ -0,0 +1,112 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class Explicit::Type
         | 
| 4 | 
            +
              module Modifiers; end
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              def self.build(type)
         | 
| 7 | 
            +
                case type
         | 
| 8 | 
            +
                in :agreement
         | 
| 9 | 
            +
                  Explicit::Type::Agreement.new
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                in [:array, itemtype]
         | 
| 12 | 
            +
                  Explicit::Type::Array.new(itemtype:)
         | 
| 13 | 
            +
                in [:array, itemtype, options]
         | 
| 14 | 
            +
                  Explicit::Type::Array.new(itemtype:, **options)
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                in :bigdecimal
         | 
| 17 | 
            +
                  Explicit::Type::BigDecimal.new
         | 
| 18 | 
            +
                in [:bigdecimal, options]
         | 
| 19 | 
            +
                  Explicit::Type::BigDecimal.new(**options)
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                in :boolean
         | 
| 22 | 
            +
                  Explicit::Type::Boolean.new
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                in :date_time_iso8601
         | 
| 25 | 
            +
                  Explicit::Type::DateTimeISO8601.new
         | 
| 26 | 
            +
                in :date_time_posix
         | 
| 27 | 
            +
                  Explicit::Type::DateTimePosix.new
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                in [:hash, keytype, valuetype]
         | 
| 30 | 
            +
                  Explicit::Type::Hash.new(keytype:, valuetype:)
         | 
| 31 | 
            +
                in [:hash, keytype, valuetype, options]
         | 
| 32 | 
            +
                  Explicit::Type::Hash.new(keytype:, valuetype:, **options)
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                in [:enum, allowed_values]
         | 
| 35 | 
            +
                  Explicit::Type::Enum.new(allowed_values)
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                in :file
         | 
| 38 | 
            +
                  Explicit::Type::File.new
         | 
| 39 | 
            +
                in [:file, options]
         | 
| 40 | 
            +
                  Explicit::Type::File.new(**options)
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                in :integer
         | 
| 43 | 
            +
                  Explicit::Type::Integer.new
         | 
| 44 | 
            +
                in [:integer, options]
         | 
| 45 | 
            +
                  Explicit::Type::Integer.new(**options)
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                in [:literal, value]
         | 
| 48 | 
            +
                  Explicit::Type::Literal.new(value:)
         | 
| 49 | 
            +
                in ::String
         | 
| 50 | 
            +
                  Explicit::Type::Literal.new(value: type)
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                in [:one_of, *subtypes]
         | 
| 53 | 
            +
                  Explicit::Type::OneOf.new(subtypes:)
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                in ::Hash
         | 
| 56 | 
            +
                  Explicit::Type::Record.new(attributes: type)
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                in :string
         | 
| 59 | 
            +
                  Explicit::Type::String.new
         | 
| 60 | 
            +
                in [:string, options]
         | 
| 61 | 
            +
                  Explicit::Type::String.new(**options)
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                ## MODIFIERS
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                in [:default, default, subtype]
         | 
| 66 | 
            +
                  Explicit::Type::Modifiers::Default.apply(default, subtype)
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                in [:description, description, subtype]
         | 
| 69 | 
            +
                  Explicit::Type::Modifiers::Description.apply(description, subtype)
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                in [:nilable, type]
         | 
| 72 | 
            +
                  Explicit::Type::Modifiers::Nilable.apply(type)
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                in [:_param_location, param_location, type]
         | 
| 75 | 
            +
                  Explicit::Type::Modifiers::ParamLocation.apply(param_location, type)
         | 
| 76 | 
            +
                end
         | 
| 77 | 
            +
              end
         | 
| 78 | 
            +
             | 
| 79 | 
            +
              attr_accessor :description, :default, :nilable, :param_location
         | 
| 80 | 
            +
             | 
| 81 | 
            +
              def param_location_path?
         | 
| 82 | 
            +
                param_location == :path
         | 
| 83 | 
            +
              end
         | 
| 84 | 
            +
             | 
| 85 | 
            +
              def required?
         | 
| 86 | 
            +
                !nilable
         | 
| 87 | 
            +
              end
         | 
| 88 | 
            +
             | 
| 89 | 
            +
              def error_i18n(name, context = {})
         | 
| 90 | 
            +
                key = "explicit.errors.#{name}"
         | 
| 91 | 
            +
             | 
| 92 | 
            +
                ::I18n.t(key, **context)
         | 
| 93 | 
            +
              end
         | 
| 94 | 
            +
             | 
| 95 | 
            +
              def swagger_i18n(name, context = {})
         | 
| 96 | 
            +
                key = "explicit.swagger.#{name}"
         | 
| 97 | 
            +
             | 
| 98 | 
            +
                ::I18n.t(key, **context)
         | 
| 99 | 
            +
              end
         | 
| 100 | 
            +
             | 
| 101 | 
            +
              def swagger_description(extras)
         | 
| 102 | 
            +
                extras = extras.compact_blank
         | 
| 103 | 
            +
             | 
| 104 | 
            +
                if description.present? && extras.empty?
         | 
| 105 | 
            +
                  description
         | 
| 106 | 
            +
                elsif description.present? && extras.any?
         | 
| 107 | 
            +
                  description + "\n\n" + extras.compact_blank.join("\n")
         | 
| 108 | 
            +
                else
         | 
| 109 | 
            +
                  extras.compact_blank.join("\n")
         | 
| 110 | 
            +
                end
         | 
| 111 | 
            +
              end
         | 
| 112 | 
            +
            end
         | 
    
        data/lib/explicit/version.rb
    CHANGED
    
    
    
        data/lib/explicit.rb
    CHANGED
    
    | @@ -1,10 +1,17 @@ | |
| 1 | 
            +
            require "active_support/core_ext/module/concerning"
         | 
| 2 | 
            +
             | 
| 1 3 | 
             
            require "explicit/configuration"
         | 
| 2 4 | 
             
            require "explicit/engine"
         | 
| 3 5 | 
             
            require "explicit/version"
         | 
| 4 6 |  | 
| 5 7 | 
             
            require "explicit/documentation"
         | 
| 8 | 
            +
            require "explicit/documentation/builder"
         | 
| 6 9 | 
             
            require "explicit/documentation/markdown"
         | 
| 7 | 
            -
            require "explicit/documentation/ | 
| 10 | 
            +
            require "explicit/documentation/section"
         | 
| 11 | 
            +
            require "explicit/documentation/output/swagger"
         | 
| 12 | 
            +
            require "explicit/documentation/output/webpage"
         | 
| 13 | 
            +
            require "explicit/documentation/page/partial"
         | 
| 14 | 
            +
            require "explicit/documentation/page/request"
         | 
| 8 15 |  | 
| 9 16 | 
             
            require "explicit/test_helper"
         | 
| 10 17 | 
             
            require "explicit/test_helper/example_recorder"
         | 
| @@ -16,20 +23,23 @@ require "explicit/request/invalid_response_error" | |
| 16 23 | 
             
            require "explicit/request/response"
         | 
| 17 24 | 
             
            require "explicit/request/route"
         | 
| 18 25 |  | 
| 19 | 
            -
            require "explicit/ | 
| 20 | 
            -
            require "explicit/ | 
| 21 | 
            -
            require "explicit/ | 
| 22 | 
            -
            require "explicit/ | 
| 23 | 
            -
            require "explicit/ | 
| 24 | 
            -
            require "explicit/ | 
| 25 | 
            -
            require "explicit/ | 
| 26 | 
            -
            require "explicit/ | 
| 27 | 
            -
            require "explicit/ | 
| 28 | 
            -
            require "explicit/ | 
| 29 | 
            -
            require "explicit/ | 
| 30 | 
            -
            require "explicit/ | 
| 31 | 
            -
            require "explicit/ | 
| 32 | 
            -
            require "explicit/ | 
| 33 | 
            -
            require "explicit/ | 
| 34 | 
            -
             | 
| 35 | 
            -
            require "explicit/ | 
| 26 | 
            +
            require "explicit/type"
         | 
| 27 | 
            +
            require "explicit/type/agreement"
         | 
| 28 | 
            +
            require "explicit/type/array"
         | 
| 29 | 
            +
            require "explicit/type/big_decimal"
         | 
| 30 | 
            +
            require "explicit/type/boolean"
         | 
| 31 | 
            +
            require "explicit/type/date_time_iso8601"
         | 
| 32 | 
            +
            require "explicit/type/date_time_posix"
         | 
| 33 | 
            +
            require "explicit/type/enum"
         | 
| 34 | 
            +
            require "explicit/type/file"
         | 
| 35 | 
            +
            require "explicit/type/hash"
         | 
| 36 | 
            +
            require "explicit/type/integer"
         | 
| 37 | 
            +
            require "explicit/type/literal"
         | 
| 38 | 
            +
            require "explicit/type/one_of"
         | 
| 39 | 
            +
            require "explicit/type/record"
         | 
| 40 | 
            +
            require "explicit/type/string"
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            require "explicit/type/modifiers/default"
         | 
| 43 | 
            +
            require "explicit/type/modifiers/description"
         | 
| 44 | 
            +
            require "explicit/type/modifiers/nilable"
         | 
| 45 | 
            +
            require "explicit/type/modifiers/param_location"
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: explicit
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.2. | 
| 4 | 
            +
              version: 0.2.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Luiz Vasconcellos
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2025-01-06 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rails
         | 
| @@ -38,8 +38,8 @@ dependencies: | |
| 38 38 | 
             
                - - "~>"
         | 
| 39 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 40 | 
             
                    version: '2.0'
         | 
| 41 | 
            -
            description: Explicit is a validation and documentation library for  | 
| 42 | 
            -
              enforces documented  | 
| 41 | 
            +
            description: Explicit is a validation and documentation library for REST APIs that
         | 
| 42 | 
            +
              enforces documented types at runtime
         | 
| 43 43 | 
             
            email:
         | 
| 44 44 | 
             
            - luizpvasc@gmail.com
         | 
| 45 45 | 
             
            executables: []
         | 
| @@ -51,15 +51,35 @@ files: | |
| 51 51 | 
             
            - Rakefile
         | 
| 52 52 | 
             
            - app/controllers/explicit/application_controller.rb
         | 
| 53 53 | 
             
            - app/helpers/explicit/application_helper.rb
         | 
| 54 | 
            -
            - app/views/explicit/ | 
| 55 | 
            -
            - app/views/explicit/ | 
| 54 | 
            +
            - app/views/explicit/documentation/_attribute.html.erb
         | 
| 55 | 
            +
            - app/views/explicit/documentation/_page.html.erb
         | 
| 56 | 
            +
            - app/views/explicit/documentation/_request.html.erb
         | 
| 57 | 
            +
            - app/views/explicit/documentation/request/_examples.html.erb
         | 
| 58 | 
            +
            - app/views/explicit/documentation/type/_agreement.html.erb
         | 
| 59 | 
            +
            - app/views/explicit/documentation/type/_array.html.erb
         | 
| 60 | 
            +
            - app/views/explicit/documentation/type/_big_decimal.html.erb
         | 
| 61 | 
            +
            - app/views/explicit/documentation/type/_boolean.html.erb
         | 
| 62 | 
            +
            - app/views/explicit/documentation/type/_date_time_iso8601.html.erb
         | 
| 63 | 
            +
            - app/views/explicit/documentation/type/_date_time_posix.html.erb
         | 
| 64 | 
            +
            - app/views/explicit/documentation/type/_enum.html.erb
         | 
| 65 | 
            +
            - app/views/explicit/documentation/type/_file.html.erb
         | 
| 66 | 
            +
            - app/views/explicit/documentation/type/_hash.html.erb
         | 
| 67 | 
            +
            - app/views/explicit/documentation/type/_integer.html.erb
         | 
| 68 | 
            +
            - app/views/explicit/documentation/type/_one_of.html.erb
         | 
| 69 | 
            +
            - app/views/explicit/documentation/type/_record.html.erb
         | 
| 70 | 
            +
            - app/views/explicit/documentation/type/_string.html.erb
         | 
| 56 71 | 
             
            - config/locales/en.yml
         | 
| 57 72 | 
             
            - config/routes.rb
         | 
| 58 73 | 
             
            - lib/explicit.rb
         | 
| 59 74 | 
             
            - lib/explicit/configuration.rb
         | 
| 60 75 | 
             
            - lib/explicit/documentation.rb
         | 
| 76 | 
            +
            - lib/explicit/documentation/builder.rb
         | 
| 61 77 | 
             
            - lib/explicit/documentation/markdown.rb
         | 
| 62 | 
            -
            - lib/explicit/documentation/ | 
| 78 | 
            +
            - lib/explicit/documentation/output/swagger.rb
         | 
| 79 | 
            +
            - lib/explicit/documentation/output/webpage.rb
         | 
| 80 | 
            +
            - lib/explicit/documentation/page/partial.rb
         | 
| 81 | 
            +
            - lib/explicit/documentation/page/request.rb
         | 
| 82 | 
            +
            - lib/explicit/documentation/section.rb
         | 
| 63 83 | 
             
            - lib/explicit/engine.rb
         | 
| 64 84 | 
             
            - lib/explicit/request.rb
         | 
| 65 85 | 
             
            - lib/explicit/request/example.rb
         | 
| @@ -67,25 +87,27 @@ files: | |
| 67 87 | 
             
            - lib/explicit/request/invalid_response_error.rb
         | 
| 68 88 | 
             
            - lib/explicit/request/response.rb
         | 
| 69 89 | 
             
            - lib/explicit/request/route.rb
         | 
| 70 | 
            -
            - lib/explicit/spec.rb
         | 
| 71 | 
            -
            - lib/explicit/spec/agreement.rb
         | 
| 72 | 
            -
            - lib/explicit/spec/array.rb
         | 
| 73 | 
            -
            - lib/explicit/spec/bigdecimal.rb
         | 
| 74 | 
            -
            - lib/explicit/spec/boolean.rb
         | 
| 75 | 
            -
            - lib/explicit/spec/date_time_iso8601.rb
         | 
| 76 | 
            -
            - lib/explicit/spec/date_time_posix.rb
         | 
| 77 | 
            -
            - lib/explicit/spec/default.rb
         | 
| 78 | 
            -
            - lib/explicit/spec/error.rb
         | 
| 79 | 
            -
            - lib/explicit/spec/hash.rb
         | 
| 80 | 
            -
            - lib/explicit/spec/inclusion.rb
         | 
| 81 | 
            -
            - lib/explicit/spec/integer.rb
         | 
| 82 | 
            -
            - lib/explicit/spec/literal.rb
         | 
| 83 | 
            -
            - lib/explicit/spec/nilable.rb
         | 
| 84 | 
            -
            - lib/explicit/spec/one_of.rb
         | 
| 85 | 
            -
            - lib/explicit/spec/record.rb
         | 
| 86 | 
            -
            - lib/explicit/spec/string.rb
         | 
| 87 90 | 
             
            - lib/explicit/test_helper.rb
         | 
| 88 91 | 
             
            - lib/explicit/test_helper/example_recorder.rb
         | 
| 92 | 
            +
            - lib/explicit/type.rb
         | 
| 93 | 
            +
            - lib/explicit/type/agreement.rb
         | 
| 94 | 
            +
            - lib/explicit/type/array.rb
         | 
| 95 | 
            +
            - lib/explicit/type/big_decimal.rb
         | 
| 96 | 
            +
            - lib/explicit/type/boolean.rb
         | 
| 97 | 
            +
            - lib/explicit/type/date_time_iso8601.rb
         | 
| 98 | 
            +
            - lib/explicit/type/date_time_posix.rb
         | 
| 99 | 
            +
            - lib/explicit/type/enum.rb
         | 
| 100 | 
            +
            - lib/explicit/type/file.rb
         | 
| 101 | 
            +
            - lib/explicit/type/hash.rb
         | 
| 102 | 
            +
            - lib/explicit/type/integer.rb
         | 
| 103 | 
            +
            - lib/explicit/type/literal.rb
         | 
| 104 | 
            +
            - lib/explicit/type/modifiers/default.rb
         | 
| 105 | 
            +
            - lib/explicit/type/modifiers/description.rb
         | 
| 106 | 
            +
            - lib/explicit/type/modifiers/nilable.rb
         | 
| 107 | 
            +
            - lib/explicit/type/modifiers/param_location.rb
         | 
| 108 | 
            +
            - lib/explicit/type/one_of.rb
         | 
| 109 | 
            +
            - lib/explicit/type/record.rb
         | 
| 110 | 
            +
            - lib/explicit/type/string.rb
         | 
| 89 111 | 
             
            - lib/explicit/version.rb
         | 
| 90 112 | 
             
            - lib/tasks/schema/api_tasks.rake
         | 
| 91 113 | 
             
            homepage: https://github.com/luizpvas/explicit
         | 
| @@ -113,5 +135,5 @@ requirements: [] | |
| 113 135 | 
             
            rubygems_version: 3.4.22
         | 
| 114 136 | 
             
            signing_key: 
         | 
| 115 137 | 
             
            specification_version: 4
         | 
| 116 | 
            -
            summary: Explicit is a validation and documentation library for  | 
| 138 | 
            +
            summary: Explicit is a validation and documentation library for REST APIs
         | 
| 117 139 | 
             
            test_files: []
         | 
| @@ -1,136 +0,0 @@ | |
| 1 | 
            -
            <!DOCTYPE html>
         | 
| 2 | 
            -
            <html>
         | 
| 3 | 
            -
            <head>
         | 
| 4 | 
            -
              <title><%= local_assigns[:page_title] || "API Documentation" %></title>
         | 
| 5 | 
            -
             | 
| 6 | 
            -
              <style>
         | 
| 7 | 
            -
                html, body {
         | 
| 8 | 
            -
                  font-family: sans-serif;
         | 
| 9 | 
            -
                  font-size: 14px;
         | 
| 10 | 
            -
                  margin: 0;
         | 
| 11 | 
            -
                  padding: 0;
         | 
| 12 | 
            -
             | 
| 13 | 
            -
                  --color-neutral-100: #f5f5f5;
         | 
| 14 | 
            -
                  --color-neutral-200: #e5e5e5;
         | 
| 15 | 
            -
                  --color-neutral-300: #d4d4d8;
         | 
| 16 | 
            -
                  --color-neutral-400: #a3a3a3;
         | 
| 17 | 
            -
                  --color-neutral-500: #737373;
         | 
| 18 | 
            -
                  --color-neutral-600: #525252;
         | 
| 19 | 
            -
                }
         | 
| 20 | 
            -
             | 
| 21 | 
            -
                .container {
         | 
| 22 | 
            -
                  display: flex;
         | 
| 23 | 
            -
                }
         | 
| 24 | 
            -
             | 
| 25 | 
            -
                .navigation {
         | 
| 26 | 
            -
                  background-color: var(--color-neutral-100);
         | 
| 27 | 
            -
                  border-right: 1px solid var(--color-neutral-300);
         | 
| 28 | 
            -
                  width: 380px;
         | 
| 29 | 
            -
                  height: 100vh;
         | 
| 30 | 
            -
                }
         | 
| 31 | 
            -
                .navigation__section {
         | 
| 32 | 
            -
                }
         | 
| 33 | 
            -
                .navigation__section__page {
         | 
| 34 | 
            -
                  display: block;
         | 
| 35 | 
            -
                }
         | 
| 36 | 
            -
             | 
| 37 | 
            -
                .main {
         | 
| 38 | 
            -
                  flex-grow: 1;
         | 
| 39 | 
            -
                  width: 100%;
         | 
| 40 | 
            -
                  height: 100vh;
         | 
| 41 | 
            -
                  overflow: auto;
         | 
| 42 | 
            -
                }
         | 
| 43 | 
            -
             | 
| 44 | 
            -
                .page {
         | 
| 45 | 
            -
                  padding: 0 2rem;
         | 
| 46 | 
            -
                  margin-bottom: 100px;
         | 
| 47 | 
            -
                }
         | 
| 48 | 
            -
                .page:not(:first-of-type) {
         | 
| 49 | 
            -
                  border-top: 1px solid var(--color-neutral-200);
         | 
| 50 | 
            -
                }
         | 
| 51 | 
            -
                .page__container {
         | 
| 52 | 
            -
                  display: flex;
         | 
| 53 | 
            -
                  gap: 1rem;
         | 
| 54 | 
            -
                }
         | 
| 55 | 
            -
                .page__request {
         | 
| 56 | 
            -
                  width: 50%;
         | 
| 57 | 
            -
                }
         | 
| 58 | 
            -
                .page__request__description {
         | 
| 59 | 
            -
                  line-height: 1.6rem;
         | 
| 60 | 
            -
                }
         | 
| 61 | 
            -
                .page__response {
         | 
| 62 | 
            -
                  width: 50%;
         | 
| 63 | 
            -
                }
         | 
| 64 | 
            -
             | 
| 65 | 
            -
                .markdown code {
         | 
| 66 | 
            -
                  background: var(--color-neutral-100);
         | 
| 67 | 
            -
                  color: var(--color-neutral-900);
         | 
| 68 | 
            -
                }
         | 
| 69 | 
            -
                .markdown p:first-of-type {
         | 
| 70 | 
            -
                  margin-block-start: 0em;
         | 
| 71 | 
            -
                }
         | 
| 72 | 
            -
                .markdown p:last-of-type {
         | 
| 73 | 
            -
                  margin-block-end: 0em;
         | 
| 74 | 
            -
                }
         | 
| 75 | 
            -
             | 
| 76 | 
            -
                .params {
         | 
| 77 | 
            -
                  margin-top: 1rem;
         | 
| 78 | 
            -
                  border: 1px solid var(--color-neutral-200);
         | 
| 79 | 
            -
                  border-radius: 8px;
         | 
| 80 | 
            -
                }
         | 
| 81 | 
            -
                .params__header {
         | 
| 82 | 
            -
                  padding: 5px;
         | 
| 83 | 
            -
                  text-align: center;
         | 
| 84 | 
            -
             | 
| 85 | 
            -
                  font-size: 12px;
         | 
| 86 | 
            -
                  text-transform: uppercase;
         | 
| 87 | 
            -
                  color: var(--color-neutral-500);
         | 
| 88 | 
            -
                  border-bottom: 1px solid var(--color-neutral-200);
         | 
| 89 | 
            -
             | 
| 90 | 
            -
                  background-color: var(--color-neutral-100);
         | 
| 91 | 
            -
                  border-top-left-radius: 8px;
         | 
| 92 | 
            -
                  border-top-right-radius: 8px;
         | 
| 93 | 
            -
                }
         | 
| 94 | 
            -
                .params__param {
         | 
| 95 | 
            -
                  padding: 0.8rem;
         | 
| 96 | 
            -
                }
         | 
| 97 | 
            -
                .params__param:not(:last-of-type) {
         | 
| 98 | 
            -
                  border-bottom: 1px solid var(--color-neutral-200);
         | 
| 99 | 
            -
                }
         | 
| 100 | 
            -
                .params__param__name {
         | 
| 101 | 
            -
                  font-family: monospace;
         | 
| 102 | 
            -
                  font-weight: bold;
         | 
| 103 | 
            -
                }
         | 
| 104 | 
            -
                .params__param__description {
         | 
| 105 | 
            -
                  margin-top: 0.5rem;
         | 
| 106 | 
            -
                  color: var(--color-neutral-500);
         | 
| 107 | 
            -
                }
         | 
| 108 | 
            -
              </style>
         | 
| 109 | 
            -
            </head>
         | 
| 110 | 
            -
             | 
| 111 | 
            -
            <body>
         | 
| 112 | 
            -
              <div class="container">
         | 
| 113 | 
            -
                <section class="navigation">
         | 
| 114 | 
            -
                  <% sections.each do |section| %>
         | 
| 115 | 
            -
                    <details class="navigation__section" open>
         | 
| 116 | 
            -
                      <summary><%= section.name %></summary>
         | 
| 117 | 
            -
             | 
| 118 | 
            -
                      <% section.pages.each do |page| %>
         | 
| 119 | 
            -
                        <%= link_to page.title, "##{page.anchor}", class: "navigation__section__page" %>
         | 
| 120 | 
            -
                      <% end %>
         | 
| 121 | 
            -
                    </details>
         | 
| 122 | 
            -
                  <% end %>
         | 
| 123 | 
            -
                </section>
         | 
| 124 | 
            -
             | 
| 125 | 
            -
                <main class="main">
         | 
| 126 | 
            -
                  <% sections.each do |section| %>
         | 
| 127 | 
            -
                    <% section.pages.each do |page| %>
         | 
| 128 | 
            -
                      <div class="page">
         | 
| 129 | 
            -
                        <%= render partial: page.partial, locals: { page: } %>
         | 
| 130 | 
            -
                      </div>
         | 
| 131 | 
            -
                    <% end %>
         | 
| 132 | 
            -
                  <% end %>
         | 
| 133 | 
            -
                </main>
         | 
| 134 | 
            -
              </div>
         | 
| 135 | 
            -
            </body>
         | 
| 136 | 
            -
            </html>
         | 
| @@ -1,37 +0,0 @@ | |
| 1 | 
            -
            <h1 id="<%= page.anchor %>"><%= page.title %></h1>
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            <div class="page__container">
         | 
| 4 | 
            -
              <div class="page__request">
         | 
| 5 | 
            -
                <div class="page__request__description markdown">
         | 
| 6 | 
            -
                  <%= page.description_html %>
         | 
| 7 | 
            -
                </div>
         | 
| 8 | 
            -
             | 
| 9 | 
            -
                <div class="params">
         | 
| 10 | 
            -
                  <div class="params__header">
         | 
| 11 | 
            -
                    <%= t("explicit.documentation.params_header") %>
         | 
| 12 | 
            -
                  </div>
         | 
| 13 | 
            -
             | 
| 14 | 
            -
                  <% page.params_properties.each do |property| %>
         | 
| 15 | 
            -
                    <div class="params__param">
         | 
| 16 | 
            -
                      <div class="params__param__name">
         | 
| 17 | 
            -
                        <%= property.name %>
         | 
| 18 | 
            -
                      </div>
         | 
| 19 | 
            -
             | 
| 20 | 
            -
                      <% if (description_html = property.description_html) %>
         | 
| 21 | 
            -
                        <div class="params__param__description markdown">
         | 
| 22 | 
            -
                          <%= description_html %>
         | 
| 23 | 
            -
                        </div>
         | 
| 24 | 
            -
                      <% end %>
         | 
| 25 | 
            -
                    </div>
         | 
| 26 | 
            -
                  <% end %>
         | 
| 27 | 
            -
                </div>
         | 
| 28 | 
            -
              </div>
         | 
| 29 | 
            -
             | 
| 30 | 
            -
              <div class="page__response">
         | 
| 31 | 
            -
                <% page.request.responses.map { |k, v| k }.sort.each do |status| %>
         | 
| 32 | 
            -
                  <div>
         | 
| 33 | 
            -
                    <%= status %>
         | 
| 34 | 
            -
                  </div>
         | 
| 35 | 
            -
                <% end %>
         | 
| 36 | 
            -
              </div>
         | 
| 37 | 
            -
            </div>
         | 
| @@ -1,19 +0,0 @@ | |
| 1 | 
            -
            # frozen_string_literal: true
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            class Explicit::Documentation::Property
         | 
| 4 | 
            -
              attr_reader :name, :spec
         | 
| 5 | 
            -
             | 
| 6 | 
            -
              def initialize(name:, spec:)
         | 
| 7 | 
            -
                @name = name
         | 
| 8 | 
            -
                @spec = spec
         | 
| 9 | 
            -
              end
         | 
| 10 | 
            -
             | 
| 11 | 
            -
              def description_html
         | 
| 12 | 
            -
                case spec
         | 
| 13 | 
            -
                in [:description, markdown_text, _subspec]
         | 
| 14 | 
            -
                  Explicit::Documentation::Markdown.render(markdown_text).html_safe
         | 
| 15 | 
            -
                else
         | 
| 16 | 
            -
                  nil
         | 
| 17 | 
            -
                end
         | 
| 18 | 
            -
              end
         | 
| 19 | 
            -
            end
         | 
| @@ -1,17 +0,0 @@ | |
| 1 | 
            -
            # frozen_string_literal: true
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            module Explicit::Spec::Agreement
         | 
| 4 | 
            -
              extend self
         | 
| 5 | 
            -
             | 
| 6 | 
            -
              VALUES = [true, "true", "on", "1", 1].freeze
         | 
| 7 | 
            -
              ERROR = [:error, :agreement].freeze
         | 
| 8 | 
            -
              OK = [:ok, true].freeze
         | 
| 9 | 
            -
             | 
| 10 | 
            -
              def build(options)
         | 
| 11 | 
            -
                lambda do |value|
         | 
| 12 | 
            -
                  return ERROR if !VALUES.include?(value)
         | 
| 13 | 
            -
             | 
| 14 | 
            -
                  OK
         | 
| 15 | 
            -
                end
         | 
| 16 | 
            -
              end
         | 
| 17 | 
            -
            end
         | 
    
        data/lib/explicit/spec/array.rb
    DELETED
    
    | @@ -1,28 +0,0 @@ | |
| 1 | 
            -
            # frozen_string_literal: true
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            module Explicit::Spec::Array
         | 
| 4 | 
            -
              extend self
         | 
| 5 | 
            -
             | 
| 6 | 
            -
              def build(itemspec, options)
         | 
| 7 | 
            -
                itemspec_validator = Explicit::Spec.build(itemspec)
         | 
| 8 | 
            -
             | 
| 9 | 
            -
                lambda do |values|
         | 
| 10 | 
            -
                  return [:error, :array] if !values.is_a?(::Array)
         | 
| 11 | 
            -
             | 
| 12 | 
            -
                  if options[:empty] == false && values.empty?
         | 
| 13 | 
            -
                    return [:error, :empty]
         | 
| 14 | 
            -
                  end
         | 
| 15 | 
            -
             | 
| 16 | 
            -
                  validated = []
         | 
| 17 | 
            -
             | 
| 18 | 
            -
                  values.each.with_index do |value, index|
         | 
| 19 | 
            -
                    case itemspec_validator.call(value)
         | 
| 20 | 
            -
                    in [:ok, value]  then validated << value
         | 
| 21 | 
            -
                    in [:error, err] then return [:error, [:array, index, err]]
         | 
| 22 | 
            -
                    end
         | 
| 23 | 
            -
                  end
         | 
| 24 | 
            -
             | 
| 25 | 
            -
                  [:ok, validated]
         | 
| 26 | 
            -
                end
         | 
| 27 | 
            -
              end
         | 
| 28 | 
            -
            end
         | 
| @@ -1,27 +0,0 @@ | |
| 1 | 
            -
            # frozen_string_literal: true
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            module Explicit::Spec::Bigdecimal
         | 
| 4 | 
            -
              extend self
         | 
| 5 | 
            -
             | 
| 6 | 
            -
              ERROR = [:error, :bigdecimal].freeze
         | 
| 7 | 
            -
             | 
| 8 | 
            -
              def build(options)
         | 
| 9 | 
            -
                lambda do |value|
         | 
| 10 | 
            -
                  return ERROR unless value.is_a?(::String) || value.is_a?(::Integer)
         | 
| 11 | 
            -
             | 
| 12 | 
            -
                  decimalvalue = BigDecimal(value)
         | 
| 13 | 
            -
             | 
| 14 | 
            -
                  if (min = options[:min]) && decimalvalue < min
         | 
| 15 | 
            -
                    return [:error, [:min, min]]
         | 
| 16 | 
            -
                  end
         | 
| 17 | 
            -
             | 
| 18 | 
            -
                  if (max = options[:max]) && decimalvalue > max
         | 
| 19 | 
            -
                    return [:error, [:max, max]]
         | 
| 20 | 
            -
                  end
         | 
| 21 | 
            -
             | 
| 22 | 
            -
                  [:ok, decimalvalue]
         | 
| 23 | 
            -
                rescue ArgumentError
         | 
| 24 | 
            -
                  ERROR
         | 
| 25 | 
            -
                end
         | 
| 26 | 
            -
              end
         | 
| 27 | 
            -
            end
         | 
| @@ -1,30 +0,0 @@ | |
| 1 | 
            -
            # frozen_string_literal: true
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            module Explicit::Spec::Boolean
         | 
| 4 | 
            -
              extend self
         | 
| 5 | 
            -
             | 
| 6 | 
            -
              VALUES = {
         | 
| 7 | 
            -
                true => true,
         | 
| 8 | 
            -
                "true" => true,
         | 
| 9 | 
            -
                "on" => true,
         | 
| 10 | 
            -
                "1" => true,
         | 
| 11 | 
            -
                1 => true,
         | 
| 12 | 
            -
                false => false,
         | 
| 13 | 
            -
                "false" => false,
         | 
| 14 | 
            -
                "off" => false,
         | 
| 15 | 
            -
                "0" => false,
         | 
| 16 | 
            -
                0 => false
         | 
| 17 | 
            -
              }.freeze
         | 
| 18 | 
            -
             | 
| 19 | 
            -
              ERROR = [:error, :boolean].freeze
         | 
| 20 | 
            -
             | 
| 21 | 
            -
              def build(options)
         | 
| 22 | 
            -
                lambda do |value|
         | 
| 23 | 
            -
                  value = VALUES[value]
         | 
| 24 | 
            -
             | 
| 25 | 
            -
                  return ERROR if value.nil?
         | 
| 26 | 
            -
             | 
| 27 | 
            -
                  [:ok, value]
         | 
| 28 | 
            -
                end
         | 
| 29 | 
            -
              end
         | 
| 30 | 
            -
            end
         | 
| @@ -1,17 +0,0 @@ | |
| 1 | 
            -
            # frozen_string_literal: true
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            require "time"
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            module Explicit::Spec::DateTimeISO8601
         | 
| 6 | 
            -
              extend self
         | 
| 7 | 
            -
             | 
| 8 | 
            -
              def call(value)
         | 
| 9 | 
            -
                return [:error, :date_time_iso8601] if !value.is_a?(::String)
         | 
| 10 | 
            -
             | 
| 11 | 
            -
                timeval = Time.iso8601(value)
         | 
| 12 | 
            -
             | 
| 13 | 
            -
                [:ok, timeval]
         | 
| 14 | 
            -
              rescue ArgumentError
         | 
| 15 | 
            -
                [:error, :date_time_iso8601]
         | 
| 16 | 
            -
              end
         | 
| 17 | 
            -
            end
         |