Repository: pboettch/json-schema-validator Branch: main Commit: fb270d5a7dc5 Files: 187 Total size: 498.6 KB Directory structure: gitextract_1ulntizm/ ├── .clang-format ├── .distro/ │ ├── .fmf/ │ │ └── version │ ├── json-schema-validator.spec │ ├── plans/ │ │ ├── import.fmf │ │ ├── main.fmf.dist-git │ │ └── smoke.fmf │ └── tests/ │ ├── import/ │ │ ├── FetchContent/ │ │ │ └── CMakeLists.txt │ │ ├── find_package/ │ │ │ └── CMakeLists.txt │ │ ├── main.fmf │ │ ├── test_FetchContent.sh │ │ └── test_find_package.sh │ └── smoke.fmf ├── .github/ │ └── workflows/ │ ├── release.yaml │ └── test.yaml ├── .gitignore ├── .packit.yaml ├── .pre-commit-config.yaml ├── CMakeLists.txt ├── CMakePresets.json ├── ChangeLog.md ├── LICENSE ├── README.md ├── cmake/ │ ├── CMakePresets-CI.json │ ├── CMakePresets-defaults.json │ └── nlohmann_json_schema_validatorConfig.cmake.in ├── conanfile.py ├── example/ │ ├── CMakeLists.txt │ ├── format.cpp │ └── readme.cpp ├── schema ├── src/ │ ├── CMakeLists.txt │ ├── json-patch.cpp │ ├── json-patch.hpp │ ├── json-schema-draft7.json.cpp │ ├── json-uri.cpp │ ├── json-validator.cpp │ ├── nlohmann/ │ │ └── json-schema.hpp │ ├── smtp-address-validator.cpp │ ├── smtp-address-validator.hpp │ └── string-format-check.cpp └── test/ ├── CMakeLists.txt ├── JSON-Schema-Test-Suite/ │ ├── CMakeLists.txt │ ├── json-schema-test.cpp │ ├── remotes/ │ │ ├── baseUriChange/ │ │ │ └── folderInteger.json │ │ ├── baseUriChangeFolder/ │ │ │ └── folderInteger.json │ │ ├── baseUriChangeFolderInSubschema/ │ │ │ └── folderInteger.json │ │ ├── folder/ │ │ │ └── folderInteger.json │ │ ├── integer.json │ │ ├── name-defs.json │ │ ├── name.json │ │ ├── ref-and-definitions.json │ │ ├── ref-and-defs.json │ │ ├── subSchemas-defs.json │ │ └── subSchemas.json │ └── tests/ │ └── draft7/ │ ├── additionalItems.json │ ├── additionalProperties.json │ ├── allOf.json │ ├── anyOf.json │ ├── boolean_schema.json │ ├── const.json │ ├── contains.json │ ├── default.json │ ├── definitions.json │ ├── dependencies.json │ ├── enum.json │ ├── exclusiveMaximum.json │ ├── exclusiveMinimum.json │ ├── format.json │ ├── id.json │ ├── if-then-else.json │ ├── infinite-loop-detection.json │ ├── items.json │ ├── maxItems.json │ ├── maxLength.json │ ├── maxProperties.json │ ├── maximum.json │ ├── minItems.json │ ├── minLength.json │ ├── minProperties.json │ ├── minimum.json │ ├── multipleOf.json │ ├── not.json │ ├── oneOf.json │ ├── optional/ │ │ ├── bignum.json │ │ ├── content.json │ │ ├── ecmascript-regex.json │ │ ├── float-overflow.json │ │ ├── format/ │ │ │ ├── date-time.json │ │ │ ├── date.json │ │ │ ├── email.json │ │ │ ├── hostname.json │ │ │ ├── idn-email.json │ │ │ ├── idn-hostname.json │ │ │ ├── ipv4.json │ │ │ ├── ipv6.json │ │ │ ├── iri-reference.json │ │ │ ├── iri.json │ │ │ ├── json-pointer.json │ │ │ ├── regex.json │ │ │ ├── relative-json-pointer.json │ │ │ ├── time.json │ │ │ ├── uri-reference.json │ │ │ ├── uri-template.json │ │ │ ├── uri.json │ │ │ └── uuid.json │ │ ├── non-bmp-regex.json │ │ └── unicode.json │ ├── pattern.json │ ├── patternProperties.json │ ├── properties.json │ ├── propertyNames.json │ ├── ref.json │ ├── refRemote.json │ ├── required.json │ ├── type.json │ ├── uniqueItems.json │ └── unknownKeyword.json ├── binary-validation.cpp ├── errors.cpp ├── id-ref.cpp ├── issue-100/ │ ├── CMakeLists.txt │ ├── instance.json │ └── schema.json ├── issue-101/ │ ├── CMakeLists.txt │ ├── instance.json │ └── schema.json ├── issue-105-verbose-combination-errors.cpp ├── issue-117-format-error.cpp ├── issue-12/ │ ├── CMakeLists.txt │ ├── instance.json │ └── schema.json ├── issue-143/ │ ├── CMakeLists.txt │ ├── instance-fail-1.json │ ├── instance-fail-a.json │ ├── instance.json │ └── schema.json ├── issue-149-entry-selection.cpp ├── issue-189-default-values.cpp ├── issue-209/ │ ├── CMakeLists.txt │ ├── color.schema.json │ ├── entities.schema.json │ └── instance.json ├── issue-229-oneof-default-values.cpp ├── issue-243-root-default-values.cpp ├── issue-25-default-values.cpp ├── issue-255-error-message-limit-precision.cpp ├── issue-27/ │ ├── CMakeLists.txt │ ├── README │ ├── instance.json │ └── schema.json ├── issue-293.cpp ├── issue-311/ │ ├── CMakeLists.txt │ ├── instance.json │ └── schema.json ├── issue-48/ │ ├── CMakeLists.txt │ ├── instance.json │ └── schema.json ├── issue-54/ │ ├── CMakeLists.txt │ ├── instance.json │ └── schema.json ├── issue-70-root-schema-constructor.cpp ├── issue-70.cpp ├── issue-75/ │ ├── CMakeLists.txt │ ├── TypeId.json │ ├── instance.json │ └── schema.json ├── issue-9/ │ ├── CMakeLists.txt │ ├── bar.json │ ├── base.json │ ├── foo/ │ │ ├── baz/ │ │ │ ├── baz.json │ │ │ └── qux/ │ │ │ └── qux.json │ │ └── foo.json │ └── instance.json ├── issue-93/ │ ├── CMakeLists.txt │ ├── blueprints.schema.json │ ├── components.schema.json │ ├── issue-93.cpp │ └── types/ │ └── color.schema.json ├── issue-96/ │ ├── CMakeLists.txt │ ├── instance.json │ └── schema.json ├── issue-98.cpp ├── json-patch.cpp ├── json-schema-validate.cpp ├── string-format-check-test.cpp ├── test-pipe-in.sh └── uri.cpp ================================================ FILE CONTENTS ================================================ ================================================ FILE: .clang-format ================================================ BasedOnStyle: LLVM #AlignConsecutiveAssignments: true #AlignConsecutiveDeclarations: true AllowShortFunctionsOnASingleLine: Inline BreakBeforeBraces: Linux ColumnLimit: 0 ConstructorInitializerAllOnOneLineOrOnePerLine: true IndentWidth: 4 IndentPPDirectives: AfterHash ObjCBlockIndentWidth: 0 SpaceAfterCStyleCast: true TabWidth: 4 AccessModifierOffset: -4 UseTab: ForIndentation ================================================ FILE: .distro/.fmf/version ================================================ 1 ================================================ FILE: .distro/json-schema-validator.spec ================================================ Name: json-schema-validator Summary: JSON schema validator for JSON for Modern C++ Version: 0.0.0 Release: %autorelease License: MIT URL: https://github.com/pboettch/json-schema-validator Source: https://github.com/pboettch/json-schema-validator/archive/refs/tags/v%{version}.tar.gz BuildRequires: ninja-build BuildRequires: cmake BuildRequires: gcc-c++ BuildRequires: json-devel %description Json schema validator library for C++ projects using nlohmann/json %package devel Summary: Development files for JSON schema validator Requires: json-schema-validator%{?_isa} = %{version}-%{release} Requires: json-devel %description devel Json schema validator development files for C++ projects using nlohmann/json %prep %autosetup -n json-schema-validator-%{version} %build %cmake \ -DJSON_VALIDATOR_SHARED_LIBS=ON \ -DJSON_VALIDATOR_INSTALL=ON \ -DJSON_VALIDATOR_BUILD_EXAMPLES=OFF \ -DJSON_VALIDATOR_BUILD_TESTS=ON %cmake_build %install %cmake_install %check %ctest %files %doc README.md %license LICENSE %{_libdir}/libnlohmann_json_schema_validator.so.* %files devel %{_libdir}/libnlohmann_json_schema_validator.so %{_includedir}/nlohmann/json-schema.hpp %{_libdir}/cmake/nlohmann_json_schema_validator %changelog %autochangelog ================================================ FILE: .distro/plans/import.fmf ================================================ summary: Basic importing tests prepare+: - name: Include minimum fetching packages how: install package: - git discover+: how: fmf filter: "tag: import" execute: how: tmt ================================================ FILE: .distro/plans/main.fmf.dist-git ================================================ discover: how: fmf path: . adjust+: # Cannot use initiator: fedora-ci reliably yet when: initiator is not defined or initiator != packit discover+: dist-git-source: true dist-git-extract: json-schema-validator-*/ ================================================ FILE: .distro/plans/smoke.fmf ================================================ summary: Basic smoke tests discover+: how: fmf filter: "tag: smoke" execute: how: tmt ================================================ FILE: .distro/tests/import/FetchContent/CMakeLists.txt ================================================ # This is a simple project that tests using cmake to load the installed libraries cmake_minimum_required(VERSION 3.14) project(test_fetch_content LANGUAGES CXX) FetchContent_Declare(nlohmann_json_schema_validator GIT_REPOSITORY https://github.com/pboettch/json-schema-validator GIT_TAG main ) FetchContent_MakeAvailable(nlohmann_json_schema_validator) if (NOT TARGET nlohmann_json_schema_validator::validator) message(FATAL_ERROR "Missing target nlohmann_json_schema_validator::validator") endif () ================================================ FILE: .distro/tests/import/find_package/CMakeLists.txt ================================================ # This is a simple project that tests using cmake to load the installed libraries cmake_minimum_required(VERSION 3.14) project(test_find_package LANGUAGES CXX) set(CMAKE_FIND_DEBUG_MODE ON) find_package(nlohmann_json_schema_validator REQUIRED) if (NOT TARGET nlohmann_json_schema_validator::validator) message(FATAL_ERROR "Missing target nlohmann_json_schema_validator::validator") endif () ================================================ FILE: .distro/tests/import/main.fmf ================================================ # Common test variables tag: - import tier: 0 path: /tests/import # Define tests /find_package: test: ./test_find_package.sh /FetchContent: test: ./test_FetchContent.sh ================================================ FILE: .distro/tests/import/test_FetchContent.sh ================================================ #!/bin/bash -eux tmp_dir=$(mktemp -d) cmake -S ./FetchContent -B ${tmp_dir} ================================================ FILE: .distro/tests/import/test_find_package.sh ================================================ #!/bin/bash -eux tmp_dir=$(mktemp -d) cmake -S ./find_package -B ${tmp_dir} ================================================ FILE: .distro/tests/smoke.fmf ================================================ # Common test variables tag: - smoke tier: 0 path: / # Define tests /version: test: echo "TODO: Write a minimum working example" ================================================ FILE: .github/workflows/release.yaml ================================================ name: release run-name: Release on: push: tags: - "[0-9]+.[0-9]+.[0-9]+" jobs: tests: uses: ./.github/workflows/test.yaml secrets: inherit publish-release: needs: [tests] runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Create GitHub Release uses: softprops/action-gh-release@v2 with: name: "json-schema-validator ${{ github.ref }}" prerelease: false draft: false generate_release_notes: true build_conan: needs: [tests] runs-on: ubuntu-latest container: ghcr.io/nlohmann/json-ci:v2.4.0 steps: - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub." - run: echo "🔎 Branch name is ${{ github.ref }} and repository is ${{ github.repository }}." - name: Clone json-schema-validator uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: python-version: '3.10' - run: python -m pip install --upgrade conan - run: conan config init - run: conan profile update settings.compiler.libcxx=libstdc++11 default - name: conan create package run: conan create . ================================================ FILE: .github/workflows/test.yaml ================================================ name: test run-name: Tests on: push: branches: [ main ] pull_request: branches: [ main ] # Make it able to be used in other workflows workflow_call: defaults: run: shell: bash jobs: pre-commit: name: Check pre-commit runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 - uses: pre-commit/action@v3.0.0 test: name: Run ctests needs: [ pre-commit ] continue-on-error: ${{ matrix.experimental }} strategy: fail-fast: false matrix: toolchain: [ gcc, llvm, intel ] json_version: [ develop, v3.12.0, v3.8.0 ] experimental: [ false ] include: - toolchain: llvm compiler_version: 15 - toolchain: gcc compiler_version: latest env: NLOHMANN_JSON_VERSION: ${{ matrix.json_version }} runs-on: ubuntu-latest container: ghcr.io/nlohmann/json-ci:v2.4.0 steps: - name: Activate Intel compilers # Not elegant, it will propagate all environment variable. # Intel does not provide a way to output the environment variables to a file # Note: PATH needs to be exported to GITHUB_PATH otherwise it can be overwritten run: | source /opt/intel/oneapi/setvars.sh printenv >> $GITHUB_ENV echo $PATH >> $GITHUB_PATH if: matrix.toolchain == 'intel' - name: Setup gcc toolchain run: | update-alternatives --install /usr/bin/g++ g++ $(which g++-${{ matrix.compiler_version }}) 999 if: matrix.compiler_version && matrix.toolchain == 'gcc' - name: Setup llvm toolchain run: | update-alternatives --install /usr/bin/clang++ clang++ $(which clang++-${{ matrix.compiler_version }}) 999 if: matrix.compiler_version && matrix.toolchain == 'llvm' - uses: actions/checkout@v3 # container version is < 3.25 which does not have workflows - name: Get a working cmake version uses: lukka/get-cmake@v3.25.2 - name: Run CMake ${{ matrix.toolchain }}-ci workflow with nlohmann/json version ${{ matrix.json_version }} uses: lukka/run-cmake@v10.5 with: workflowPreset: "${{ matrix.toolchain }}-ci" coverage: name: Run coverage tests needs: [ test ] runs-on: ubuntu-latest container: ghcr.io/nlohmann/json-ci:v2.4.0 if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' }} steps: - uses: actions/checkout@v3 - name: Get latest cmake version uses: lukka/get-cmake@latest - name: Get test coverage uses: lukka/run-cmake@v10.5 with: workflowPreset: ci-coverage - name: Get lcov data uses: danielealbano/lcov-action@v3 with: # Note lcov-action prepends and appends wild-cards *. Account for those # https://github.com/danielealbano/lcov-action/issues/11 remove_patterns: /test/,/cmake-build*/ - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 with: files: coverage.info verbose: true ================================================ FILE: .gitignore ================================================ build*/ *.sw? cmake-build-* venv env compile_commands.json .vs/* ================================================ FILE: .packit.yaml ================================================ files_to_sync: - src: .distro/ dest: ./ delete: true filters: - "protect .git*" - "protect sources" - "protect changelog" - "protect gating.yaml" # Temporary workaround until # https://github.com/packit/packit/pull/2573 - "- json-schema-validator.spec" - .packit.yaml upstream_package_name: json-schema-validator specfile_path: .distro/json-schema-validator.spec downstream_package_name: json-schema-validator update_release: false targets: &targets - fedora-all-x86_64 # TODO: aarch64 is failing at test # JSON-Suite::Optional::Format::idn-email # - fedora-all-aarch64 _: # Job templates - &build-in-packit job: copr_build - &build-in-lecris <<: *build-in-packit owner: "@scikit-build" - &tests job: tests fmf_path: .distro identifier: downstream jobs: # Upstream jobs - <<: *build-in-lecris trigger: release project: release # - <<: *tests # trigger: release - <<: *build-in-lecris trigger: commit branch: main project: nightly # - <<: *tests # trigger: commit # branch: main - <<: *build-in-packit trigger: pull_request # - <<: *tests # trigger: pull_request # Downstream jobs - job: propose_downstream trigger: release dist_git_branches: - fedora-rawhide - job: koji_build trigger: commit dist_git_branches: - fedora-all - job: bodhi_update trigger: commit dist_git_branches: - fedora-branched ================================================ FILE: .pre-commit-config.yaml ================================================ repos: - repo: https://github.com/Takishima/cmake-pre-commit-hooks rev: v1.9.6 hooks: - id: clang-format args: - '-i' - id: clang-tidy args: # TODO: Remove when upstream issue is fixed # https://gitlab.kitware.com/cmake/cmake/-/issues/24827 # https://github.com/Takishima/cmake-pre-commit-hooks/issues/63 - '-Bcmake-build-pre-commit' - '--preset' - 'pre-commit' stages: [ manual ] - repo: https://github.com/pre-commit/pre-commit-hooks rev: v6.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer - id: check-yaml - repo: https://github.com/executablebooks/mdformat rev: 0.7.22 hooks: - id: mdformat additional_dependencies: - mdformat-gfm - mdformat-tables - repo: https://github.com/python-jsonschema/check-jsonschema rev: 0.34.0 hooks: - id: check-github-workflows ================================================ FILE: CMakeLists.txt ================================================ cmake_minimum_required(VERSION 3.14) # CMake version compatibility # TODO: Remove when bumping cmake >= 3.25 if (POLICY CMP0140) # Enables: return(PROPAGATE) cmake_policy(SET CMP0140 NEW) endif () #[==============================================================================================[ # Basic project definition # ]==============================================================================================] # TODO: CMake >= 3.19 can use string(JSON VERSION GET "${METADATA}" "version") to load from JSON set(PROJECT_VERSION 2.4.0) # TODO: Version 3, rename the project and namespace to something more compact project(nlohmann_json_schema_validator VERSION ${PROJECT_VERSION} DESCRIPTION "Json validator for nlohmann::json library" HOMEPAGE_URL "https://github.com/pboettch/json-schema-validator" LANGUAGES CXX) # TODO: Remove when bumping cmake >= 3.21 if (NOT DEFINED nlohmann_json_schema_validator_IS_TOP_LEVEL) if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) set(PROJECT_IS_TOP_LEVEL ON) else () set(PROJECT_IS_TOP_LEVEL OFF) endif () endif () #[==============================================================================================[ # Options # ]==============================================================================================] option(JSON_VALIDATOR_INSTALL "JsonValidator: Install targets" ${PROJECT_IS_TOP_LEVEL}) option(JSON_VALIDATOR_BUILD_TESTS "JsonValidator: Build tests" ${PROJECT_IS_TOP_LEVEL}) option(JSON_VALIDATOR_BUILD_EXAMPLES "JsonValidator: Build examples" ${PROJECT_IS_TOP_LEVEL}) option(JSON_VALIDATOR_SHARED_LIBS "JsonValidator: Build as shared library" ${PROJECT_IS_TOP_LEVEL}) option(JSON_VALIDATOR_TEST_COVERAGE "JsonValidator: Build with test coverage" OFF) mark_as_advanced(JSON_VALIDATOR_TEST_COVERAGE) # Get a default JSON_FETCH_VERSION from environment variables to workaround the CI if (DEFINED ENV{NLOHMANN_JSON_VERSION}) set(JSON_FETCH_VERSION_DEFAULT $ENV{NLOHMANN_JSON_VERSION}) else () set(JSON_FETCH_VERSION_DEFAULT v3.12.0) endif () set(JSON_FETCH_VERSION ${JSON_FETCH_VERSION_DEFAULT} CACHE STRING "Fetch nlohmann::json version") #[==============================================================================================[ # Project configuration # ]==============================================================================================] # Include cmake modules include(FetchContent) if (JSON_VALIDATOR_INSTALL) include(GNUInstallDirs) include(CMakePackageConfigHelpers) endif () # Default to release build if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif () # Enable cmake's BUILD_SHARED_LIBS set(BUILD_SHARED_LIBS ${nlohmann_json_schema_validator_SHARED_LIBS}) if (JSON_VALIDATOR_TEST_COVERAGE) if (CMAKE_CXX_COMPILER_ID STREQUAL Clang) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping") elseif (CMAKE_CXX_COMPILER_ID STREQUAL GNU) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") else () message(WARNING "JsonValidator: Other toolchain coverage flags unknown.\n" "Using --coverage as default") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") endif () endif () #[==============================================================================================[ # External packages # ]==============================================================================================] set(fetch_packages "") if (NOT TARGET nlohmann_json) # Fetch/Find nlohmann_json # TODO: Remove when bumping cmake >= 3.24 if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.24) FetchContent_Declare(nlohmann_json GIT_REPOSITORY https://github.com/nlohmann/json GIT_TAG ${JSON_FETCH_VERSION} FIND_PACKAGE_ARGS ) list(APPEND fetch_packages nlohmann_json) else () # Try to get system installed version find_package(nlohmann_json QUIET) if (NOT nlohmann_json_FOUND) # If failed fetch the desired version FetchContent_Declare(nlohmann_json GIT_REPOSITORY https://github.com/nlohmann/json GIT_TAG ${JSON_FETCH_VERSION} ) list(APPEND fetch_packages nlohmann_json) endif () endif () endif () # Handle configure flags if (JSON_VALIDATOR_INSTALL) # TODO: This is not ideal, this package should not be installing nlohmann::json # Currently required in order to satisfy cmake exporter set(JSON_Install ON CACHE BOOL "") endif () # Get all dependencies FetchContent_MakeAvailable(${fetch_packages}) if (JSON_VALIDATOR_INSTALL AND NOT nlohmann_json_FOUND AND JSON_Install) # TODO: This is not ideal message(WARNING "JsonValidator: No nlohmann::json found on the system and nlohmann_json_schema_validator will be installed\n" "This will also install nlohmann::json in its typical installation path\n" "This is not ideal because it might overwrite system installed") endif () #[==============================================================================================[ # Main definition # ]==============================================================================================] message(STATUS "JsonValidator: Configured for ${CMAKE_BUILD_TYPE}") if (DEFINED nlohmann_json_VERSION) message(STATUS "JsonValidator: Using nlohmann/json version: ${nlohmann_json_VERSION}") else () message(STATUS "JsonValidator: nlohmann_json_VERSION is not set. Possible value: ${JSON_FETCH_VERSION}") endif () ## Main targets add_library(nlohmann_json_schema_validator) add_library(nlohmann_json_schema_validator::validator ALIAS nlohmann_json_schema_validator) set_target_properties(nlohmann_json_schema_validator PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR} EXPORT_NAME validator # TODO: Version 3, simplify the library name # OUTPUT_NAME nlohmann_json_validator ) # Main definitions in here add_subdirectory(src) # Enable examples # Enable testings if (JSON_VALIDATOR_BUILD_TESTS) enable_testing() add_subdirectory(test) endif () if (JSON_VALIDATOR_BUILD_EXAMPLES) add_subdirectory(example) endif () #[==============================================================================================[ # Install or Export # ]==============================================================================================] if (JSON_VALIDATOR_INSTALL) # Note other install targets found in subdirectories # Here mostly the cmake boilerplate are set write_basic_package_version_file(nlohmann_json_schema_validatorConfigVersion.cmake VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion ) configure_package_config_file(cmake/nlohmann_json_schema_validatorConfig.cmake.in nlohmann_json_schema_validatorConfig.cmake INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/nlohmann_json_schema_validator ) # Install Targets files export(EXPORT nlohmann_json_schema_validatorTargets NAMESPACE nlohmann_json_schema_validator:: FILE nlohmann_json_schema_validatorTargets.cmake ) install(EXPORT nlohmann_json_schema_validatorTargets FILE nlohmann_json_schema_validatorTargets.cmake NAMESPACE nlohmann_json_schema_validator:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/nlohmann_json_schema_validator COMPONENT nlohmann_json_schema_validator_Development ) # Install cmake export files install(FILES ${CMAKE_CURRENT_BINARY_DIR}/nlohmann_json_schema_validatorConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/nlohmann_json_schema_validatorConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/nlohmann_json_schema_validator COMPONENT nlohmann_json_schema_validator_Development ) endif () # Handle the project being included externally (e.g. FetchContent) if (NOT PROJECT_IS_TOP_LEVEL) # Export variables set in nlohmann_json_schema_validatorConfig.cmake # TODO: Remove when bumping cmake >= 3.25 if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.25) return(PROPAGATE nlohmann_json_schema_validator_VERSION nlohmann_json_schema_validator_VERSION_MAJOR nlohmann_json_schema_validator_VERSION_MINOR nlohmann_json_schema_validator_VERSION_PATCH nlohmann_json_schema_validator_VERSION_TWEAK ) else () set(nlohmann_json_schema_validator_VERSION ${nlohmann_json_schema_validator_VERSION} PARENT_SCOPE) set(nlohmann_json_schema_validator_VERSION_MAJOR ${nlohmann_json_schema_validator_VERSION_MAJOR} PARENT_SCOPE) set(nlohmann_json_schema_validator_VERSION_MINOR ${nlohmann_json_schema_validator_VERSION_MINOR} PARENT_SCOPE) set(nlohmann_json_schema_validator_VERSION_PATCH ${nlohmann_json_schema_validator_VERSION_PATCH} PARENT_SCOPE) set(nlohmann_json_schema_validator_VERSION_TWEAK ${nlohmann_json_schema_validator_VERSION_TWEAK} PARENT_SCOPE) endif () endif () ================================================ FILE: CMakePresets.json ================================================ { "version": 6, "include": [ "cmake/CMakePresets-defaults.json", "cmake/CMakePresets-CI.json" ] } ================================================ FILE: ChangeLog.md ================================================ ## Release 2.4.0 - Added CI job to publish GitHub release by @JohanMabille in - Maintenance to Fedora CI infrastructure by @LecrisUT and @JohanMabille in - Reference validation using contains() result rather than exception handling by @BalrogOfHell in - add support for $defs instead of definitions by rpatters1 in - Apply clang-format / fix "test / Check pre-commit" failures by @serge-s in - Adding verbose error messages for logical combinations by Csaba Imre Zempleni in - fix: issue-311 by andrejlevkovitch - Fix cmake install target on windows by @barts-of in - error-messages: Numeric limit errors should show maximum precision by @pboettch - Add Fedora packaging by @LecrisUT in - Improve and fix bugs in Conanfile by Jacob Crabill ================================================ FILE: LICENSE ================================================ Modern C++ JSON schema validator is licensed under the MIT License : Copyright (c) 2016 Patrick Boettcher Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ [![Build Status](https://travis-ci.org/pboettch/json-schema-validator.svg?branch=master)](https://travis-ci.org/pboettch/json-schema-validator) # JSON schema validator for JSON for Modern C++ # What is it? This is a C++ library for validating JSON documents based on a [JSON Schema](http://json-schema.org/) which itself should validate with [draft-7 of JSON Schema Validation](http://json-schema.org/schema). First a disclaimer: *It is work in progress and contributions or hints or discussions are welcome.* Niels Lohmann et al develop a great JSON parser for C++ called [JSON for Modern C++](https://github.com/nlohmann/json). This validator is based on this library, hence the name. External documentation is missing as well. However the API of the validator is rather simple. # New in version 2 Although significant changes have been done for the 2nd version (a complete rewrite) the API is compatible with the 1.0.0 release. Except for the namespace which is now `nlohmann::json_schema`. Version **2** supports JSON schema draft 7, whereas 1 was supporting draft 4 only. Please update your schemas. The primary change in 2 is the way a schema is used. While in version 1 the schema was kept as a JSON-document and used again and again during validation, in version 2 the schema is parsed into compiled C++ objects which are then used during validation. There are surely still optimizations to be done, but validation speed has improved by factor 100 or more. # Design goals The main goal of this validator is to produce *human-comprehensible* error messages if a JSON-document/instance does not comply to its schema. By default this is done with exceptions thrown at the users with a helpful message telling what's wrong with the document while validating. Starting with **2.0.0** the user can pass a `json_schema::basic_error_handler`-derived object along with the instance to validate to receive a callback each time a validation error occurs and decide what to do (throwing, counting, collecting). Another goal was to use Niels Lohmann's JSON-library. This is why the validator lives in his namespace. # Thread-safety Instance validation is thread-safe and the same validator-object can be used by different threads: The validate method is `const` which indicates the object is not modified when being called: ```C++ json json_validator::validate(const json &) const; ``` Validator-object creation however is not thread-safe. A validator has to be created in one (main?) thread once. # Weaknesses Numerical validation uses nlohmann-json's integer, unsigned and floating point types, depending on if the schema type is "integer" or "number". Bignum (i.e. arbitrary precision and range) is not supported at this time. # Building This library is based on Niels Lohmann's JSON-library and thus has a build-dependency to it. Currently at least version **3.8.0** of NLohmann's JSON library is required. Various methods using CMake can be used to build this project. ## Build out-of-source Do not run cmake inside the source-dir. Rather create a dedicated build-dir: ```Bash git clone https://github.com/pboettch/json-schema-validator.git cd json-schema-validator mkdir build cd build cmake [..] make make install # if needed ctest # run unit, non-regression and test-suite tests ``` ## Building as shared library By default a static library is built. Shared libraries can be generated by using the `BUILD_SHARED_LIBS`-cmake variable: In your initial call to cmake simply add: ```bash cmake [..] -DBUILD_SHARED_LIBS=ON [..] ``` ## nlohmann-json integration As nlohmann-json is a dependency, this library tries find it. The cmake-configuration first checks if nlohmann-json is available as a cmake-target. This may be the case, because it is used as a submodule in a super-project which already provides and uses nlohmann-json. Otherwise, it calls `find_package` for nlohmann-json and requires nlohmann-json to be installed on the system. ### Building with Hunter package manager To enable access to nlohmann json library, Hunter can be used. Just run with `JSON_VALIDATOR_HUNTER=ON` option. No further dependencies needed ```bash cmake [..] -DJSON_VALIDATOR_HUNTER=ON [..] ``` ### Building as a CMake-subdirectory from within another project Adding this library as a subdirectory to a parent project is one way of building it. If the parent project already used `find_package()` to find the CMake-package of nlohmann_json or includes it as a submodule likewise. ### Building directly, finding a CMake-package. (short) When nlohmann-json has been installed, it provides files which allows CMake's `find_package()` to be used. This library is using this mechanism if `nlohmann_json::nlohmann_json`-target does not exist. ### Install Since version 2.1.0 this library can be installed and CMake-package-files will be created accordingly. If the installation of nlohmann-json and this library is done into default unix-system-paths CMake will be able to find this library by simply doing: ```CMake find_package(nlohmann_json_schema_validator REQUIRED) ``` and ```CMake target_link_libraries( [..] nlohmann_json_schema_validator) ``` to build and link. ## Code See also `app/json-schema-validate.cpp`. ```C++ #include #include #include using nlohmann::json; using nlohmann::json_schema::json_validator; // The schema is defined based upon a string literal static json person_schema = R"( { "$schema": "http://json-schema.org/draft-07/schema#", "title": "A person", "properties": { "name": { "description": "Name", "type": "string" }, "age": { "description": "Age of the person", "type": "number", "minimum": 2, "maximum": 200 } }, "required": [ "name", "age" ], "type": "object" } )"_json; // The people are defined with brace initialization static json bad_person = {{"age", 42}}; static json good_person = {{"name", "Albert"}, {"age", 42}}; int main() { /* json-parse the schema */ json_validator validator; // create validator try { validator.set_root_schema(person_schema); // insert root-schema } catch (const std::exception &e) { std::cerr << "Validation of schema failed, here is why: " << e.what() << "\n"; return EXIT_FAILURE; } /* json-parse the people - API of 1.0.0, default throwing error handler */ for (auto &person : {bad_person, good_person}) { std::cout << "About to validate this person:\n" << std::setw(2) << person << std::endl; try { validator.validate(person); // validate the document - uses the default throwing error-handler std::cout << "Validation succeeded\n"; } catch (const std::exception &e) { std::cerr << "Validation failed, here is why: " << e.what() << "\n"; } } /* json-parse the people - with custom error handler */ class custom_error_handler : public nlohmann::json_schema::basic_error_handler { void error(const nlohmann::json_pointer> &pointer, const json &instance, const std::string &message) override { nlohmann::json_schema::basic_error_handler::error(pointer, instance, message); std::cerr << "ERROR: '" << pointer << "' - '" << instance << "': " << message << "\n"; } }; for (auto &person : {bad_person, good_person}) { std::cout << "About to validate this person:\n" << std::setw(2) << person << std::endl; custom_error_handler err; validator.validate(person, err); // validate the document if (err) std::cerr << "Validation failed\n"; else std::cout << "Validation succeeded\n"; } return EXIT_SUCCESS; } ``` # Compliance There is an application which can be used for testing the validator with the [JSON-Schema-Test-Suite](https://github.com/json-schema-org/JSON-Schema-Test-Suite). In order to simplify the testing, the test-suite is included in the repository. If you have cloned this repository providing a path the repository-root via the cmake-variable `JSON_SCHEMA_TEST_SUITE_PATH` will enable the test-target(s). All required tests are **OK**. # Format Optionally JSON-schema-validator can validate predefined or user-defined formats. Therefore a format-checker-function can be provided by the user which is called by the validator when a format-check is required (ie. the schema contains a format-field). This is how the prototype looks like and how it can be passed to the validation-instance: ```C++ static void my_format_checker(const std::string &format, const std::string &value) { if (format == "something") { if (!check_value_for_something(value)) throw std::invalid_argument("value is not a good something"); } else throw std::logic_error("Don't know how to validate " + format); } // when creating the validator json_validator validator(nullptr, // or loader-callback my_format_checker); // create validator ``` ## Default Checker The library contains a default-checker, which does some checks. It needs to be provided manually to the constructor of the validator: ```C++ json_validator validator(loader, // or nullptr for no loader nlohmann::json_schema::default_string_format_check); ``` Supported formats: `date-time, date, time, email, hostname, ipv4, ipv6, uuid, regex` More formats can be added in `src/string-format-check.cpp`. Please contribute implementions for missing json schema draft formats. ## Default value processing As a result of the validation, the library returns a json patch including the default values of the specified schema. ```C++ #include #include using nlohmann::json; using nlohmann::json_schema::json_validator; static const json rectangle_schema = R"( { "$schema": "http://json-schema.org/draft-07/schema#", "title": "A rectangle", "properties": { "width": { "$ref": "#/definitions/length", "default": 20 }, "height": { "$ref": "#/definitions/length" } }, "definitions": { "length": { "type": "integer", "minimum": 1, "default": 10 } } })"_json; int main() { try { json_validator validator{rectangle_schema}; /* validate empty json -> will be expanded by the default values defined in the schema */ json rectangle = "{}"_json; const auto default_patch = validator.validate(rectangle); rectangle = rectangle.patch(default_patch); std::cout << rectangle.dump() << std::endl; // {"height":10,"width":20} } catch (const std::exception &e) { std::cerr << "Validation of schema failed: " << e.what() << "\n"; return EXIT_FAILURE; } return EXIT_SUCCESS; } ``` The example above will output the specified default values `{"height":10,"width":20}` to stdout. > Note that the default value specified in a `$ref` may be overridden by the current instance location. Also note that this behavior will break draft-7, but it is compliant to newer drafts (e.g. `2019-09` or `2020-12`). # Contributing This project uses [`pre-commit`](https://pre-commit.com/) to enforce style-checks. Please install and run it before creating commits and making pull requests. ```console $ pip install pre-commit $ pre-commit install ``` ================================================ FILE: cmake/CMakePresets-CI.json ================================================ { "version": 6, "include": [ "CMakePresets-defaults.json" ], "configurePresets": [ { "name": "ci-base", "hidden": true, "generator": "Ninja", "inherits": [ "default" ], "cacheVariables": { "CMAKE_BUILD_TYPE": { "type": "STRING", "value": "Debug" }, "JSON_VALIDATOR_BUILD_TESTS": { "type": "BOOL", "value": true }, "JSON_VALIDATOR_INSTALL": { "type": "BOOL", "value": false }, "JSON_BuildTests": { "type": "BOOL", "value": false } }, "errors": { "deprecated": true } }, { "name": "gcc-ci", "displayName": "Configure preset for GCC toolchain", "inherits": [ "ci-base" ], "binaryDir": "cmake-build-ci-gcc", "cacheVariables": { "CMAKE_CXX_COMPILER": { "type": "FILEPATH", "value": "g++" }, "CMAKE_LINKER": { "type": "FILEPATH", "value": "ld" } } }, { "name": "intel-ci", "displayName": "Configure preset for Intel toolchain", "inherits": [ "ci-base" ], "binaryDir": "cmake-build-ci-intel", "cacheVariables": { "CMAKE_CXX_COMPILER": { "type": "FILEPATH", "value": "icpx" } } }, { "name": "llvm-ci", "displayName": "Configure preset for LLVM toolchain", "inherits": [ "ci-base" ], "binaryDir": "cmake-build-ci-llvm", "cacheVariables": { "CMAKE_CXX_COMPILER": { "type": "FILEPATH", "value": "clang++" }, "CMAKE_LINKER": { "type": "FILEPATH", "value": "lld" } } }, { "name": "ci-coverage", "displayName": "Configure preset for test coverage", "inherits": [ "gcc-ci" ], "binaryDir": "cmake-build-ci-coverage", "errors": { "deprecated": false }, "cacheVariables": { "JSON_VALIDATOR_TEST_COVERAGE": { "type": "BOOL", "value": true } } }, { "name": "pre-commit", "displayName": "Configure preset for pre-commit checks", "inherits": [ "default" ], "binaryDir": "cmake-build-pre-commit", "cacheVariables": { "JSON_VALIDATOR_TEST_COVERAGE": { "type": "BOOL", "value": true }, "JSON_VALIDATOR_INSTALL": { "type": "BOOL", "value": false } } } ], "buildPresets": [ { "name": "ci-base", "hidden": true, "inherits": [ "default" ], "cleanFirst": true }, { "name": "ci-coverage", "displayName": "Build preset for test coverage", "inherits": [ "ci-base" ], "configurePreset": "ci-coverage" }, { "name": "gcc-ci", "displayName": "Build preset for GCC toolchain", "inherits": [ "ci-base" ], "configurePreset": "gcc-ci" }, { "name": "intel-ci", "displayName": "Build preset for Intel toolchain", "inherits": [ "ci-base" ], "configurePreset": "intel-ci" }, { "name": "llvm-ci", "displayName": "Build preset for LLVM toolchain", "inherits": [ "ci-base" ], "configurePreset": "llvm-ci" } ], "testPresets": [ { "name": "ci-base", "hidden": true, "inherits": [ "default" ], "output": { "outputOnFailure": true } }, { "name": "ci-coverage", "inherits": [ "default" ], "configurePreset": "ci-coverage" }, { "name": "gcc-ci", "displayName": "Test preset for GCC toolchain", "inherits": [ "ci-base" ], "configurePreset": "gcc-ci" }, { "name": "intel-ci", "displayName": "Test preset for Intel toolchain", "inherits": [ "ci-base" ], "configurePreset": "intel-ci" }, { "name": "llvm-ci", "displayName": "Test preset for LLVM toolchain", "inherits": [ "ci-base" ], "configurePreset": "llvm-ci" } ], "workflowPresets": [ { "name": "gcc-ci", "displayName": "CI test for GCC toolchain", "steps": [ { "type": "configure", "name": "gcc-ci" }, { "type": "build", "name": "gcc-ci" }, { "type": "test", "name": "gcc-ci" } ] }, { "name": "intel-ci", "displayName": "CI test for Intel toolchain", "steps": [ { "type": "configure", "name": "intel-ci" }, { "type": "build", "name": "intel-ci" }, { "type": "test", "name": "intel-ci" } ] }, { "name": "llvm-ci", "displayName": "CI test for LLVM toolchain", "steps": [ { "type": "configure", "name": "llvm-ci" }, { "type": "build", "name": "llvm-ci" }, { "type": "test", "name": "llvm-ci" } ] }, { "name": "ci-coverage", "displayName": "Coverage tests", "steps": [ { "type": "configure", "name": "ci-coverage" }, { "type": "build", "name": "ci-coverage" }, { "type": "test", "name": "ci-coverage" } ] } ] } ================================================ FILE: cmake/CMakePresets-defaults.json ================================================ { "version": 6, "configurePresets": [ { "name": "default", "displayName": "Default configuration preset", "binaryDir": "cmake-build-release", "cacheVariables": { "CMAKE_BUILD_TYPE": { "type": "STRING", "value": "Release" } } } ], "buildPresets": [ { "name": "default", "displayName": "Default build preset", "configurePreset": "default" } ], "testPresets": [ { "name": "default", "displayName": "Default test preset", "configurePreset": "default" } ], "workflowPresets": [ { "name": "default", "displayName": "Default workflow", "steps": [ { "type": "configure", "name": "default" }, { "type": "build", "name": "default" }, { "type": "test", "name": "default" } ] } ] } ================================================ FILE: cmake/nlohmann_json_schema_validatorConfig.cmake.in ================================================ @PACKAGE_INIT@ include(CMakeFindDependencyMacro) find_dependency(nlohmann_json) include("${CMAKE_CURRENT_LIST_DIR}/nlohmann_json_schema_validatorTargets.cmake") check_required_components( "nlohmann_json_schema_validator" ) ================================================ FILE: conanfile.py ================================================ import os import re from conan import ConanFile from conan.tools.cmake import cmake_layout, CMake, CMakeToolchain from conans.tools import load from conans import tools as ctools def get_version(): try: version = os.getenv('PROJECT_VERSION', None) if version: return version content = load('CMakeLists.txt') version = re.search('set\(PROJECT_VERSION (.*)\)', content).group(1) return version.strip() except: return None class JsonSchemaValidatorConan(ConanFile): name = 'JsonSchemaValidator' version = get_version() url = 'https://github.com/pboettch/json-schema-validator' license = 'MIT' settings = 'os', 'compiler', 'build_type', 'arch' options = { 'shared': [True, False], 'fPIC': [True, False], 'build_examples': [True, False], 'build_tests': [True, False], 'test_coverage': [True, False], } default_options = { 'shared': False, 'fPIC': True, 'build_examples': True, 'build_tests': False, 'test_coverage': False, } generators = 'CMakeDeps', 'CMakeToolchain', 'VirtualBuildEnv', 'VirtualRunEnv' exports_sources = [ 'CMakeLists.txt', 'conanfile.py', 'cmake/*', 'src/*', 'example/*', 'test/*', ] requires = [ 'nlohmann_json/3.11.2' ] def generate(self): tc = CMakeToolchain(self) tc.variables['JSON_VALIDATOR_BUILD_EXAMPLES'] = self.options.build_examples tc.variables['JSON_VALIDATOR_BUILD_TESTS'] = self.options.build_tests tc.variables['JSON_VALIDATOR_SHARED_LIBS '] = self.options.shared tc.variables['JSON_VALIDATOR_TEST_COVERAGE '] = self.options.test_coverage tc.generate() def layout(self): cmake_layout(self) def build(self): cmake = CMake(self) cmake.configure() cmake.verbose = True cmake.build() def package(self): cmake = CMake(self) cmake.install() def package_info(self): includedir = os.path.join(self.package_folder, "include") self.cpp_info.includedirs = [includedir] libdir = os.path.join(self.package_folder, "lib") self.cpp_info.libdirs = [libdir] self.cpp_info.libs += ctools.collect_libs(self, libdir) bindir = os.path.join(self.package_folder, "bin") self.output.info("Appending PATH environment variable: {}".format(bindir)) self.env_info.PATH.append(bindir) self.user_info.VERSION = self.version ================================================ FILE: example/CMakeLists.txt ================================================ add_executable(readme-json-schema readme.cpp) target_link_libraries(readme-json-schema nlohmann_json_schema_validator) add_executable(format-json-schema format.cpp) target_link_libraries(format-json-schema nlohmann_json_schema_validator) if (JSON_VALIDATOR_INSTALL) install(TARGETS readme-json-schema format-json-schema DESTINATION ${CMAKE_INSTALL_BINDIR}) endif () ================================================ FILE: example/format.cpp ================================================ #include #include using nlohmann::json; using nlohmann::json_schema::json_validator; // The schema is defined based upon a string literal static json uri_schema = R"( { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "properties": { "myUri": { "type":"string", "format": "uri" } } })"_json; // The people are defined with brace initialization static json good_uri = {{"myUri", "http://hostname.com/"}}; static json bad_uri = {{"myUri", "http:/hostname.com/"}}; static void uri_format_checker(const std::string &format, const std::string &value) { if (format == "uri") { if (value.find("://") == std::string::npos) throw std::invalid_argument("URI does not contain :// - invalid"); } else throw std::logic_error("Don't know how to validate " + format); } int main() { json_validator validator(nullptr, uri_format_checker); // create validator try { validator.set_root_schema(uri_schema); // insert root-schema } catch (const std::exception &e) { std::cerr << "Validation of schema failed, here is why: " << e.what() << "\n"; return EXIT_FAILURE; } validator.validate(good_uri); try { validator.validate(bad_uri); } catch (const std::exception &e) { std::cerr << "Validation expectedly failed, here is why: " << e.what() << "\n"; } return EXIT_SUCCESS; } ================================================ FILE: example/readme.cpp ================================================ #include #include #include using nlohmann::json; using nlohmann::json_schema::json_validator; // The schema is defined based upon a string literal static json person_schema = R"( { "$schema": "http://json-schema.org/draft-07/schema#", "title": "A person", "properties": { "name": { "description": "Name", "type": "string" }, "age": { "description": "Age of the person", "type": "number", "minimum": 2, "maximum": 200 }, "address":{ "type": "object", "properties":{ "street":{ "type": "string", "default": "Abbey Road" } } } }, "required": [ "name", "age" ], "type": "object" } )"_json; // The people are defined with brace initialization static json bad_person = {{"age", 42}}; static json good_person = {{"name", "Albert"}, {"age", 42}, {"address", {{"street", "Main Street"}}}}; static json good_defaulted_person = {{"name", "Knut"}, {"age", 69}, {"address", {}}}; int main() { /* json-parse the schema */ json_validator validator; // create validator try { validator.set_root_schema(person_schema); // insert root-schema } catch (const std::exception &e) { std::cerr << "Validation of schema failed, here is why: " << e.what() << "\n"; return EXIT_FAILURE; } /* json-parse the people - API of 1.0.0, default throwing error handler */ for (auto &person : {bad_person, good_person, good_defaulted_person}) { std::cout << "About to validate this person:\n" << std::setw(2) << person << std::endl; try { auto defaultPatch = validator.validate(person); // validate the document - uses the default throwing error-handler std::cout << "Validation succeeded\n"; std::cout << "Patch with defaults: " << defaultPatch.dump(2) << std::endl; } catch (const std::exception &e) { std::cerr << "Validation failed, here is why: " << e.what() << "\n"; } } /* json-parse the people - with custom error handler */ class custom_error_handler : public nlohmann::json_schema::basic_error_handler { void error(const nlohmann::json::json_pointer &ptr, const json &instance, const std::string &message) override { nlohmann::json_schema::basic_error_handler::error(ptr, instance, message); std::cerr << "ERROR: '" << ptr << "' - '" << instance << "': " << message << "\n"; } }; for (auto &person : {bad_person, good_person}) { std::cout << "About to validate this person:\n" << std::setw(2) << person << std::endl; custom_error_handler err; validator.validate(person, err); // validate the document if (err) std::cerr << "Validation failed\n"; else std::cout << "Validation succeeded\n"; } return EXIT_SUCCESS; } ================================================ FILE: schema ================================================ { "$schema": "http://json-schema.org/draft-07/schema#", "$id": "http://json-schema.org/draft-07/schema#", "title": "Core schema meta-schema", "definitions": { "schemaArray": { "type": "array", "minItems": 1, "items": { "$ref": "#" } }, "nonNegativeInteger": { "type": "integer", "minimum": 0 }, "nonNegativeIntegerDefault0": { "allOf": [ { "$ref": "#/definitions/nonNegativeInteger" }, { "default": 0 } ] }, "simpleTypes": { "enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ] }, "stringArray": { "type": "array", "items": { "type": "string" }, "uniqueItems": true, "default": [] } }, "type": ["object", "boolean"], "properties": { "$id": { "type": "string", "format": "uri-reference" }, "$schema": { "type": "string", "format": "uri" }, "$ref": { "type": "string", "format": "uri-reference" }, "$comment": { "type": "string" }, "title": { "type": "string" }, "description": { "type": "string" }, "default": true, "readOnly": { "type": "boolean", "default": false }, "examples": { "type": "array", "items": true }, "multipleOf": { "type": "number", "exclusiveMinimum": 0 }, "maximum": { "type": "number" }, "exclusiveMaximum": { "type": "number" }, "minimum": { "type": "number" }, "exclusiveMinimum": { "type": "number" }, "maxLength": { "$ref": "#/definitions/nonNegativeInteger" }, "minLength": { "$ref": "#/definitions/nonNegativeIntegerDefault0" }, "pattern": { "type": "string", "format": "regex" }, "additionalItems": { "$ref": "#" }, "items": { "anyOf": [ { "$ref": "#" }, { "$ref": "#/definitions/schemaArray" } ], "default": true }, "maxItems": { "$ref": "#/definitions/nonNegativeInteger" }, "minItems": { "$ref": "#/definitions/nonNegativeIntegerDefault0" }, "uniqueItems": { "type": "boolean", "default": false }, "contains": { "$ref": "#" }, "maxProperties": { "$ref": "#/definitions/nonNegativeInteger" }, "minProperties": { "$ref": "#/definitions/nonNegativeIntegerDefault0" }, "required": { "$ref": "#/definitions/stringArray" }, "additionalProperties": { "$ref": "#" }, "definitions": { "type": "object", "additionalProperties": { "$ref": "#" }, "default": {} }, "properties": { "type": "object", "additionalProperties": { "$ref": "#" }, "default": {} }, "patternProperties": { "type": "object", "additionalProperties": { "$ref": "#" }, "propertyNames": { "format": "regex" }, "default": {} }, "dependencies": { "type": "object", "additionalProperties": { "anyOf": [ { "$ref": "#" }, { "$ref": "#/definitions/stringArray" } ] } }, "propertyNames": { "$ref": "#" }, "const": true, "enum": { "type": "array", "items": true, "minItems": 1, "uniqueItems": true }, "type": { "anyOf": [ { "$ref": "#/definitions/simpleTypes" }, { "type": "array", "items": { "$ref": "#/definitions/simpleTypes" }, "minItems": 1, "uniqueItems": true } ] }, "format": { "type": "string" }, "contentMediaType": { "type": "string" }, "contentEncoding": { "type": "string" }, "if": {"$ref": "#"}, "then": {"$ref": "#"}, "else": {"$ref": "#"}, "allOf": { "$ref": "#/definitions/schemaArray" }, "anyOf": { "$ref": "#/definitions/schemaArray" }, "oneOf": { "$ref": "#/definitions/schemaArray" }, "not": { "$ref": "#" } }, "default": true } ================================================ FILE: src/CMakeLists.txt ================================================ target_sources(nlohmann_json_schema_validator PRIVATE smtp-address-validator.cpp json-schema-draft7.json.cpp json-uri.cpp json-validator.cpp json-patch.cpp string-format-check.cpp ) target_include_directories(nlohmann_json_schema_validator PUBLIC $ $ ) set_target_properties(nlohmann_json_schema_validator PROPERTIES PUBLIC_HEADER nlohmann/json-schema.hpp) # TODO: Why would this need to be if guarded? if (JSON_VALIDATOR_SHARED_LIBS) target_compile_definitions(nlohmann_json_schema_validator PRIVATE -DJSON_SCHEMA_VALIDATOR_EXPORTS) endif () # TODO: Consider setting minimum cxx standard instead target_compile_features(nlohmann_json_schema_validator PUBLIC cxx_range_for) # for C++11 - flags # TODO: This should be handled by the CI/presets, not the cmake if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") target_compile_options(nlohmann_json_schema_validator PRIVATE -Wall -Wextra -Wshadow) endif () # TODO: gcc support for <4.9 should be removed # regex with boost if gcc < 4.9 - default is std::regex if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9.0") find_package(Boost COMPONENTS regex) if (NOT Boost_FOUND) message(STATUS "GCC less then 4.9 and boost-regex NOT found - no regex used") target_compile_definitions(nlohmann_json_schema_validator PRIVATE -DJSON_SCHEMA_NO_REGEX) else () message(STATUS "GCC less then 4.9 and boost-regex FOUND - using boost::regex") target_compile_definitions(nlohmann_json_schema_validator PRIVATE -DJSON_SCHEMA_BOOST_REGEX) target_include_directories(nlohmann_json_schema_validator PRIVATE ${Boost_INCLUDE_DIRS}) target_link_libraries(nlohmann_json_schema_validator PRIVATE ${Boost_LIBRARIES}) endif () endif () endif () target_link_libraries(nlohmann_json_schema_validator PUBLIC nlohmann_json::nlohmann_json) if (JSON_VALIDATOR_INSTALL) # Normal installation target to system. When using scikit-build check python subdirectory install(TARGETS nlohmann_json_schema_validator EXPORT nlohmann_json_schema_validatorTargets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT nlohmann_json_schema_validator_Runtime NAMELINK_COMPONENT nlohmann_json_schema_validator_Development ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT nlohmann_json_schema_validator_Development PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/nlohmann COMPONENT nlohmann_json_schema_validator_Development RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT nlohmann_json_schema_validator_Runtime) endif () ================================================ FILE: src/json-patch.cpp ================================================ #include "json-patch.hpp" #include namespace { // originally from http://jsonpatch.com/, http://json.schemastore.org/json-patch // with fixes const nlohmann::json patch_schema = R"patch({ "title": "JSON schema for JSONPatch files", "$schema": "http://json-schema.org/draft-04/schema#", "type": "array", "items": { "oneOf": [ { "additionalProperties": false, "required": [ "value", "op", "path"], "properties": { "path" : { "$ref": "#/definitions/path" }, "op": { "description": "The operation to perform.", "type": "string", "enum": [ "add", "replace", "test" ] }, "value": { "description": "The value to add, replace or test." } } }, { "additionalProperties": false, "required": [ "op", "path"], "properties": { "path" : { "$ref": "#/definitions/path" }, "op": { "description": "The operation to perform.", "type": "string", "enum": [ "remove" ] } } }, { "additionalProperties": false, "required": [ "from", "op", "path" ], "properties": { "path" : { "$ref": "#/definitions/path" }, "op": { "description": "The operation to perform.", "type": "string", "enum": [ "move", "copy" ] }, "from": { "$ref": "#/definitions/path", "description": "A JSON Pointer path pointing to the location to move/copy from." } } } ] }, "definitions": { "path": { "description": "A JSON Pointer path.", "type": "string" } } })patch"_json; } // namespace namespace nlohmann { json_patch::json_patch(json &&patch) : j_(std::move(patch)) { validateJsonPatch(j_); } json_patch::json_patch(const json &patch) : j_(std::move(patch)) { validateJsonPatch(j_); } json_patch &json_patch::add(const json::json_pointer &ptr, json value) { j_.push_back(json{{"op", "add"}, {"path", ptr.to_string()}, {"value", std::move(value)}}); return *this; } json_patch &json_patch::replace(const json::json_pointer &ptr, json value) { j_.push_back(json{{"op", "replace"}, {"path", ptr.to_string()}, {"value", std::move(value)}}); return *this; } json_patch &json_patch::remove(const json::json_pointer &ptr) { j_.push_back(json{{"op", "remove"}, {"path", ptr.to_string()}}); return *this; } void json_patch::validateJsonPatch(json const &patch) { // static put here to have it created at the first usage of validateJsonPatch static nlohmann::json_schema::json_validator patch_validator(patch_schema); patch_validator.validate(patch); for (auto const &op : patch) json::json_pointer(op["path"].get()); } } // namespace nlohmann ================================================ FILE: src/json-patch.hpp ================================================ #pragma once #include #include namespace nlohmann { class JsonPatchFormatException : public std::exception { public: explicit JsonPatchFormatException(std::string msg) : ex_{std::move(msg)} {} inline const char *what() const noexcept override final { return ex_.c_str(); } private: std::string ex_; }; class json_patch { public: json_patch() = default; json_patch(json &&patch); json_patch(const json &patch); json_patch &add(const json::json_pointer &, json value); json_patch &replace(const json::json_pointer &, json value); json_patch &remove(const json::json_pointer &); json &get_json() { return j_; } const json &get_json() const { return j_; } operator json() const { return j_; } private: json j_ = nlohmann::json::array(); static void validateJsonPatch(json const &patch); }; } // namespace nlohmann ================================================ FILE: src/json-schema-draft7.json.cpp ================================================ /* * JSON schema validator for JSON for modern C++ * * Copyright (c) 2016-2019 Patrick Boettcher . * * SPDX-License-Identifier: MIT * */ #include namespace nlohmann { namespace json_schema { json draft7_schema_builtin = R"( { "$schema": "http://json-schema.org/draft-07/schema#", "$id": "http://json-schema.org/draft-07/schema#", "title": "Core schema meta-schema", "definitions": { "schemaArray": { "type": "array", "minItems": 1, "items": { "$ref": "#" } }, "nonNegativeInteger": { "type": "integer", "minimum": 0 }, "nonNegativeIntegerDefault0": { "allOf": [ { "$ref": "#/definitions/nonNegativeInteger" }, { "default": 0 } ] }, "simpleTypes": { "enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ] }, "stringArray": { "type": "array", "items": { "type": "string" }, "uniqueItems": true, "default": [] } }, "type": ["object", "boolean"], "properties": { "$id": { "type": "string", "format": "uri-reference" }, "$schema": { "type": "string", "format": "uri" }, "$ref": { "type": "string", "format": "uri-reference" }, "$comment": { "type": "string" }, "title": { "type": "string" }, "description": { "type": "string" }, "default": true, "readOnly": { "type": "boolean", "default": false }, "examples": { "type": "array", "items": true }, "multipleOf": { "type": "number", "exclusiveMinimum": 0 }, "maximum": { "type": "number" }, "exclusiveMaximum": { "type": "number" }, "minimum": { "type": "number" }, "exclusiveMinimum": { "type": "number" }, "maxLength": { "$ref": "#/definitions/nonNegativeInteger" }, "minLength": { "$ref": "#/definitions/nonNegativeIntegerDefault0" }, "pattern": { "type": "string", "format": "regex" }, "additionalItems": { "$ref": "#" }, "items": { "anyOf": [ { "$ref": "#" }, { "$ref": "#/definitions/schemaArray" } ], "default": true }, "maxItems": { "$ref": "#/definitions/nonNegativeInteger" }, "minItems": { "$ref": "#/definitions/nonNegativeIntegerDefault0" }, "uniqueItems": { "type": "boolean", "default": false }, "contains": { "$ref": "#" }, "maxProperties": { "$ref": "#/definitions/nonNegativeInteger" }, "minProperties": { "$ref": "#/definitions/nonNegativeIntegerDefault0" }, "required": { "$ref": "#/definitions/stringArray" }, "additionalProperties": { "$ref": "#" }, "definitions": { "type": "object", "additionalProperties": { "$ref": "#" }, "default": {} }, "properties": { "type": "object", "additionalProperties": { "$ref": "#" }, "default": {} }, "patternProperties": { "type": "object", "additionalProperties": { "$ref": "#" }, "propertyNames": { "format": "regex" }, "default": {} }, "dependencies": { "type": "object", "additionalProperties": { "anyOf": [ { "$ref": "#" }, { "$ref": "#/definitions/stringArray" } ] } }, "propertyNames": { "$ref": "#" }, "const": true, "enum": { "type": "array", "items": true, "minItems": 1, "uniqueItems": true }, "type": { "anyOf": [ { "$ref": "#/definitions/simpleTypes" }, { "type": "array", "items": { "$ref": "#/definitions/simpleTypes" }, "minItems": 1, "uniqueItems": true } ] }, "format": { "type": "string" }, "contentMediaType": { "type": "string" }, "contentEncoding": { "type": "string" }, "if": { "$ref": "#" }, "then": { "$ref": "#" }, "else": { "$ref": "#" }, "allOf": { "$ref": "#/definitions/schemaArray" }, "anyOf": { "$ref": "#/definitions/schemaArray" }, "oneOf": { "$ref": "#/definitions/schemaArray" }, "not": { "$ref": "#" } }, "default": true } )"_json; } } // namespace nlohmann ================================================ FILE: src/json-uri.cpp ================================================ /* * JSON schema validator for JSON for modern C++ * * Copyright (c) 2016-2019 Patrick Boettcher . * * SPDX-License-Identifier: MIT * */ #include #include namespace nlohmann { void json_uri::update(const std::string &uri) { std::string pointer = ""; // default pointer is document-root // first split the URI into location and pointer auto pointer_separator = uri.find('#'); if (pointer_separator != std::string::npos) { // and extract the pointer-string if found pointer = uri.substr(pointer_separator + 1); // remove # // unescape %-values IOW, decode JSON-URI-formatted JSON-pointer std::size_t pos = pointer.size() - 1; do { pos = pointer.rfind('%', pos); if (pos == std::string::npos) break; if (pos >= pointer.size() - 2) { pos--; continue; } std::string hex = pointer.substr(pos + 1, 2); char ascii = static_cast(std::strtoul(hex.c_str(), nullptr, 16)); pointer.replace(pos, 3, 1, ascii); pos--; } while (1); } auto location = uri.substr(0, pointer_separator); if (location.size()) { // a location part has been found // if it is an URN take it as it is if (location.find("urn:") == 0) { urn_ = location; // and clear URL members scheme_ = ""; authority_ = ""; path_ = ""; } else { // it is an URL // split URL in protocol, hostname and path std::size_t pos = 0; auto proto = location.find("://", pos); if (proto != std::string::npos) { // extract the protocol urn_ = ""; // clear URN-member if URL is parsed scheme_ = location.substr(pos, proto - pos); pos = 3 + proto; // 3 == "://" auto authority = location.find("/", pos); if (authority != std::string::npos) { // and the hostname (no proto without hostname) authority_ = location.substr(pos, authority - pos); pos = authority; } } auto path = location.substr(pos); // URNs cannot of have paths if (urn_.size() && path.size()) throw std::invalid_argument("Cannot add a path (" + path + ") to an URN URI (" + urn_ + ")"); if (path[0] == '/') // if it starts with a / it is root-path path_ = path; else if (pos == 0) { // the URL contained only a path and the current path has no / at the end, strip last element until / and append auto last_slash = path_.rfind('/'); path_ = path_.substr(0, last_slash) + '/' + path; } else // otherwise it is a subfolder path_.append(path); } } pointer_ = ""_json_pointer; identifier_ = ""; if (pointer[0] == '/') pointer_ = json::json_pointer(pointer); else identifier_ = pointer; } std::string json_uri::location() const { if (urn_.size()) return urn_; std::stringstream s; if (scheme_.size() > 0) s << scheme_ << "://"; s << authority_ << path_; return s.str(); } std::string json_uri::to_string() const { std::stringstream s; s << location() << " # "; if (identifier_ == "") s << pointer_.to_string(); else s << identifier_; return s.str(); } std::ostream &operator<<(std::ostream &os, const json_uri &u) { return os << u.to_string(); } std::string json_uri::escape(const std::string &src) { std::vector> chars = { {"~", "~0"}, {"/", "~1"}}; std::string l = src; for (const auto &c : chars) { std::size_t pos = 0; do { pos = l.find(c.first, pos); if (pos == std::string::npos) break; l.replace(pos, 1, c.second); pos += c.second.size(); } while (1); } return l; } } // namespace nlohmann ================================================ FILE: src/json-validator.cpp ================================================ /* * JSON schema validator for JSON for modern C++ * * Copyright (c) 2016-2019 Patrick Boettcher . * * SPDX-License-Identifier: MIT * */ #include #include "json-patch.hpp" #include #include #include #include #include using nlohmann::json; using nlohmann::json_patch; using nlohmann::json_uri; using nlohmann::json_schema::root_schema; using namespace nlohmann::json_schema; #ifdef JSON_SCHEMA_BOOST_REGEX # include # define REGEX_NAMESPACE boost #elif defined(JSON_SCHEMA_NO_REGEX) # define NO_STD_REGEX #else # include # define REGEX_NAMESPACE std #endif namespace { class schema { protected: root_schema *root_; json default_value_ = nullptr; protected: virtual std::shared_ptr make_for_default_( std::shared_ptr<::schema> & /* sch */, root_schema * /* root */, std::vector & /* uris */, nlohmann::json & /* default_value */) const { return nullptr; }; public: virtual ~schema() = default; schema(root_schema *root) : root_(root) {} virtual void validate(const json::json_pointer &ptr, const json &instance, json_patch &patch, error_handler &e) const = 0; virtual const json &default_value(const json::json_pointer &, const json &, error_handler &) const { return default_value_; } void set_default_value(const json &v) { default_value_ = v; } static std::shared_ptr make(json &schema, root_schema *root, const std::vector &key, std::vector uris); }; class schema_ref : public schema { const std::string id_; std::weak_ptr target_; std::shared_ptr target_strong_; // for references to references keep also the shared_ptr because // no one else might use it after resolving void validate(const json::json_pointer &ptr, const json &instance, json_patch &patch, error_handler &e) const final { auto target = target_.lock(); if (target) target->validate(ptr, instance, patch, e); else e.error(ptr, instance, "unresolved or freed schema-reference " + id_); } const json &default_value(const json::json_pointer &ptr, const json &instance, error_handler &e) const override final { if (!default_value_.is_null()) return default_value_; auto target = target_.lock(); if (target) return target->default_value(ptr, instance, e); e.error(ptr, instance, "unresolved or freed schema-reference " + id_); return default_value_; } protected: virtual std::shared_ptr make_for_default_( std::shared_ptr<::schema> &sch, root_schema *root, std::vector &uris, nlohmann::json &default_value) const override { // create a new reference schema using the original reference (which will be resolved later) // to store this overloaded default value #209 auto result = std::make_shared(uris[0].to_string(), root); result->set_target(sch, true); result->set_default_value(default_value); return result; }; public: schema_ref(const std::string &id, root_schema *root) : schema(root), id_(id) {} const std::string &id() const { return id_; } void set_target(const std::shared_ptr &target, bool strong = false) { target_ = target; if (strong) target_strong_ = target; } }; } // namespace namespace nlohmann { namespace json_schema { class root_schema { schema_loader loader_; format_checker format_check_; content_checker content_check_; std::shared_ptr root_; struct schema_file { std::map> schemas; std::map> unresolved; // contains all unresolved references from any other file seen during parsing json unknown_keywords; }; // location as key std::map files_; schema_file &get_or_create_file(const std::string &loc) { auto file = files_.lower_bound(loc); if (file != files_.end() && !(files_.key_comp()(loc, file->first))) return file->second; else return files_.insert(file, {loc, {}})->second; } public: root_schema(schema_loader &&loader, format_checker &&format, content_checker &&content) : loader_(std::move(loader)), format_check_(std::move(format)), content_check_(std::move(content)) { } format_checker &format_check() { return format_check_; } content_checker &content_check() { return content_check_; } void insert(const json_uri &uri, const std::shared_ptr &s) { auto &file = get_or_create_file(uri.location()); auto sch = file.schemas.lower_bound(uri.fragment()); if (sch != file.schemas.end() && !(file.schemas.key_comp()(uri.fragment(), sch->first))) { throw std::invalid_argument("schema with " + uri.to_string() + " already inserted"); return; } file.schemas.insert({uri.fragment(), s}); // was someone referencing this newly inserted schema? auto unresolved = file.unresolved.find(uri.fragment()); if (unresolved != file.unresolved.end()) { unresolved->second->set_target(s); file.unresolved.erase(unresolved); } } void insert_unknown_keyword(const json_uri &uri, const std::string &key, json &value) { auto &file = get_or_create_file(uri.location()); auto new_uri = uri.append(key); auto fragment = new_uri.pointer(); // is there a reference looking for this unknown-keyword, which is thus no longer a unknown keyword but a schema auto unresolved = file.unresolved.find(fragment.to_string()); if (unresolved != file.unresolved.end()) schema::make(value, this, {}, {{new_uri}}); else { // no, nothing ref'd it, keep for later // need to create an object for each reference-token in the // JSON-Pointer When not existing, a stringified integer reference // token (e.g. "123") in the middle of the pointer will be // interpreted a an array-index and an array will be created. // json_pointer's reference_tokens is private - get them std::deque ref_tokens; auto uri_pointer = uri.pointer(); while (!uri_pointer.empty()) { ref_tokens.push_front(uri_pointer.back()); uri_pointer.pop_back(); } // for each token create an object, if not already existing auto unk_kw = &file.unknown_keywords; for (auto &rt : ref_tokens) { // create a json_pointer from rt as rt can be an stringified integer doing find on an array won't work json::json_pointer rt_ptr{"/" + rt}; if (unk_kw->contains(rt_ptr) == false) (*unk_kw)[rt] = json::object(); unk_kw = &(*unk_kw)[rt_ptr]; } (*unk_kw)[key] = value; } // recursively add possible subschemas of unknown keywords if (value.type() == json::value_t::object) for (auto &subsch : value.items()) insert_unknown_keyword(new_uri, subsch.key(), subsch.value()); } std::shared_ptr get_or_create_ref(const json_uri &uri) { auto &file = get_or_create_file(uri.location()); // existing schema auto sch = file.schemas.find(uri.fragment()); if (sch != file.schemas.end()) return sch->second; // referencing an unknown keyword, turn it into schema // // an unknown keyword can only be referenced by a json-pointer, // not by a plain name fragment if (!uri.pointer().to_string().empty()) { bool contains_pointer = file.unknown_keywords.contains(uri.pointer()); if (contains_pointer) { auto &subschema = file.unknown_keywords.at(uri.pointer()); auto s = schema::make(subschema, this, {}, {{uri}}); if (s) { // if schema is valid (non-null) file.unknown_keywords.erase(uri.fragment()); return s; } } } // get or create a schema_ref auto r = file.unresolved.lower_bound(uri.fragment()); if (r != file.unresolved.end() && !(file.unresolved.key_comp()(uri.fragment(), r->first))) { return r->second; // unresolved, already seen previously - use existing reference } else { return file.unresolved.insert(r, {uri.fragment(), std::make_shared(uri.to_string(), this)}) ->second; // unresolved, create reference } } void set_root_schema(json sch) { files_.clear(); root_ = schema::make(sch, this, {}, {{"#"}}); // load all files which have not yet been loaded do { bool new_schema_loaded = false; // files_ is modified during parsing, iterators are invalidated std::vector locations; for (auto &file : files_) locations.push_back(file.first); for (auto &loc : locations) { if (files_[loc].schemas.size() == 0) { // nothing has been loaded for this file if (loader_) { json loaded_schema; loader_(loc, loaded_schema); schema::make(loaded_schema, this, {}, {{loc}}); new_schema_loaded = true; } else { throw std::invalid_argument("external schema reference '" + loc + "' needs loading, but no loader callback given"); } } } if (!new_schema_loaded) // if no new schema loaded, no need to try again break; } while (1); for (const auto &file : files_) { if (file.second.unresolved.size() != 0) { // Build a representation of the undefined // references as a list of comma-separated strings. auto n_urefs = file.second.unresolved.size(); std::string urefs = "["; decltype(n_urefs) counter = 0; for (const auto &p : file.second.unresolved) { urefs += p.first; if (counter != n_urefs - 1u) { urefs += ", "; } ++counter; } urefs += "]"; throw std::invalid_argument("after all files have been parsed, '" + (file.first == "" ? "" : file.first) + "' has still the following undefined references: " + urefs); } } } void validate(const json::json_pointer &ptr, const json &instance, json_patch &patch, error_handler &e, const json_uri &initial) const { if (!root_) { e.error(ptr, "", "no root schema has yet been set for validating an instance"); return; } auto file_entry = files_.find(initial.location()); if (file_entry == files_.end()) { e.error(ptr, "", "no file found serving requested root-URI. " + initial.location()); return; } auto &file = file_entry->second; auto sch = file.schemas.find(initial.fragment()); if (sch == file.schemas.end()) { e.error(ptr, "", "no schema find for request initial URI: " + initial.to_string()); return; } sch->second->validate(ptr, instance, patch, e); } }; } // namespace json_schema } // namespace nlohmann namespace { class first_error_handler : public error_handler { public: bool error_{false}; json::json_pointer ptr_; json instance_; std::string message_; void error(const json::json_pointer &ptr, const json &instance, const std::string &message) override { if (*this) return; error_ = true; ptr_ = ptr; instance_ = instance; message_ = message; } operator bool() const { return error_; } }; class logical_not : public schema { std::shared_ptr subschema_; void validate(const json::json_pointer &ptr, const json &instance, json_patch &patch, error_handler &e) const final { first_error_handler esub; subschema_->validate(ptr, instance, patch, esub); if (!esub) e.error(ptr, instance, "the subschema has succeeded, but it is required to not validate"); } const json &default_value(const json::json_pointer &ptr, const json &instance, error_handler &e) const override { return subschema_->default_value(ptr, instance, e); } public: logical_not(json &sch, root_schema *root, const std::vector &uris) : schema(root) { subschema_ = schema::make(sch, root, {"not"}, uris); } }; enum logical_combination_types { allOf, anyOf, oneOf }; class logical_combination_error_handler : public error_handler { public: struct error_entry { json::json_pointer ptr_; json instance_; std::string message_; }; std::vector error_entry_list_; void error(const json::json_pointer &ptr, const json &instance, const std::string &message) override { error_entry_list_.push_back(error_entry{ptr, instance, message}); } void propagate(error_handler &e, const std::string &prefix) const { for (const error_entry &entry : error_entry_list_) e.error(entry.ptr_, entry.instance_, prefix + entry.message_); } operator bool() const { return !error_entry_list_.empty(); } }; template class logical_combination : public schema { std::vector> subschemata_; void validate(const json::json_pointer &ptr, const json &instance, json_patch &patch, error_handler &e) const final { size_t count = 0; logical_combination_error_handler error_summary; for (std::size_t index = 0; index < subschemata_.size(); ++index) { const std::shared_ptr &s = subschemata_[index]; logical_combination_error_handler esub; auto oldPatchSize = patch.get_json().size(); s->validate(ptr, instance, patch, esub); if (!esub) count++; else { patch.get_json().get_ref().resize(oldPatchSize); esub.propagate(error_summary, "case#" + std::to_string(index) + "] "); } if (is_validate_complete(instance, ptr, e, esub, count, index)) return; } if (count == 0) { e.error(ptr, instance, "no subschema has succeeded, but one of them is required to validate. Type: " + key + ", number of failed subschemas: " + std::to_string(subschemata_.size())); error_summary.propagate(e, "[combination: " + key + " / "); } } // specialized for each of the logical_combination_types static const std::string key; static bool is_validate_complete(const json &, const json::json_pointer &, error_handler &, const logical_combination_error_handler &, size_t, size_t); public: logical_combination(json &sch, root_schema *root, const std::vector &uris) : schema(root) { size_t c = 0; for (auto &subschema : sch) subschemata_.push_back(schema::make(subschema, root, {key, std::to_string(c++)}, uris)); // value of allOf, anyOf, and oneOf "MUST be a non-empty array" // TODO error/throw? when subschemata_.empty() } }; template <> const std::string logical_combination::key = "allOf"; template <> const std::string logical_combination::key = "anyOf"; template <> const std::string logical_combination::key = "oneOf"; template <> bool logical_combination::is_validate_complete(const json &, const json::json_pointer &, error_handler &e, const logical_combination_error_handler &esub, size_t, size_t current_schema_index) { if (esub) { e.error(esub.error_entry_list_.front().ptr_, esub.error_entry_list_.front().instance_, "at least one subschema has failed, but all of them are required to validate - " + esub.error_entry_list_.front().message_); esub.propagate(e, "[combination: allOf / case#" + std::to_string(current_schema_index) + "] "); } return esub; } template <> bool logical_combination::is_validate_complete(const json &, const json::json_pointer &, error_handler &, const logical_combination_error_handler &, size_t count, size_t) { return count == 1; } template <> bool logical_combination::is_validate_complete(const json &instance, const json::json_pointer &ptr, error_handler &e, const logical_combination_error_handler &, size_t count, size_t) { if (count > 1) e.error(ptr, instance, "more than one subschema has succeeded, but exactly one of them is required to validate"); return count > 1; } class type_schema : public schema { std::vector> type_; std::pair enum_, const_; std::vector> logic_; static std::shared_ptr make(json &schema, json::value_t type, root_schema *, const std::vector &, std::set &); std::shared_ptr if_, then_, else_; void validate(const json::json_pointer &ptr, const json &instance, json_patch &patch, error_handler &e) const override final { // depending on the type of instance run the type specific validator - if present auto type = type_[static_cast(instance.type())]; if (type) type->validate(ptr, instance, patch, e); else e.error(ptr, instance, "unexpected instance type"); if (enum_.first) { bool seen_in_enum = false; for (auto &v : enum_.second) if (instance == v) { seen_in_enum = true; break; } if (!seen_in_enum) e.error(ptr, instance, "instance not found in required enum"); } if (const_.first && const_.second != instance) e.error(ptr, instance, "instance not const"); for (auto l : logic_) l->validate(ptr, instance, patch, e); if (if_) { first_error_handler err; if_->validate(ptr, instance, patch, err); if (!err) { if (then_) then_->validate(ptr, instance, patch, e); } else { if (else_) else_->validate(ptr, instance, patch, e); } } if (instance.is_null()) { patch.add(nlohmann::json::json_pointer{}, default_value_); } } protected: virtual std::shared_ptr make_for_default_( std::shared_ptr<::schema> & /* sch */, root_schema * /* root */, std::vector & /* uris */, nlohmann::json &default_value) const override { auto result = std::make_shared(*this); result->set_default_value(default_value); return result; }; public: type_schema(json &sch, root_schema *root, const std::vector &uris) : schema(root), type_(static_cast(json::value_t::discarded) + 1) { // association between JSON-schema-type and NLohmann-types static const std::vector> schema_types = { {"null", json::value_t::null}, {"object", json::value_t::object}, {"array", json::value_t::array}, {"string", json::value_t::string}, {"boolean", json::value_t::boolean}, {"integer", json::value_t::number_integer}, {"number", json::value_t::number_float}, }; std::set known_keywords; auto attr = sch.find("type"); if (attr == sch.end()) // no type field means all sub-types possible for (auto &t : schema_types) type_[static_cast(t.second)] = type_schema::make(sch, t.second, root, uris, known_keywords); else { switch (attr.value().type()) { // "type": "type" case json::value_t::string: { auto schema_type = attr.value().get(); for (auto &t : schema_types) if (t.first == schema_type) type_[static_cast(t.second)] = type_schema::make(sch, t.second, root, uris, known_keywords); } break; case json::value_t::array: // "type": ["type1", "type2"] for (auto &array_value : attr.value()) { auto schema_type = array_value.get(); for (auto &t : schema_types) if (t.first == schema_type) type_[static_cast(t.second)] = type_schema::make(sch, t.second, root, uris, known_keywords); } break; default: break; } sch.erase(attr); } attr = sch.find("default"); if (attr != sch.end()) { set_default_value(attr.value()); sch.erase(attr); } for (auto &key : known_keywords) sch.erase(key); // with nlohmann::json float instance (but number in schema-definition) can be seen as unsigned or integer - // reuse the number-validator for integer values as well, if they have not been specified explicitly if (type_[static_cast(json::value_t::number_float)] && !type_[static_cast(json::value_t::number_integer)]) type_[static_cast(json::value_t::number_integer)] = type_[static_cast(json::value_t::number_float)]; // #54: JSON-schema does not differentiate between unsigned and signed integer - nlohmann::json does // we stick with JSON-schema: use the integer-validator if instance-value is unsigned type_[static_cast(json::value_t::number_unsigned)] = type_[static_cast(json::value_t::number_integer)]; // special for binary types if (type_[static_cast(json::value_t::string)]) { type_[static_cast(json::value_t::binary)] = type_[static_cast(json::value_t::string)]; } attr = sch.find("enum"); if (attr != sch.end()) { enum_ = {true, attr.value()}; sch.erase(attr); } attr = sch.find("const"); if (attr != sch.end()) { const_ = {true, attr.value()}; sch.erase(attr); } attr = sch.find("not"); if (attr != sch.end()) { logic_.push_back(std::make_shared(attr.value(), root, uris)); sch.erase(attr); } attr = sch.find("allOf"); if (attr != sch.end()) { logic_.push_back(std::make_shared>(attr.value(), root, uris)); sch.erase(attr); } attr = sch.find("anyOf"); if (attr != sch.end()) { logic_.push_back(std::make_shared>(attr.value(), root, uris)); sch.erase(attr); } attr = sch.find("oneOf"); if (attr != sch.end()) { logic_.push_back(std::make_shared>(attr.value(), root, uris)); sch.erase(attr); } attr = sch.find("if"); if (attr != sch.end()) { auto attr_then = sch.find("then"); auto attr_else = sch.find("else"); if (attr_then != sch.end() || attr_else != sch.end()) { if_ = schema::make(attr.value(), root, {"if"}, uris); if (attr_then != sch.end()) { then_ = schema::make(attr_then.value(), root, {"then"}, uris); sch.erase(attr_then); } if (attr_else != sch.end()) { else_ = schema::make(attr_else.value(), root, {"else"}, uris); sch.erase(attr_else); } } sch.erase(attr); } } }; class string : public schema { std::pair maxLength_{false, 0}; std::pair minLength_{false, 0}; #ifndef NO_STD_REGEX std::pair pattern_{false, REGEX_NAMESPACE::regex()}; std::string patternString_; #endif std::pair format_; std::tuple content_{false, "", ""}; std::size_t utf8_length(const std::string &s) const { size_t len = 0; for (auto c : s) if ((c & 0xc0) != 0x80) len++; return len; } void validate(const json::json_pointer &ptr, const json &instance, json_patch &, error_handler &e) const override { if (minLength_.first) { if (utf8_length(instance.get()) < minLength_.second) { std::ostringstream s; s << "instance is too short as per minLength:" << minLength_.second; e.error(ptr, instance, s.str()); } } if (maxLength_.first) { if (utf8_length(instance.get()) > maxLength_.second) { std::ostringstream s; s << "instance is too long as per maxLength: " << maxLength_.second; e.error(ptr, instance, s.str()); } } if (std::get<0>(content_)) { if (root_->content_check() == nullptr) e.error(ptr, instance, std::string("a content checker was not provided but a contentEncoding or contentMediaType for this string have been present: '") + std::get<1>(content_) + "' '" + std::get<2>(content_) + "'"); else { try { root_->content_check()(std::get<1>(content_), std::get<2>(content_), instance); } catch (const std::exception &ex) { e.error(ptr, instance, std::string("content-checking failed: ") + ex.what()); } } } else if (instance.type() == json::value_t::binary) { e.error(ptr, instance, "expected string, but get binary data"); } if (instance.type() != json::value_t::string) { return; // next checks only for strings } #ifndef NO_STD_REGEX if (pattern_.first && !REGEX_NAMESPACE::regex_search(instance.get(), pattern_.second)) e.error(ptr, instance, "instance does not match regex pattern: " + patternString_); #endif if (format_.first) { if (root_->format_check() == nullptr) e.error(ptr, instance, std::string("a format checker was not provided but a format keyword for this string is present: ") + format_.second); else { try { root_->format_check()(format_.second, instance.get()); } catch (const std::exception &ex) { e.error(ptr, instance, std::string("format-checking failed: ") + ex.what()); } } } } public: string(json &sch, root_schema *root) : schema(root) { auto attr = sch.find("maxLength"); if (attr != sch.end()) { maxLength_ = {true, attr.value().get()}; sch.erase(attr); } attr = sch.find("minLength"); if (attr != sch.end()) { minLength_ = {true, attr.value().get()}; sch.erase(attr); } attr = sch.find("contentEncoding"); if (attr != sch.end()) { std::get<0>(content_) = true; std::get<1>(content_) = attr.value().get(); // special case for nlohmann::json-binary-types // // https://github.com/pboettch/json-schema-validator/pull/114 // // We cannot use explicitly in a schema: {"type": "binary"} or // "type": ["binary", "number"] we have to be implicit. For a // schema where "contentEncoding" is set to "binary", an instance // of type json::value_t::binary is accepted. If a // contentEncoding-callback has to be provided and is called // accordingly. For encoding=binary, no other type validations are done sch.erase(attr); } attr = sch.find("contentMediaType"); if (attr != sch.end()) { std::get<0>(content_) = true; std::get<2>(content_) = attr.value().get(); sch.erase(attr); } if (std::get<0>(content_) == true && root_->content_check() == nullptr) { throw std::invalid_argument{"schema contains contentEncoding/contentMediaType but content checker was not set"}; } #ifndef NO_STD_REGEX attr = sch.find("pattern"); if (attr != sch.end()) { patternString_ = attr.value().get(); pattern_ = {true, REGEX_NAMESPACE::regex(attr.value().get(), REGEX_NAMESPACE::regex::ECMAScript)}; sch.erase(attr); } #endif attr = sch.find("format"); if (attr != sch.end()) { if (root_->format_check() == nullptr) throw std::invalid_argument{"a format checker was not provided but a format keyword for this string is present: " + format_.second}; format_ = {true, attr.value().get()}; sch.erase(attr); } } }; template class numeric : public schema { std::pair maximum_{false, 0}; std::pair minimum_{false, 0}; bool exclusiveMaximum_ = false; bool exclusiveMinimum_ = false; std::pair multipleOf_{false, 0}; // multipleOf - if the remainder of the division is 0 -> OK bool violates_multiple_of(T x) const { double res = std::remainder(x, multipleOf_.second); double multiple = std::fabs(x / multipleOf_.second); if (multiple > 1) { res = res / multiple; } double eps = std::nextafter(x, 0) - static_cast(x); return std::fabs(res) > std::fabs(eps); } void validate(const json::json_pointer &ptr, const json &instance, json_patch &, error_handler &e) const override { T value = instance; // conversion of json to value_type std::ostringstream oss; if (multipleOf_.first && value != 0) // zero is multiple of everything if (violates_multiple_of(value)) oss << "instance is not a multiple of " << json(multipleOf_.second); if (maximum_.first) { if (exclusiveMaximum_ && value >= maximum_.second) oss << "instance exceeds or equals maximum of " << json(maximum_.second); else if (value > maximum_.second) oss << "instance exceeds maximum of " << json(maximum_.second); } if (minimum_.first) { if (exclusiveMinimum_ && value <= minimum_.second) oss << "instance is below or equals minimum of " << json(minimum_.second); else if (value < minimum_.second) oss << "instance is below minimum of " << json(minimum_.second); } oss.seekp(0, std::ios::end); auto size = oss.tellp(); if (size != 0) { oss.seekp(0, std::ios::beg); e.error(ptr, instance, oss.str()); } } public: numeric(const json &sch, root_schema *root, std::set &kw) : schema(root) { auto attr = sch.find("maximum"); if (attr != sch.end()) { maximum_ = {true, attr.value().get()}; kw.insert("maximum"); } attr = sch.find("minimum"); if (attr != sch.end()) { minimum_ = {true, attr.value().get()}; kw.insert("minimum"); } attr = sch.find("exclusiveMaximum"); if (attr != sch.end()) { exclusiveMaximum_ = true; maximum_ = {true, attr.value().get()}; kw.insert("exclusiveMaximum"); } attr = sch.find("exclusiveMinimum"); if (attr != sch.end()) { exclusiveMinimum_ = true; minimum_ = {true, attr.value().get()}; kw.insert("exclusiveMinimum"); } attr = sch.find("multipleOf"); if (attr != sch.end()) { multipleOf_ = {true, attr.value().get()}; kw.insert("multipleOf"); } } }; class null : public schema { void validate(const json::json_pointer &ptr, const json &instance, json_patch &, error_handler &e) const override { if (!instance.is_null()) e.error(ptr, instance, "expected to be null"); } public: null(json &, root_schema *root) : schema(root) {} }; class boolean_type : public schema { void validate(const json::json_pointer &, const json &, json_patch &, error_handler &) const override {} public: boolean_type(json &, root_schema *root) : schema(root) {} }; class boolean : public schema { bool true_; void validate(const json::json_pointer &ptr, const json &instance, json_patch &, error_handler &e) const override { if (!true_) { // false schema // empty array // switch (instance.type()) { // case json::value_t::array: // if (instance.size() != 0) // valid false-schema // e.error(ptr, instance, "false-schema required empty array"); // return; //} e.error(ptr, instance, "instance invalid as per false-schema"); } } public: boolean(json &sch, root_schema *root) : schema(root), true_(sch) {} }; class required : public schema { const std::vector required_; void validate(const json::json_pointer &ptr, const json &instance, json_patch &, error_handler &e) const override final { for (auto &r : required_) if (instance.find(r) == instance.end()) e.error(ptr, instance, "required property '" + r + "' not found in object as a dependency"); } public: required(const std::vector &r, root_schema *root) : schema(root), required_(r) {} }; class object : public schema { std::pair maxProperties_{false, 0}; std::pair minProperties_{false, 0}; std::vector required_; std::map> properties_; #ifndef NO_STD_REGEX std::vector>> patternProperties_; #endif std::shared_ptr additionalProperties_; std::map> dependencies_; std::shared_ptr propertyNames_; void validate(const json::json_pointer &ptr, const json &instance, json_patch &patch, error_handler &e) const override { if (maxProperties_.first && instance.size() > maxProperties_.second) e.error(ptr, instance, "too many properties"); if (minProperties_.first && instance.size() < minProperties_.second) e.error(ptr, instance, "too few properties"); for (auto &r : required_) if (instance.find(r) == instance.end()) e.error(ptr, instance, "required property '" + r + "' not found in object"); // for each property in instance for (auto &p : instance.items()) { if (propertyNames_) propertyNames_->validate(ptr, p.key(), patch, e); bool a_prop_or_pattern_matched = false; auto schema_p = properties_.find(p.key()); // check if it is in "properties" if (schema_p != properties_.end()) { a_prop_or_pattern_matched = true; schema_p->second->validate(ptr / p.key(), p.value(), patch, e); } #ifndef NO_STD_REGEX // check all matching patternProperties for (auto &schema_pp : patternProperties_) if (REGEX_NAMESPACE::regex_search(p.key(), schema_pp.first)) { a_prop_or_pattern_matched = true; schema_pp.second->validate(ptr / p.key(), p.value(), patch, e); } #endif // check additionalProperties as a last resort if (!a_prop_or_pattern_matched && additionalProperties_) { first_error_handler additional_prop_err; additionalProperties_->validate(ptr / p.key(), p.value(), patch, additional_prop_err); if (additional_prop_err) e.error(ptr, instance, "validation failed for additional property '" + p.key() + "': " + additional_prop_err.message_); } } // reverse search for (auto const &prop : properties_) { const auto finding = instance.find(prop.first); if (instance.end() == finding) { // if the prop is not in the instance const auto &default_value = prop.second->default_value(ptr, instance, e); if (!default_value.is_null()) { // if default value is available patch.add((ptr / prop.first), default_value); } } } for (auto &dep : dependencies_) { auto prop = instance.find(dep.first); if (prop != instance.end()) // if dependency-property is present in instance dep.second->validate(ptr / dep.first, instance, patch, e); // validate } } public: object(json &sch, root_schema *root, const std::vector &uris) : schema(root) { auto attr = sch.find("maxProperties"); if (attr != sch.end()) { maxProperties_ = {true, attr.value().get()}; sch.erase(attr); } attr = sch.find("minProperties"); if (attr != sch.end()) { minProperties_ = {true, attr.value().get()}; sch.erase(attr); } attr = sch.find("required"); if (attr != sch.end()) { required_ = attr.value().get>(); sch.erase(attr); } attr = sch.find("properties"); if (attr != sch.end()) { for (auto prop : attr.value().items()) properties_.insert( std::make_pair( prop.key(), schema::make(prop.value(), root, {"properties", prop.key()}, uris))); sch.erase(attr); } #ifndef NO_STD_REGEX attr = sch.find("patternProperties"); if (attr != sch.end()) { for (auto prop : attr.value().items()) patternProperties_.push_back( std::make_pair( REGEX_NAMESPACE::regex(prop.key(), REGEX_NAMESPACE::regex::ECMAScript), schema::make(prop.value(), root, {prop.key()}, uris))); sch.erase(attr); } #endif attr = sch.find("additionalProperties"); if (attr != sch.end()) { additionalProperties_ = schema::make(attr.value(), root, {"additionalProperties"}, uris); sch.erase(attr); } attr = sch.find("dependencies"); if (attr != sch.end()) { for (auto &dep : attr.value().items()) switch (dep.value().type()) { case json::value_t::array: dependencies_.emplace(dep.key(), std::make_shared( dep.value().get>(), root)); break; default: dependencies_.emplace(dep.key(), schema::make(dep.value(), root, {"dependencies", dep.key()}, uris)); break; } sch.erase(attr); } attr = sch.find("propertyNames"); if (attr != sch.end()) { propertyNames_ = schema::make(attr.value(), root, {"propertyNames"}, uris); sch.erase(attr); } attr = sch.find("default"); if (attr != sch.end()) { set_default_value(*attr); } } }; class array : public schema { std::pair maxItems_{false, 0}; std::pair minItems_{false, 0}; bool uniqueItems_ = false; std::shared_ptr items_schema_; std::vector> items_; std::shared_ptr additionalItems_; std::shared_ptr contains_; void validate(const json::json_pointer &ptr, const json &instance, json_patch &patch, error_handler &e) const override { if (maxItems_.first && instance.size() > maxItems_.second) e.error(ptr, instance, "array has too many items"); if (minItems_.first && instance.size() < minItems_.second) e.error(ptr, instance, "array has too few items"); if (uniqueItems_) { for (auto it = instance.cbegin(); it != instance.cend(); ++it) { auto v = std::find(it + 1, instance.end(), *it); if (v != instance.end()) e.error(ptr, instance, "items have to be unique for this array"); } } size_t index = 0; if (items_schema_) for (auto &i : instance) { items_schema_->validate(ptr / index, i, patch, e); index++; } else { auto item = items_.cbegin(); for (auto &i : instance) { std::shared_ptr item_validator; if (item == items_.cend()) item_validator = additionalItems_; else { item_validator = *item; item++; } if (!item_validator) break; item_validator->validate(ptr / index, i, patch, e); } } if (contains_) { bool contained = false; for (auto &item : instance) { first_error_handler local_e; contains_->validate(ptr, item, patch, local_e); if (!local_e) { contained = true; break; } } if (!contained) e.error(ptr, instance, "array does not contain required element as per 'contains'"); } } public: array(json &sch, root_schema *root, const std::vector &uris) : schema(root) { auto attr = sch.find("maxItems"); if (attr != sch.end()) { maxItems_ = {true, attr.value().get()}; sch.erase(attr); } attr = sch.find("minItems"); if (attr != sch.end()) { minItems_ = {true, attr.value().get()}; sch.erase(attr); } attr = sch.find("uniqueItems"); if (attr != sch.end()) { uniqueItems_ = attr.value().get(); sch.erase(attr); } attr = sch.find("items"); if (attr != sch.end()) { if (attr.value().type() == json::value_t::array) { size_t c = 0; for (auto &subsch : attr.value()) items_.push_back(schema::make(subsch, root, {"items", std::to_string(c++)}, uris)); auto attr_add = sch.find("additionalItems"); if (attr_add != sch.end()) { additionalItems_ = schema::make(attr_add.value(), root, {"additionalItems"}, uris); sch.erase(attr_add); } } else if (attr.value().type() == json::value_t::object || attr.value().type() == json::value_t::boolean) items_schema_ = schema::make(attr.value(), root, {"items"}, uris); sch.erase(attr); } attr = sch.find("contains"); if (attr != sch.end()) { contains_ = schema::make(attr.value(), root, {"contains"}, uris); sch.erase(attr); } } }; std::shared_ptr type_schema::make(json &schema, json::value_t type, root_schema *root, const std::vector &uris, std::set &kw) { switch (type) { case json::value_t::null: return std::make_shared(schema, root); case json::value_t::number_unsigned: case json::value_t::number_integer: return std::make_shared>(schema, root, kw); case json::value_t::number_float: return std::make_shared>(schema, root, kw); case json::value_t::string: return std::make_shared(schema, root); case json::value_t::boolean: return std::make_shared(schema, root); case json::value_t::object: return std::make_shared(schema, root, uris); case json::value_t::array: return std::make_shared(schema, root, uris); case json::value_t::discarded: // not a real type - silence please break; case json::value_t::binary: break; } return nullptr; } } // namespace namespace { std::shared_ptr schema::make(json &schema, root_schema *root, const std::vector &keys, std::vector uris) { // remove URIs which contain plain name identifiers, as sub-schemas cannot be referenced for (auto uri = uris.begin(); uri != uris.end();) if (uri->identifier() != "") uri = uris.erase(uri); else uri++; // append to all URIs the keys for this sub-schema for (auto &key : keys) for (auto &uri : uris) uri = uri.append(key); std::shared_ptr<::schema> sch; // boolean schema if (schema.type() == json::value_t::boolean) sch = std::make_shared(schema, root); else if (schema.type() == json::value_t::object) { auto attr = schema.find("$id"); // if $id is present, this schema can be referenced by this ID // as an additional URI if (attr != schema.end()) { if (std::find(uris.begin(), uris.end(), attr.value().get()) == uris.end()) uris.push_back(uris.back().derive(attr.value().get())); // so add it to the list if it is not there already schema.erase(attr); } auto findDefinitions = [&](const std::string &defs) -> bool { attr = schema.find(defs); if (attr != schema.end()) { for (auto &def : attr.value().items()) schema::make(def.value(), root, {defs, def.key()}, uris); schema.erase(attr); return true; } return false; }; if (!findDefinitions("$defs")) { findDefinitions("definitions"); } attr = schema.find("$ref"); if (attr != schema.end()) { // this schema is a reference // the last one on the uri-stack is the last id seen before coming here, // so this is the origial URI for this reference, the $ref-value has thus be resolved from it auto id = uris.back().derive(attr.value().get()); sch = root->get_or_create_ref(id); schema.erase(attr); // special case where we break draft-7 and allow overriding of properties when a $ref is used attr = schema.find("default"); if (attr != schema.end()) { // copy the referenced schema depending on the underlying type and modify the default value if (auto new_sch = sch->make_for_default_(sch, root, uris, attr.value())) { sch = new_sch; } schema.erase(attr); } } else { sch = std::make_shared(schema, root, uris); } schema.erase("$schema"); schema.erase("title"); schema.erase("description"); } else { throw std::invalid_argument("invalid JSON-type for a schema for " + uris[0].to_string() + ", expected: boolean or object"); } for (auto &uri : uris) { // for all URIs this schema is referenced by root->insert(uri, sch); if (schema.type() == json::value_t::object) for (auto &u : schema.items()) root->insert_unknown_keyword(uri, u.key(), u.value()); // insert unknown keywords for later reference } return sch; } class throwing_error_handler : public error_handler { void error(const json::json_pointer &ptr, const json &instance, const std::string &message) override { throw std::invalid_argument(std::string("At ") + ptr.to_string() + " of " + instance.dump() + " - " + message + "\n"); } }; } // namespace namespace nlohmann { namespace json_schema { json_validator::json_validator(schema_loader loader, format_checker format, content_checker content) : root_(std::unique_ptr(new root_schema(std::move(loader), std::move(format), std::move(content)))) { } json_validator::json_validator(const json &schema, schema_loader loader, format_checker format, content_checker content) : json_validator(std::move(loader), std::move(format), std::move(content)) { set_root_schema(schema); } json_validator::json_validator(json &&schema, schema_loader loader, format_checker format, content_checker content) : json_validator(std::move(loader), std::move(format), std::move(content)) { set_root_schema(std::move(schema)); } // move constructor, destructor and move assignment operator can be defaulted here // where root_schema is a complete type json_validator::json_validator(json_validator &&) = default; json_validator::~json_validator() = default; json_validator &json_validator::operator=(json_validator &&) = default; void json_validator::set_root_schema(const json &schema) { root_->set_root_schema(schema); } void json_validator::set_root_schema(json &&schema) { root_->set_root_schema(std::move(schema)); } json json_validator::validate(const json &instance) const { throwing_error_handler err; return validate(instance, err); } json json_validator::validate(const json &instance, error_handler &err, const json_uri &initial_uri) const { json::json_pointer ptr; json_patch patch; root_->validate(ptr, instance, patch, err, initial_uri); return patch; } } // namespace json_schema } // namespace nlohmann ================================================ FILE: src/nlohmann/json-schema.hpp ================================================ /* * JSON schema validator for JSON for modern C++ * * Copyright (c) 2016-2019 Patrick Boettcher . * * SPDX-License-Identifier: MIT * */ #ifndef NLOHMANN_JSON_SCHEMA_HPP__ #define NLOHMANN_JSON_SCHEMA_HPP__ #ifdef _WIN32 # if defined(JSON_SCHEMA_VALIDATOR_EXPORTS) # define JSON_SCHEMA_VALIDATOR_API __declspec(dllexport) # elif defined(JSON_SCHEMA_VALIDATOR_IMPORTS) # define JSON_SCHEMA_VALIDATOR_API __declspec(dllimport) # else # define JSON_SCHEMA_VALIDATOR_API # endif #else # define JSON_SCHEMA_VALIDATOR_API #endif #include #ifdef NLOHMANN_JSON_VERSION_MAJOR # if (NLOHMANN_JSON_VERSION_MAJOR * 10000 + NLOHMANN_JSON_VERSION_MINOR * 100 + NLOHMANN_JSON_VERSION_PATCH) < 30800 # error "Please use this library with NLohmann's JSON version 3.8.0 or higher" # endif #else # error "expected existing NLOHMANN_JSON_VERSION_MAJOR preproc variable, please update to NLohmann's JSON 3.8.0" #endif // make yourself a home - welcome to nlohmann's namespace namespace nlohmann { // A class representing a JSON-URI for schemas derived from // section 8 of JSON Schema: A Media Type for Describing JSON Documents // draft-wright-json-schema-00 // // New URIs can be derived from it using the derive()-method. // This is useful for resolving refs or subschema-IDs in json-schemas. // // This is done implement the requirements described in section 8.2. // class JSON_SCHEMA_VALIDATOR_API json_uri { std::string urn_; std::string scheme_; std::string authority_; std::string path_; json::json_pointer pointer_; // fragment part if JSON-Pointer std::string identifier_; // fragment part if Locatation Independent ID protected: // decodes a JSON uri and replaces all or part of the currently stored values void update(const std::string &uri); std::tuple as_tuple() const { return std::make_tuple(urn_, scheme_, authority_, path_, identifier_ != "" ? identifier_ : pointer_.to_string()); } public: json_uri(const std::string &uri) { update(uri); } const std::string &scheme() const { return scheme_; } const std::string &authority() const { return authority_; } const std::string &path() const { return path_; } const json::json_pointer &pointer() const { return pointer_; } const std::string &identifier() const { return identifier_; } std::string fragment() const { if (identifier_ == "") return pointer_.to_string(); else return identifier_; } std::string url() const { return location(); } std::string location() const; static std::string escape(const std::string &); // create a new json_uri based in this one and the given uri // resolves relative changes (pathes or pointers) and resets part if proto or hostname changes json_uri derive(const std::string &uri) const { json_uri u = *this; u.update(uri); return u; } // append a pointer-field to the pointer-part of this uri json_uri append(const std::string &field) const { if (identifier_ != "") return *this; json_uri u = *this; u.pointer_ /= field; return u; } std::string to_string() const; friend bool operator<(const json_uri &l, const json_uri &r) { return l.as_tuple() < r.as_tuple(); } friend bool operator==(const json_uri &l, const json_uri &r) { return l.as_tuple() == r.as_tuple(); } friend std::ostream &operator<<(std::ostream &os, const json_uri &u); }; namespace json_schema { extern json draft7_schema_builtin; typedef std::function schema_loader; typedef std::function format_checker; typedef std::function content_checker; // Interface for validation error handlers class JSON_SCHEMA_VALIDATOR_API error_handler { public: virtual ~error_handler() {} virtual void error(const json::json_pointer & /*ptr*/, const json & /*instance*/, const std::string & /*message*/) = 0; }; class JSON_SCHEMA_VALIDATOR_API basic_error_handler : public error_handler { bool error_{false}; public: void error(const json::json_pointer & /*ptr*/, const json & /*instance*/, const std::string & /*message*/) override { error_ = true; } virtual void reset() { error_ = false; } operator bool() const { return error_; } }; /** * Checks validity of JSON schema built-in string format specifiers like 'date-time', 'ipv4', ... */ void JSON_SCHEMA_VALIDATOR_API default_string_format_check(const std::string &format, const std::string &value); class root_schema; class JSON_SCHEMA_VALIDATOR_API json_validator { std::unique_ptr root_; public: json_validator(schema_loader = nullptr, format_checker = nullptr, content_checker = nullptr); json_validator(const json &, schema_loader = nullptr, format_checker = nullptr, content_checker = nullptr); json_validator(json &&, schema_loader = nullptr, format_checker = nullptr, content_checker = nullptr); json_validator(json_validator &&); json_validator &operator=(json_validator &&); json_validator(json_validator const &) = delete; json_validator &operator=(json_validator const &) = delete; ~json_validator(); // insert and set the root-schema void set_root_schema(const json &); void set_root_schema(json &&); // validate a json-document based on the root-schema json validate(const json &) const; // validate a json-document based on the root-schema with a custom error-handler json validate(const json &, error_handler &, const json_uri &initial_uri = json_uri("#")) const; }; } // namespace json_schema } // namespace nlohmann #endif /* NLOHMANN_JSON_SCHEMA_HPP__ */ ================================================ FILE: src/smtp-address-validator.cpp ================================================ /* Snarfed from : Copyright (c) 2021 Gene Hightower Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "smtp-address-validator.hpp" static const signed char _address_actions[] = { 0, 1, 0, 1, 1, 0}; static const short _address_key_offsets[] = { 0, 0, 24, 26, 50, 52, 54, 56, 58, 60, 62, 86, 103, 105, 107, 109, 111, 113, 115, 117, 134, 150, 161, 168, 176, 180, 181, 190, 195, 196, 201, 202, 207, 210, 213, 219, 222, 225, 228, 234, 237, 240, 243, 249, 252, 261, 270, 282, 293, 302, 311, 320, 328, 345, 353, 360, 367, 368, 375, 382, 389, 396, 397, 404, 411, 418, 425, 426, 433, 440, 447, 454, 455, 462, 469, 476, 483, 484, 491, 498, 505, 512, 513, 523, 531, 538, 545, 546, 552, 559, 566, 573, 581, 589, 597, 608, 618, 626, 634, 641, 649, 657, 665, 667, 673, 681, 689, 697, 699, 705, 713, 721, 729, 731, 737, 745, 753, 761, 763, 769, 777, 785, 793, 795, 802, 812, 821, 829, 837, 839, 848, 857, 865, 873, 875, 884, 893, 901, 909, 911, 920, 929, 937, 945, 947, 956, 965, 974, 983, 992, 1004, 1015, 1024, 1033, 1042, 1051, 1060, 1072, 1083, 1092, 1101, 1109, 1118, 1127, 1136, 1148, 1159, 1168, 1177, 1185, 1194, 1203, 1212, 1224, 1235, 1244, 1253, 1261, 1270, 1279, 1288, 1300, 1311, 1320, 1329, 1337, 1339, 1353, 1355, 1357, 1359, 1361, 1363, 1365, 1367, 1368, 1370, 1388, 0}; static const signed char _address_trans_keys[] = { -32, -19, -16, -12, 34, 45, 61, 63, -62, -33, -31, -17, -15, -13, 33, 39, 42, 43, 47, 57, 65, 90, 94, 126, -128, -65, -32, -19, -16, -12, 33, 46, 61, 64, -62, -33, -31, -17, -15, -13, 35, 39, 42, 43, 45, 57, 63, 90, 94, 126, -96, -65, -128, -65, -128, -97, -112, -65, -128, -65, -128, -113, -32, -19, -16, -12, 33, 45, 61, 63, -62, -33, -31, -17, -15, -13, 35, 39, 42, 43, 47, 57, 65, 90, 94, 126, -32, -19, -16, -12, 91, -62, -33, -31, -17, -15, -13, 48, 57, 65, 90, 97, 122, -128, -65, -96, -65, -128, -65, -128, -97, -112, -65, -128, -65, -128, -113, -32, -19, -16, -12, 45, -62, -33, -31, -17, -15, -13, 48, 57, 65, 90, 97, 122, -32, -19, -16, -12, -62, -33, -31, -17, -15, -13, 48, 57, 65, 90, 97, 122, 45, 48, 49, 50, 73, 51, 57, 65, 90, 97, 122, 45, 48, 57, 65, 90, 97, 122, 45, 58, 48, 57, 65, 90, 97, 122, 33, 90, 94, 126, 93, 45, 46, 58, 48, 57, 65, 90, 97, 122, 48, 49, 50, 51, 57, 46, 48, 49, 50, 51, 57, 46, 48, 49, 50, 51, 57, 93, 48, 57, 93, 48, 57, 53, 93, 48, 52, 54, 57, 93, 48, 53, 46, 48, 57, 46, 48, 57, 46, 53, 48, 52, 54, 57, 46, 48, 53, 46, 48, 57, 46, 48, 57, 46, 53, 48, 52, 54, 57, 46, 48, 53, 45, 46, 58, 48, 57, 65, 90, 97, 122, 45, 46, 58, 48, 57, 65, 90, 97, 122, 45, 46, 53, 58, 48, 52, 54, 57, 65, 90, 97, 122, 45, 46, 58, 48, 53, 54, 57, 65, 90, 97, 122, 45, 58, 80, 48, 57, 65, 90, 97, 122, 45, 58, 118, 48, 57, 65, 90, 97, 122, 45, 54, 58, 48, 57, 65, 90, 97, 122, 45, 58, 48, 57, 65, 90, 97, 122, 58, 33, 47, 48, 57, 59, 64, 65, 70, 71, 90, 94, 96, 97, 102, 103, 126, 58, 93, 48, 57, 65, 70, 97, 102, 58, 48, 57, 65, 70, 97, 102, 58, 48, 57, 65, 70, 97, 102, 58, 58, 48, 57, 65, 70, 97, 102, 58, 48, 57, 65, 70, 97, 102, 58, 48, 57, 65, 70, 97, 102, 58, 48, 57, 65, 70, 97, 102, 58, 58, 48, 57, 65, 70, 97, 102, 58, 48, 57, 65, 70, 97, 102, 58, 48, 57, 65, 70, 97, 102, 58, 48, 57, 65, 70, 97, 102, 58, 58, 48, 57, 65, 70, 97, 102, 58, 48, 57, 65, 70, 97, 102, 58, 48, 57, 65, 70, 97, 102, 58, 48, 57, 65, 70, 97, 102, 58, 58, 48, 57, 65, 70, 97, 102, 58, 48, 57, 65, 70, 97, 102, 58, 48, 57, 65, 70, 97, 102, 58, 48, 57, 65, 70, 97, 102, 58, 58, 48, 57, 65, 70, 97, 102, 58, 48, 57, 65, 70, 97, 102, 58, 48, 57, 65, 70, 97, 102, 58, 48, 57, 65, 70, 97, 102, 58, 48, 49, 50, 58, 51, 57, 65, 70, 97, 102, 46, 58, 48, 57, 65, 70, 97, 102, 58, 48, 57, 65, 70, 97, 102, 58, 48, 57, 65, 70, 97, 102, 58, 48, 57, 65, 70, 97, 102, 93, 48, 57, 65, 70, 97, 102, 93, 48, 57, 65, 70, 97, 102, 93, 48, 57, 65, 70, 97, 102, 46, 58, 48, 57, 65, 70, 97, 102, 46, 58, 48, 57, 65, 70, 97, 102, 46, 58, 48, 57, 65, 70, 97, 102, 46, 53, 58, 48, 52, 54, 57, 65, 70, 97, 102, 46, 58, 48, 53, 54, 57, 65, 70, 97, 102, 46, 58, 48, 57, 65, 70, 97, 102, 46, 58, 48, 57, 65, 70, 97, 102, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 58, 48, 57, 65, 70, 97, 102, 48, 49, 50, 93, 51, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 49, 50, 51, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 49, 50, 51, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 49, 50, 51, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 49, 50, 51, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 46, 53, 58, 93, 48, 52, 54, 57, 65, 70, 97, 102, 46, 58, 93, 48, 53, 54, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 46, 53, 58, 93, 48, 52, 54, 57, 65, 70, 97, 102, 46, 58, 93, 48, 53, 54, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 46, 53, 58, 93, 48, 52, 54, 57, 65, 70, 97, 102, 46, 58, 93, 48, 53, 54, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 46, 53, 58, 93, 48, 52, 54, 57, 65, 70, 97, 102, 46, 58, 93, 48, 53, 54, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 46, 53, 58, 93, 48, 52, 54, 57, 65, 70, 97, 102, 46, 58, 93, 48, 53, 54, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 46, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, 48, 57, 65, 70, 97, 102, 58, 93, -32, -19, -16, -12, 34, 92, -62, -33, -31, -17, -15, -13, 32, 126, -128, -65, -96, -65, -128, -65, -128, -97, -112, -65, -128, -65, -128, -113, 64, 32, 126, -32, -19, -16, -12, 45, 46, -62, -33, -31, -17, -15, -13, 48, 57, 65, 90, 97, 122, 0}; static const signed char _address_single_lengths[] = { 0, 8, 0, 8, 0, 0, 0, 0, 0, 0, 8, 5, 0, 0, 0, 0, 0, 0, 0, 5, 4, 5, 1, 2, 0, 1, 3, 3, 1, 3, 1, 3, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 2, 1, 3, 3, 4, 3, 3, 3, 3, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 2, 1, 1, 1, 0, 1, 1, 1, 2, 2, 2, 3, 2, 2, 2, 1, 2, 2, 2, 2, 0, 2, 2, 2, 2, 0, 2, 2, 2, 2, 0, 2, 2, 2, 2, 0, 2, 2, 2, 2, 1, 4, 3, 2, 2, 2, 3, 3, 2, 2, 2, 3, 3, 2, 2, 2, 3, 3, 2, 2, 2, 3, 3, 3, 3, 3, 4, 3, 3, 3, 3, 3, 3, 4, 3, 3, 3, 2, 3, 3, 3, 4, 3, 3, 3, 2, 3, 3, 3, 4, 3, 3, 3, 2, 3, 3, 3, 4, 3, 3, 3, 2, 2, 6, 0, 0, 0, 0, 0, 0, 0, 1, 0, 6, 0, 0}; static const signed char _address_range_lengths[] = { 0, 8, 1, 8, 1, 1, 1, 1, 1, 1, 8, 6, 1, 1, 1, 1, 1, 1, 1, 6, 6, 3, 3, 3, 2, 0, 3, 1, 0, 1, 0, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 2, 1, 3, 3, 4, 4, 3, 3, 3, 3, 8, 3, 3, 3, 0, 3, 3, 3, 3, 0, 3, 3, 3, 3, 0, 3, 3, 3, 3, 0, 3, 3, 3, 3, 0, 3, 3, 3, 3, 0, 3, 3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3, 4, 4, 3, 3, 3, 3, 3, 3, 0, 3, 3, 3, 3, 0, 3, 3, 3, 3, 0, 3, 3, 3, 3, 0, 3, 3, 3, 3, 0, 3, 3, 3, 3, 3, 0, 3, 3, 3, 3, 0, 3, 3, 3, 3, 0, 3, 3, 3, 3, 0, 3, 3, 3, 3, 3, 4, 4, 3, 3, 3, 3, 3, 4, 4, 3, 3, 3, 3, 3, 3, 4, 4, 3, 3, 3, 3, 3, 3, 4, 4, 3, 3, 3, 3, 3, 3, 4, 4, 3, 3, 3, 0, 4, 1, 1, 1, 1, 1, 1, 1, 0, 1, 6, 0, 0}; static const short _address_index_offsets[] = { 0, 0, 17, 19, 36, 38, 40, 42, 44, 46, 48, 65, 77, 79, 81, 83, 85, 87, 89, 91, 103, 114, 123, 128, 134, 137, 139, 146, 151, 153, 158, 160, 165, 168, 171, 176, 179, 182, 185, 190, 193, 196, 199, 204, 207, 214, 221, 230, 238, 245, 252, 259, 265, 275, 281, 286, 291, 293, 298, 303, 308, 313, 315, 320, 325, 330, 335, 337, 342, 347, 352, 357, 359, 364, 369, 374, 379, 381, 386, 391, 396, 401, 403, 411, 417, 422, 427, 429, 433, 438, 443, 448, 454, 460, 466, 474, 481, 487, 493, 498, 504, 510, 516, 519, 523, 529, 535, 541, 544, 548, 554, 560, 566, 569, 573, 579, 585, 591, 594, 598, 604, 610, 616, 619, 624, 632, 639, 645, 651, 654, 661, 668, 674, 680, 683, 690, 697, 703, 709, 712, 719, 726, 732, 738, 741, 748, 755, 762, 769, 776, 785, 793, 800, 807, 814, 821, 828, 837, 845, 852, 859, 865, 872, 879, 886, 895, 903, 910, 917, 923, 930, 937, 944, 953, 961, 968, 975, 981, 988, 995, 1002, 1011, 1019, 1026, 1033, 1039, 1042, 1053, 1055, 1057, 1059, 1061, 1063, 1065, 1067, 1069, 1071, 1084, 0}; static const short _address_cond_targs[] = { 4, 6, 7, 9, 186, 3, 3, 3, 2, 5, 8, 3, 3, 3, 3, 3, 0, 3, 0, 4, 6, 7, 9, 3, 10, 3, 11, 2, 5, 8, 3, 3, 3, 3, 3, 0, 2, 0, 2, 0, 2, 0, 5, 0, 5, 0, 5, 0, 4, 6, 7, 9, 3, 3, 3, 3, 2, 5, 8, 3, 3, 3, 3, 3, 0, 13, 15, 16, 18, 21, 12, 14, 17, 196, 196, 196, 0, 196, 0, 12, 0, 12, 0, 12, 0, 14, 0, 14, 0, 14, 0, 13, 15, 16, 18, 19, 12, 14, 17, 196, 196, 196, 0, 13, 15, 16, 18, 12, 14, 17, 196, 196, 196, 0, 22, 26, 44, 46, 48, 45, 23, 23, 0, 22, 23, 23, 23, 0, 22, 24, 23, 23, 23, 0, 25, 25, 0, 197, 0, 22, 27, 24, 23, 23, 23, 0, 28, 40, 42, 41, 0, 29, 0, 30, 36, 38, 37, 0, 31, 0, 25, 32, 34, 33, 0, 197, 33, 0, 197, 25, 0, 35, 197, 33, 25, 0, 197, 25, 0, 31, 37, 0, 31, 30, 0, 31, 39, 37, 30, 0, 31, 30, 0, 29, 41, 0, 29, 28, 0, 29, 43, 41, 28, 0, 29, 28, 0, 22, 27, 24, 45, 23, 23, 0, 22, 27, 24, 26, 23, 23, 0, 22, 27, 47, 24, 45, 26, 23, 23, 0, 22, 27, 24, 26, 23, 23, 23, 0, 22, 24, 49, 23, 23, 23, 0, 22, 24, 50, 23, 23, 23, 0, 22, 51, 24, 23, 23, 23, 0, 22, 52, 23, 23, 23, 0, 185, 25, 53, 25, 53, 25, 25, 53, 25, 0, 57, 197, 54, 54, 54, 0, 57, 55, 55, 55, 0, 57, 56, 56, 56, 0, 57, 0, 124, 58, 58, 58, 0, 62, 59, 59, 59, 0, 62, 60, 60, 60, 0, 62, 61, 61, 61, 0, 62, 0, 124, 63, 63, 63, 0, 67, 64, 64, 64, 0, 67, 65, 65, 65, 0, 67, 66, 66, 66, 0, 67, 0, 124, 68, 68, 68, 0, 72, 69, 69, 69, 0, 72, 70, 70, 70, 0, 72, 71, 71, 71, 0, 72, 0, 124, 73, 73, 73, 0, 77, 74, 74, 74, 0, 77, 75, 75, 75, 0, 77, 76, 76, 76, 0, 77, 0, 98, 78, 78, 78, 0, 82, 79, 79, 79, 0, 82, 80, 80, 80, 0, 82, 81, 81, 81, 0, 82, 0, 83, 91, 94, 98, 97, 123, 123, 0, 27, 87, 84, 84, 84, 0, 87, 85, 85, 85, 0, 87, 86, 86, 86, 0, 87, 0, 88, 88, 88, 0, 197, 89, 89, 89, 0, 197, 90, 90, 90, 0, 197, 25, 25, 25, 0, 27, 87, 92, 84, 84, 0, 27, 87, 93, 85, 85, 0, 27, 87, 86, 86, 86, 0, 27, 95, 87, 92, 96, 84, 84, 0, 27, 87, 93, 85, 85, 85, 0, 27, 87, 85, 85, 85, 0, 27, 87, 96, 84, 84, 0, 197, 99, 99, 99, 0, 103, 197, 100, 100, 100, 0, 103, 197, 101, 101, 101, 0, 103, 197, 102, 102, 102, 0, 103, 197, 0, 104, 104, 104, 0, 108, 197, 105, 105, 105, 0, 108, 197, 106, 106, 106, 0, 108, 197, 107, 107, 107, 0, 108, 197, 0, 109, 109, 109, 0, 113, 197, 110, 110, 110, 0, 113, 197, 111, 111, 111, 0, 113, 197, 112, 112, 112, 0, 113, 197, 0, 114, 114, 114, 0, 118, 197, 115, 115, 115, 0, 118, 197, 116, 116, 116, 0, 118, 197, 117, 117, 117, 0, 118, 197, 0, 119, 119, 119, 0, 87, 197, 120, 120, 120, 0, 87, 197, 121, 121, 121, 0, 87, 197, 122, 122, 122, 0, 87, 197, 0, 87, 84, 84, 84, 0, 125, 177, 180, 197, 183, 184, 184, 0, 27, 129, 197, 126, 126, 126, 0, 129, 197, 127, 127, 127, 0, 129, 197, 128, 128, 128, 0, 129, 197, 0, 130, 169, 172, 175, 176, 176, 0, 27, 134, 197, 131, 131, 131, 0, 134, 197, 132, 132, 132, 0, 134, 197, 133, 133, 133, 0, 134, 197, 0, 135, 161, 164, 167, 168, 168, 0, 27, 139, 197, 136, 136, 136, 0, 139, 197, 137, 137, 137, 0, 139, 197, 138, 138, 138, 0, 139, 197, 0, 140, 153, 156, 159, 160, 160, 0, 27, 144, 197, 141, 141, 141, 0, 144, 197, 142, 142, 142, 0, 144, 197, 143, 143, 143, 0, 144, 197, 0, 145, 146, 149, 152, 119, 119, 0, 27, 87, 197, 120, 120, 120, 0, 27, 87, 197, 147, 120, 120, 0, 27, 87, 197, 148, 121, 121, 0, 27, 87, 197, 122, 122, 122, 0, 27, 150, 87, 197, 147, 151, 120, 120, 0, 27, 87, 197, 148, 121, 121, 121, 0, 27, 87, 197, 121, 121, 121, 0, 27, 87, 197, 151, 120, 120, 0, 27, 144, 197, 154, 141, 141, 0, 27, 144, 197, 155, 142, 142, 0, 27, 144, 197, 143, 143, 143, 0, 27, 157, 144, 197, 154, 158, 141, 141, 0, 27, 144, 197, 155, 142, 142, 142, 0, 27, 144, 197, 142, 142, 142, 0, 27, 144, 197, 158, 141, 141, 0, 144, 197, 141, 141, 141, 0, 27, 139, 197, 162, 136, 136, 0, 27, 139, 197, 163, 137, 137, 0, 27, 139, 197, 138, 138, 138, 0, 27, 165, 139, 197, 162, 166, 136, 136, 0, 27, 139, 197, 163, 137, 137, 137, 0, 27, 139, 197, 137, 137, 137, 0, 27, 139, 197, 166, 136, 136, 0, 139, 197, 136, 136, 136, 0, 27, 134, 197, 170, 131, 131, 0, 27, 134, 197, 171, 132, 132, 0, 27, 134, 197, 133, 133, 133, 0, 27, 173, 134, 197, 170, 174, 131, 131, 0, 27, 134, 197, 171, 132, 132, 132, 0, 27, 134, 197, 132, 132, 132, 0, 27, 134, 197, 174, 131, 131, 0, 134, 197, 131, 131, 131, 0, 27, 129, 197, 178, 126, 126, 0, 27, 129, 197, 179, 127, 127, 0, 27, 129, 197, 128, 128, 128, 0, 27, 181, 129, 197, 178, 182, 126, 126, 0, 27, 129, 197, 179, 127, 127, 127, 0, 27, 129, 197, 127, 127, 127, 0, 27, 129, 197, 182, 126, 126, 0, 129, 197, 126, 126, 126, 0, 124, 197, 0, 188, 190, 191, 193, 194, 195, 187, 189, 192, 186, 0, 186, 0, 187, 0, 187, 0, 187, 0, 189, 0, 189, 0, 189, 0, 11, 0, 186, 0, 13, 15, 16, 18, 19, 20, 12, 14, 17, 196, 196, 196, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 0}; static const signed char _address_cond_actions[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 3, 0, 3, 0, 3, 0, 3, 0, 3, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 3, 1, 3, 0, 3, 0, 3, 0, 3, 0, 3, 0, 3, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 3, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 3, 0, 0, 3, 1, 3, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 3, 0, 0, 0, 0, 3, 0, 3, 0, 0, 0, 0, 3, 1, 0, 3, 1, 0, 3, 0, 1, 0, 0, 3, 1, 0, 3, 0, 0, 3, 0, 0, 3, 0, 0, 0, 0, 3, 0, 0, 3, 0, 0, 3, 0, 0, 3, 0, 0, 0, 0, 3, 0, 0, 3, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 3, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 3, 0, 0, 0, 3, 1, 0, 0, 0, 3, 1, 0, 0, 0, 3, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 3, 1, 0, 0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 1, 3, 0, 0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 1, 3, 0, 0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 1, 3, 0, 0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 1, 3, 0, 0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 1, 3, 0, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 1, 3, 0, 0, 0, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 1, 3, 0, 0, 0, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 1, 3, 0, 0, 0, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 1, 3, 0, 0, 0, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 3, 0, 3, 0, 3, 0, 3, 0, 3, 0, 3, 0, 3, 0, 3, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0}; static const short _address_eof_trans[] = { 1086, 1087, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100, 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 1120, 1121, 1122, 1123, 1124, 1125, 1126, 1127, 1128, 1129, 1130, 1131, 1132, 1133, 1134, 1135, 1136, 1137, 1138, 1139, 1140, 1141, 1142, 1143, 1144, 1145, 1146, 1147, 1148, 1149, 1150, 1151, 1152, 1153, 1154, 1155, 1156, 1157, 1158, 1159, 1160, 1161, 1162, 1163, 1164, 1165, 1166, 1167, 1168, 1169, 1170, 1171, 1172, 1173, 1174, 1175, 1176, 1177, 1178, 1179, 1180, 1181, 1182, 1183, 1184, 1185, 1186, 1187, 1188, 1189, 1190, 1191, 1192, 1193, 1194, 1195, 1196, 1197, 1198, 1199, 1200, 1201, 1202, 1203, 1204, 1205, 1206, 1207, 1208, 1209, 1210, 1211, 1212, 1213, 1214, 1215, 1216, 1217, 1218, 1219, 1220, 1221, 1222, 1223, 1224, 1225, 1226, 1227, 1228, 1229, 1230, 1231, 1232, 1233, 1234, 1235, 1236, 1237, 1238, 1239, 1240, 1241, 1242, 1243, 1244, 1245, 1246, 1247, 1248, 1249, 1250, 1251, 1252, 1253, 1254, 1255, 1256, 1257, 1258, 1259, 1260, 1261, 1262, 1263, 1264, 1265, 1266, 1267, 1268, 1269, 1270, 1271, 1272, 1273, 1274, 1275, 1276, 1277, 1278, 1279, 1280, 1281, 1282, 1283, 0}; static const int address_start = 1; bool is_address(const char *p, const char *pe) { int cs = 0; const char *eof = pe; bool result = false; { cs = (int) address_start; } { int _klen; unsigned int _trans = 0; const signed char *_keys; const signed char *_acts; unsigned int _nacts; _resume: { } if (p == pe && p != eof) goto _out; if (p == eof) { if (_address_eof_trans[cs] > 0) { _trans = (unsigned int) _address_eof_trans[cs] - 1; } } else { _keys = (_address_trans_keys + (_address_key_offsets[cs])); _trans = (unsigned int) _address_index_offsets[cs]; _klen = (int) _address_single_lengths[cs]; if (_klen > 0) { const signed char *_lower = _keys; const signed char *_upper = _keys + _klen - 1; const signed char *_mid; while (1) { if (_upper < _lower) { _keys += _klen; _trans += (unsigned int) _klen; break; } _mid = _lower + ((_upper - _lower) >> 1); if (((*(p))) < (*(_mid))) _upper = _mid - 1; else if (((*(p))) > (*(_mid))) _lower = _mid + 1; else { _trans += (unsigned int) (_mid - _keys); goto _match; } } } _klen = (int) _address_range_lengths[cs]; if (_klen > 0) { const signed char *_lower = _keys; const signed char *_upper = _keys + (_klen << 1) - 2; const signed char *_mid; while (1) { if (_upper < _lower) { _trans += (unsigned int) _klen; break; } _mid = _lower + (((_upper - _lower) >> 1) & ~1); if (((*(p))) < (*(_mid))) _upper = _mid - 2; else if (((*(p))) > (*(_mid + 1))) _lower = _mid + 2; else { _trans += (unsigned int) ((_mid - _keys) >> 1); break; } } } _match: { } } cs = (int) _address_cond_targs[_trans]; if (_address_cond_actions[_trans] != 0) { _acts = (_address_actions + (_address_cond_actions[_trans])); _nacts = (unsigned int) (*(_acts)); _acts += 1; while (_nacts > 0) { switch ((*(_acts))) { case 0: { { result = true; } break; } case 1: { { result = false; } break; } } _nacts -= 1; _acts += 1; } } if (p == eof) { if (cs >= 196) goto _out; } else { if (cs != 0) { p += 1; goto _resume; } } _out: { } } return result; } ================================================ FILE: src/smtp-address-validator.hpp ================================================ #ifndef SMTP_ADDRESS_PARSER_HPP_INCLUDED #define SMTP_ADDRESS_PARSER_HPP_INCLUDED /* Snarfed from : Copyright (c) 2021 Gene Hightower Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ bool is_address(const char *p, const char *pe); #endif // SMTP_ADDRESS_PARSER_HPP_INCLUDED ================================================ FILE: src/string-format-check.cpp ================================================ #include #include "smtp-address-validator.hpp" #include #include #include #include #include #include #include #include #ifdef JSON_SCHEMA_BOOST_REGEX # include # define REGEX_NAMESPACE boost #elif defined(JSON_SCHEMA_NO_REGEX) # define NO_STD_REGEX #else # include # define REGEX_NAMESPACE std #endif /** * Many of the RegExes are from @see http://jmrware.com/articles/2009/uri_regexp/URI_regex.html */ namespace { template void range_check(const T value, const T min, const T max) { if (!((value >= min) && (value <= max))) { std::stringstream out; out << "Value " << value << " should be in interval [" << min << "," << max << "] but is not!"; throw std::invalid_argument(out.str()); } } /** @see date_time_check */ void rfc3339_date_check(const std::string &value) { const static REGEX_NAMESPACE::regex dateRegex{R"(^([0-9]{4})\-([0-9]{2})\-([0-9]{2})$)"}; REGEX_NAMESPACE::smatch matches; if (!REGEX_NAMESPACE::regex_match(value, matches, dateRegex)) { throw std::invalid_argument(value + " is not a date string according to RFC 3339."); } const auto year = std::stoi(matches[1].str()); const auto month = std::stoi(matches[2].str()); const auto mday = std::stoi(matches[3].str()); const auto isLeapYear = (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)); range_check(month, 1, 12); if (month == 2) { range_check(mday, 1, isLeapYear ? 29 : 28); } else if (month <= 7) { range_check(mday, 1, month % 2 == 0 ? 30 : 31); } else { range_check(mday, 1, month % 2 == 0 ? 31 : 30); } } /** @see date_time_check */ void rfc3339_time_check(const std::string &value) { const static REGEX_NAMESPACE::regex timeRegex{R"(^([0-9]{2})\:([0-9]{2})\:([0-9]{2})(\.[0-9]+)?(?:[Zz]|((?:\+|\-)[0-9]{2})\:([0-9]{2}))$)"}; REGEX_NAMESPACE::smatch matches; if (!REGEX_NAMESPACE::regex_match(value, matches, timeRegex)) { throw std::invalid_argument(value + " is not a time string according to RFC 3339."); } auto hour = std::stoi(matches[1].str()); auto minute = std::stoi(matches[2].str()); auto second = std::stoi(matches[3].str()); // const auto secfrac = std::stof( matches[4].str() ); range_check(hour, 0, 23); range_check(minute, 0, 59); int offsetHour = 0, offsetMinute = 0; /* don't check the numerical offset if time zone is specified as 'Z' */ if (!matches[5].str().empty()) { offsetHour = std::stoi(matches[5].str()); offsetMinute = std::stoi(matches[6].str()); range_check(offsetHour, -23, 23); range_check(offsetMinute, 0, 59); if (offsetHour < 0) offsetMinute *= -1; } /** * @todo Could be made more exact by querying a leap second database and choosing the * correct maximum in {58,59,60}. This current solution might match some invalid dates * but it won't lead to false negatives. This only works if we know the full date, however */ auto day_minutes = hour * 60 + minute - (offsetHour * 60 + offsetMinute); if (day_minutes < 0) day_minutes += 60 * 24; hour = day_minutes % 24; minute = day_minutes / 24; if (hour == 23 && minute == 59) range_check(second, 0, 60); // possible leap-second else range_check(second, 0, 59); } /** * @see https://tools.ietf.org/html/rfc3339#section-5.6 * * @verbatim * date-fullyear = 4DIGIT * date-month = 2DIGIT ; 01-12 * date-mday = 2DIGIT ; 01-28, 01-29, 01-30, 01-31 based on * ; month/year * time-hour = 2DIGIT ; 00-23 * time-minute = 2DIGIT ; 00-59 * time-second = 2DIGIT ; 00-58, 00-59, 00-60 based on leap second * ; rules * time-secfrac = "." 1*DIGIT * time-numoffset = ("+" / "-") time-hour ":" time-minute * time-offset = "Z" / time-numoffset * * partial-time = time-hour ":" time-minute ":" time-second * [time-secfrac] * full-date = date-fullyear "-" date-month "-" date-mday * full-time = partial-time time-offset * * date-time = full-date "T" full-time * @endverbatim * NOTE: Per [ABNF] and ISO8601, the "T" and "Z" characters in this * syntax may alternatively be lower case "t" or "z" respectively. */ void rfc3339_date_time_check(const std::string &value) { const static REGEX_NAMESPACE::regex dateTimeRegex{R"(^([0-9]{4}\-[0-9]{2}\-[0-9]{2})[Tt]([0-9]{2}\:[0-9]{2}\:[0-9]{2}(?:\.[0-9]+)?(?:[Zz]|(?:\+|\-)[0-9]{2}\:[0-9]{2}))$)"}; REGEX_NAMESPACE::smatch matches; if (!REGEX_NAMESPACE::regex_match(value, matches, dateTimeRegex)) { throw std::invalid_argument(value + " is not a date-time string according to RFC 3339."); } rfc3339_date_check(matches[1].str()); rfc3339_time_check(matches[2].str()); } const std::string decOctet{R"((?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9]))"}; // matches numbers 0-255 const std::string ipv4Address{"(?:" + decOctet + R"(\.){3})" + decOctet}; const std::string h16{R"([0-9A-Fa-f]{1,4})"}; const std::string h16Left{"(?:" + h16 + ":)"}; const std::string ipv6Address{ "(?:" "(?:" + h16Left + "{6}" "|::" + h16Left + "{5}" "|(?:" + h16 + ")?::" + h16Left + "{4}" "|(?:" + h16Left + "{0,1}" + h16 + ")?::" + h16Left + "{3}" "|(?:" + h16Left + "{0,2}" + h16 + ")?::" + h16Left + "{2}" "|(?:" + h16Left + "{0,3}" + h16 + ")?::" + h16Left + "|(?:" + h16Left + "{0,4}" + h16 + ")?::" ")(?:" + h16Left + h16 + "|" + ipv4Address + ")" "|(?:" + h16Left + "{0,5}" + h16 + ")?::" + h16 + "|(?:" + h16Left + "{0,6}" + h16 + ")?::" ")"}; const std::string ipvFuture{R"([Vv][0-9A-Fa-f]+\.[A-Za-z0-9\-._~!$&'()*+,;=:]+)"}; const std::string regName{R"((?:[A-Za-z0-9\-._~!$&'()*+,;=]|%[0-9A-Fa-f]{2})*)"}; const std::string host{ "(?:" R"(\[(?:)" + ipv6Address + "|" + ipvFuture + R"()\])" + "|" + ipv4Address + "|" + regName + ")"}; const std::string uuid{R"([0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12})"}; // from http://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address const std::string hostname{R"(^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$)"}; bool is_ascii(std::string const &value) { for (auto ch : value) { if (ch & 0x80) { return false; } } return true; } /** * @see * * @verbatim * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] * * hier-part = "//" authority path-abempty * / path-absolute * / path-rootless * / path-empty * * URI-reference = URI / relative-ref * * absolute-URI = scheme ":" hier-part [ "?" query ] * * relative-ref = relative-part [ "?" query ] [ "#" fragment ] * * relative-part = "//" authority path-abempty * / path-absolute * / path-noscheme * / path-empty * * scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) * * authority = [ userinfo "@" ] host [ ":" port ] * userinfo = *( unreserved / pct-encoded / sub-delims / ":" ) * host = IP-literal / IPv4address / reg-name * port = *DIGIT * * IP-literal = "[" ( IPv6address / IPvFuture ) "]" * * IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" ) * * IPv6address = 6( h16 ":" ) ls32 * / "::" 5( h16 ":" ) ls32 * / [ h16 ] "::" 4( h16 ":" ) ls32 * / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32 * / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32 * / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32 * / [ *4( h16 ":" ) h16 ] "::" ls32 * / [ *5( h16 ":" ) h16 ] "::" h16 * / [ *6( h16 ":" ) h16 ] "::" * * h16 = 1*4HEXDIG * ls32 = ( h16 ":" h16 ) / IPv4address * IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet * dec-octet = DIGIT ; 0-9 * / %x31-39 DIGIT ; 10-99 * / "1" 2DIGIT ; 100-199 * / "2" %x30-34 DIGIT ; 200-249 * / "25" %x30-35 ; 250-255 * * reg-name = *( unreserved / pct-encoded / sub-delims ) * * path = path-abempty ; begins with "/" or is empty * / path-absolute ; begins with "/" but not "//" * / path-noscheme ; begins with a non-colon segment * / path-rootless ; begins with a segment * / path-empty ; zero characters * * path-abempty = *( "/" segment ) * path-absolute = "/" [ segment-nz *( "/" segment ) ] * path-noscheme = segment-nz-nc *( "/" segment ) * path-rootless = segment-nz *( "/" segment ) * path-empty = 0 * * segment = *pchar * segment-nz = 1*pchar * segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" ) * ; non-zero-length segment without any colon ":" * * pchar = unreserved / pct-encoded / sub-delims / ":" / "@" * * query = *( pchar / "/" / "?" ) * * fragment = *( pchar / "/" / "?" ) * * pct-encoded = "%" HEXDIG HEXDIG * * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" * reserved = gen-delims / sub-delims * gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@" * sub-delims = "!" / "$" / "&" / "'" / "(" / ")" * / "*" / "+" / "," / ";" / "=" * * @endverbatim * @see adapted from: https://github.com/jhermsmeier/uri.regex/blob/master/uri.regex * */ void rfc3986_uri_check(const std::string &value) { const static std::string scheme{R"(([A-Za-z][A-Za-z0-9+\-.]*):)"}; const static std::string hierPart{ R"((?:(\/\/)(?:((?:[A-Za-z0-9\-._~!$&'()*+,;=:]|)" R"(%[0-9A-Fa-f]{2})*)@)?((?:\[(?:(?:(?:(?:[0-9A-Fa-f]{1,4}:){6}|)" R"(::(?:[0-9A-Fa-f]{1,4}:){5}|)" R"((?:[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){4}|)" R"((?:(?:[0-9A-Fa-f]{1,4}:){0,1}[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){3}|)" R"((?:(?:[0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){2}|)" R"((?:(?:[0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})?::[0-9A-Fa-f]{1,4}:|)" R"((?:(?:[0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})?::)(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|)" R"((?:(?:25[0-5]|2[0-4][0-9]|)" R"([01]?[0-9][0-9]?)\.){3}(?:25[0-5]|)" R"(2[0-4][0-9]|)" R"([01]?[0-9][0-9]?))|)" R"((?:(?:[0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})?::[0-9A-Fa-f]{1,4}|)" R"((?:(?:[0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})?::)|)" R"([Vv][0-9A-Fa-f]+\.[A-Za-z0-9\-._~!$&'()*+,;=:]+)\]|)" R"((?:(?:25[0-5]|)" R"(2[0-4][0-9]|)" R"([01]?[0-9][0-9]?)\.){3}(?:25[0-5]|)" R"(2[0-4][0-9]|)" R"([01]?[0-9][0-9]?)|)" R"((?:[A-Za-z0-9\-._~!$&'()*+,;=]|)" R"(%[0-9A-Fa-f]{2})*))(?::([0-9]*))?((?:\/(?:[A-Za-z0-9\-._~!$&'()*+,;=:@]|)" R"(%[0-9A-Fa-f]{2})*)*)|)" R"(\/((?:(?:[A-Za-z0-9\-._~!$&'()*+,;=:@]|)" R"(%[0-9A-Fa-f]{2})+(?:\/(?:[A-Za-z0-9\-._~!$&'()*+,;=:@]|)" R"(%[0-9A-Fa-f]{2})*)*)?)|)" R"(((?:[A-Za-z0-9\-._~!$&'()*+,;=:@]|)" R"(%[0-9A-Fa-f]{2})+(?:\/(?:[A-Za-z0-9\-._~!$&'()*+,;=:@]|)" R"(%[0-9A-Fa-f]{2})*)*)|))"}; const static std::string query{R"((?:\?((?:[A-Za-z0-9\-._~!$&'()*+,;=:@\/?]|%[0-9A-Fa-f]{2})*))?)"}; const static std::string fragment{ R"((?:\#((?:[A-Za-z0-9\-._~!$&'()*+,;=:@\/?]|%[0-9A-Fa-f]{2})*))?)"}; const static std::string uriFormat{scheme + hierPart + query + fragment}; const static REGEX_NAMESPACE::regex uriRegex{uriFormat}; if (!REGEX_NAMESPACE::regex_match(value, uriRegex)) { throw std::invalid_argument(value + " is not a URI string according to RFC 3986."); } } } // namespace namespace nlohmann { namespace json_schema { /** * Checks validity for built-ins by converting the definitions given as ABNF in the linked RFC from * @see https://json-schema.org/understanding-json-schema/reference/string.html#built-in-formats * into regular expressions using @see https://www.msweet.org/abnf/ and some manual editing. * * @see https://json-schema.org/latest/json-schema-validation.html */ void default_string_format_check(const std::string &format, const std::string &value) { if (format == "date-time") { rfc3339_date_time_check(value); } else if (format == "date") { rfc3339_date_check(value); } else if (format == "time") { rfc3339_time_check(value); } else if (format == "uri") { rfc3986_uri_check(value); } else if (format == "email") { if (!is_ascii(value)) { throw std::invalid_argument(value + " contains non-ASCII values, not RFC 5321 compliant."); } if (!is_address(&*value.begin(), &*value.end())) { throw std::invalid_argument(value + " is not a valid email according to RFC 5321."); } } else if (format == "idn-email") { if (!is_address(&*value.begin(), &*value.end())) { throw std::invalid_argument(value + " is not a valid idn-email according to RFC 6531."); } } else if (format == "hostname") { static const REGEX_NAMESPACE::regex hostRegex{hostname}; if (!REGEX_NAMESPACE::regex_match(value, hostRegex)) { throw std::invalid_argument(value + " is not a valid hostname according to RFC 3986 Appendix A."); } } else if (format == "ipv4") { const static REGEX_NAMESPACE::regex ipv4Regex{"^" + ipv4Address + "$"}; if (!REGEX_NAMESPACE::regex_match(value, ipv4Regex)) { throw std::invalid_argument(value + " is not an IPv4 string according to RFC 2673."); } } else if (format == "ipv6") { static const REGEX_NAMESPACE::regex ipv6Regex{ipv6Address}; if (!REGEX_NAMESPACE::regex_match(value, ipv6Regex)) { throw std::invalid_argument(value + " is not an IPv6 string according to RFC 5954."); } } else if (format == "uuid") { static const REGEX_NAMESPACE::regex uuidRegex{uuid}; if (!REGEX_NAMESPACE::regex_match(value, uuidRegex)) { throw std::invalid_argument(value + " is not an uuid string according to RFC 4122."); } } else if (format == "regex") { try { REGEX_NAMESPACE::regex re(value, std::regex::ECMAScript); } catch (std::exception &exception) { throw exception; } } else { /* yet unsupported JSON schema draft 7 built-ins */ static const std::vector jsonSchemaStringFormatBuiltIns{ "date-time", "time", "date", "email", "idn-email", "hostname", "idn-hostname", "ipv4", "ipv6", "uri", "uri-reference", "iri", "iri-reference", "uri-template", "json-pointer", "relative-json-pointer", "regex"}; if (std::find(jsonSchemaStringFormatBuiltIns.begin(), jsonSchemaStringFormatBuiltIns.end(), format) != jsonSchemaStringFormatBuiltIns.end()) { throw std::logic_error("JSON schema string format built-in " + format + " not yet supported. " + "Please open an issue or use a custom format checker."); } throw std::logic_error("Don't know how to validate " + format); } } } // namespace json_schema } // namespace nlohmann ================================================ FILE: test/CMakeLists.txt ================================================ set(PIPE_IN_TEST_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/test-pipe-in.sh) # simple nlohmann_json_schema_validator-executable add_executable(json-schema-validate json-schema-validate.cpp) target_link_libraries(json-schema-validate nlohmann_json_schema_validator) function(add_test_simple_schema name schema instance) add_test( NAME ${name} COMMAND ${PIPE_IN_TEST_SCRIPT} $ ${schema} ${instance} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) endfunction() file(GLOB TEST_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/*) foreach(DIR ${TEST_DIRS}) if(IS_DIRECTORY ${DIR}) add_subdirectory(${DIR}) endif() endforeach() add_executable(uri uri.cpp) target_link_libraries(uri nlohmann_json_schema_validator) add_test(NAME uri COMMAND uri) add_executable(errors errors.cpp) target_link_libraries(errors nlohmann_json_schema_validator) add_test(NAME errors COMMAND errors) add_executable(issue-70 issue-70.cpp) target_link_libraries(issue-70 nlohmann_json_schema_validator) add_test(NAME issue-70 COMMAND issue-70) add_executable(issue-70-root-schema-constructor issue-70-root-schema-constructor.cpp) target_link_libraries(issue-70-root-schema-constructor nlohmann_json_schema_validator) add_test(NAME issue-70-root-schema-constructor COMMAND issue-70-root-schema-constructor) add_executable(issue-25-default-values issue-25-default-values.cpp) target_link_libraries(issue-25-default-values nlohmann_json_schema_validator) add_test(NAME issue-25-default-values COMMAND issue-25-default-values) add_executable(issue-98 issue-98.cpp) target_link_libraries(issue-98 nlohmann_json_schema_validator) add_test(NAME issue-98-erase-exception-unknown-keywords COMMAND issue-98) add_executable(issue-293 issue-293.cpp) target_link_libraries(issue-293 nlohmann_json_schema_validator) add_test(NAME issue-293-float-point-error COMMAND issue-293) # Unit test for string format checks add_executable(string-format-check-test string-format-check-test.cpp) target_include_directories(string-format-check-test PRIVATE ${PROJECT_SOURCE_DIR}/src/) target_link_libraries(string-format-check-test nlohmann_json_schema_validator) add_test(NAME string-format-check-test COMMAND string-format-check-test) # Unit test for json-patch add_executable(json-patch json-patch.cpp) target_include_directories(json-patch PRIVATE ${PROJECT_SOURCE_DIR}/src) target_link_libraries(json-patch nlohmann_json_schema_validator) add_test(NAME json-patch COMMAND json-patch) # Unit test for format checker fail at schema parsing time add_executable(issue-117-format-error issue-117-format-error.cpp) target_link_libraries(issue-117-format-error nlohmann_json_schema_validator) add_test(NAME issue-117-format-error COMMAND issue-117-format-error) add_executable(binary-validation binary-validation.cpp) target_include_directories(binary-validation PRIVATE ${PROJECT_SOURCE_DIR}/src) target_link_libraries(binary-validation PRIVATE nlohmann_json_schema_validator) add_test(NAME binary-validation COMMAND binary-validation) add_executable(issue-149-entry-selection issue-149-entry-selection.cpp) target_link_libraries(issue-149-entry-selection PRIVATE nlohmann_json_schema_validator) add_test(NAME issue-149-entry-selection COMMAND issue-149-entry-selection) add_executable(issue-189-default-values issue-189-default-values.cpp) target_link_libraries(issue-189-default-values nlohmann_json_schema_validator) add_test(NAME issue-189-default-values COMMAND issue-189-default-values) add_executable(issue-229-oneof-default-values issue-229-oneof-default-values.cpp) target_link_libraries(issue-229-oneof-default-values nlohmann_json_schema_validator) add_test(NAME issue-229-oneof-default-values COMMAND issue-229-oneof-default-values) add_executable(issue-243-root-default-values issue-243-root-default-values.cpp) target_link_libraries(issue-243-root-default-values nlohmann_json_schema_validator) add_test(NAME issue-243-root-default-values COMMAND issue-243-root-default-values) add_executable(issue-255-error-message-limit-precision issue-255-error-message-limit-precision.cpp) target_link_libraries(issue-255-error-message-limit-precision nlohmann_json_schema_validator) add_test(NAME issue-255-error-message-limit-precision COMMAND issue-255-error-message-limit-precision) add_executable(issue-105-verbose-combination-errors issue-105-verbose-combination-errors.cpp) target_link_libraries(issue-105-verbose-combination-errors nlohmann_json_schema_validator) add_test(NAME issue-105-verbose-combination-errors COMMAND issue-105-verbose-combination-errors) ================================================ FILE: test/JSON-Schema-Test-Suite/CMakeLists.txt ================================================ set(JSON_SCHEMA_TEST_PREFIX "JSON-Suite" CACHE STRING "prefix for JSON-tests added to ctest") set(DRAFT "draft7") # find schema-test-suite find_path(JSON_SCHEMA_TEST_SUITE_PATH NAMES tests/${DRAFT}) if (NOT JSON_SCHEMA_TEST_SUITE_PATH) message(STATUS "Set JSON_SCHEMA_TEST_SUITE_PATH to a path in which JSON-Schema-Test-Suite is located (github.com/json-schema-org/JSON-Schema-Test-Suite). Using internal test-suite which might be out of date.") set(JSON_SCHEMA_TEST_SUITE_PATH ${CMAKE_CURRENT_SOURCE_DIR}) endif() if(JSON_SCHEMA_TEST_SUITE_PATH) # json-schema-validator-tester add_executable(json-schema-test json-schema-test.cpp) target_link_libraries(json-schema-test nlohmann_json_schema_validator) target_compile_definitions(json-schema-test PRIVATE JSON_SCHEMA_TEST_SUITE_PATH="${JSON_SCHEMA_TEST_SUITE_PATH}") option(JSON_SCHEMA_ENABLE_OPTIONAL_TESTS "Enable optional tests of the JSONSchema Test Suite" ON) # create tests foreach test-file file(GLOB TEST_FILES ${JSON_SCHEMA_TEST_SUITE_PATH}/tests/${DRAFT}/*.json) foreach(TEST_FILE ${TEST_FILES}) get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) add_test(NAME "${JSON_SCHEMA_TEST_PREFIX}::${TEST_NAME}" COMMAND ${PIPE_IN_TEST_SCRIPT} $ ${TEST_FILE}) endforeach() if (JSON_SCHEMA_ENABLE_OPTIONAL_TESTS) file(GLOB OPT_TEST_FILES ${JSON_SCHEMA_TEST_SUITE_PATH}/tests/${DRAFT}/optional/*.json) file(GLOB FORMAT_TEST_FILES ${JSON_SCHEMA_TEST_SUITE_PATH}/tests/${DRAFT}/optional/format/*.json) foreach(TEST_FILE ${OPT_TEST_FILES}) get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) add_test(NAME "${JSON_SCHEMA_TEST_PREFIX}::Optional::${TEST_NAME}" COMMAND ${PIPE_IN_TEST_SCRIPT} $ ${TEST_FILE}) endforeach() foreach(TEST_FILE ${FORMAT_TEST_FILES}) get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) add_test(NAME "${JSON_SCHEMA_TEST_PREFIX}::Optional::Format::${TEST_NAME}" COMMAND ${PIPE_IN_TEST_SCRIPT} $ ${TEST_FILE}) endforeach() # some optional tests will fail set_tests_properties( JSON-Suite::Optional::bignum JSON-Suite::Optional::non-bmp-regex JSON-Suite::Optional::float-overflow JSON-Suite::Optional::ecmascript-regex JSON-Suite::Optional::Format::idn-hostname JSON-Suite::Optional::Format::iri-reference JSON-Suite::Optional::Format::iri JSON-Suite::Optional::Format::json-pointer JSON-Suite::Optional::Format::relative-json-pointer JSON-Suite::Optional::Format::uri-reference JSON-Suite::Optional::Format::uri-template JSON-Suite::Optional::unicode PROPERTIES WILL_FAIL ON) endif() else() endif() ================================================ FILE: test/JSON-Schema-Test-Suite/json-schema-test.cpp ================================================ /* * JSON schema validator for JSON for modern C++ * * Copyright (c) 2016-2019 Patrick Boettcher . * * SPDX-License-Identifier: MIT * */ #include #include #include #include using nlohmann::json; using nlohmann::json_uri; using nlohmann::json_schema::json_validator; static void loader(const json_uri &uri, json &schema) { if (uri.location() == "http://json-schema.org/draft-07/schema") { schema = nlohmann::json_schema::draft7_schema_builtin; return; } std::string fn = JSON_SCHEMA_TEST_SUITE_PATH; fn += "/remotes"; fn += uri.path(); std::cerr << fn << "\n"; std::fstream s(fn.c_str()); if (!s.good()) throw std::invalid_argument("could not open " + uri.url() + " for schema loading\n"); try { s >> schema; } catch (std::exception &e) { throw e; } } // from here // https://stackoverflow.com/a/34571089/880584 static std::string base64_decode(const std::string &in) { std::string out; std::vector T(256, -1); for (int i = 0; i < 64; i++) T["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[i]] = i; unsigned val = 0; int valb = -8; for (uint8_t c : in) { if (c == '=') break; if (T[c] == -1) { throw std::invalid_argument("base64-decode: unexpected character in encode string: '" + std::string(1, c) + "'"); } val = (val << 6) + T[c]; valb += 6; if (valb >= 0) { out.push_back(char((val >> valb) & 0xFF)); valb -= 8; } } return out; } static void content(const std::string &contentEncoding, const std::string &contentMediaType, const json &instance) { std::string content = instance; if (contentEncoding == "base64") content = base64_decode(instance); else if (contentEncoding != "") throw std::invalid_argument("unable to check for contentEncoding '" + contentEncoding + "'"); if (contentMediaType == "application/json") auto dummy = json::parse(content); // throws if conversion fails else if (contentMediaType != "") throw std::invalid_argument("unable to check for contentMediaType '" + contentMediaType + "'"); } int main(void) { json validation; // a validation case following the JSON-test-suite-schema try { std::cin >> validation; } catch (std::exception &e) { std::cout << e.what() << "\n"; return EXIT_FAILURE; } size_t total_failed = 0, total = 0; for (auto &test_group : validation) { size_t group_failed = 0, group_total = 0; std::cout << "Testing Group " << test_group["description"] << "\n"; const auto &schema = test_group["schema"]; json_validator validator(loader, nlohmann::json_schema::default_string_format_check, content); validator.set_root_schema(schema); for (auto &test_case : test_group["tests"]) { std::cout << " Testing Case " << test_case["description"] << "\n"; bool valid = true; try { validator.validate(test_case["data"]); } catch (const std::out_of_range &e) { valid = false; std::cout << " Test Case Exception (out of range): " << e.what() << "\n"; } catch (const std::invalid_argument &e) { valid = false; std::cout << " Test Case Exception (invalid argument): " << e.what() << "\n"; } catch (const std::logic_error &e) { valid = !test_case["valid"]; /* force test-case failure */ std::cout << " Not yet implemented: " << e.what() << "\n"; } if (valid == test_case["valid"]) std::cout << " --> Test Case exited with " << valid << " as expected.\n"; else { group_failed++; std::cout << " --> Test Case exited with " << valid << " NOT expected.\n"; } group_total++; std::cout << "\n"; } total_failed += group_failed; total += group_total; std::cout << "Group RESULT: " << test_group["description"] << " " << (group_total - group_failed) << " of " << group_total << " have succeeded - " << group_failed << " failed\n"; std::cout << "-------------\n"; } std::cout << "Total RESULT: " << (total - total_failed) << " of " << total << " have succeeded - " << total_failed << " failed\n"; return total_failed; } ================================================ FILE: test/JSON-Schema-Test-Suite/remotes/baseUriChange/folderInteger.json ================================================ { "type": "integer" } ================================================ FILE: test/JSON-Schema-Test-Suite/remotes/baseUriChangeFolder/folderInteger.json ================================================ { "type": "integer" } ================================================ FILE: test/JSON-Schema-Test-Suite/remotes/baseUriChangeFolderInSubschema/folderInteger.json ================================================ { "type": "integer" } ================================================ FILE: test/JSON-Schema-Test-Suite/remotes/folder/folderInteger.json ================================================ { "type": "integer" } ================================================ FILE: test/JSON-Schema-Test-Suite/remotes/integer.json ================================================ { "type": "integer" } ================================================ FILE: test/JSON-Schema-Test-Suite/remotes/name-defs.json ================================================ { "$defs": { "orNull": { "anyOf": [ { "type": "null" }, { "$ref": "#" } ] } }, "type": "string" } ================================================ FILE: test/JSON-Schema-Test-Suite/remotes/name.json ================================================ { "definitions": { "orNull": { "anyOf": [ { "type": "null" }, { "$ref": "#" } ] } }, "type": "string" } ================================================ FILE: test/JSON-Schema-Test-Suite/remotes/ref-and-definitions.json ================================================ { "$id": "http://localhost:1234/ref-and-definitions.json", "definitions": { "inner": { "properties": { "bar": { "type": "string" } } } }, "allOf": [ { "$ref": "#/definitions/inner" } ] } ================================================ FILE: test/JSON-Schema-Test-Suite/remotes/ref-and-defs.json ================================================ { "$id": "http://localhost:1234/ref-and-defs.json", "$defs": { "inner": { "properties": { "bar": { "type": "string" } } } }, "$ref": "#/$defs/inner" } ================================================ FILE: test/JSON-Schema-Test-Suite/remotes/subSchemas-defs.json ================================================ { "$defs": { "integer": { "type": "integer" }, "refToInteger": { "$ref": "#/$defs/integer" } } } ================================================ FILE: test/JSON-Schema-Test-Suite/remotes/subSchemas.json ================================================ { "integer": { "type": "integer" }, "refToInteger": { "$ref": "#/integer" } } ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/additionalItems.json ================================================ [ { "description": "additionalItems as schema", "schema": { "items": [{}], "additionalItems": {"type": "integer"} }, "tests": [ { "description": "additional items match schema", "data": [ null, 2, 3, 4 ], "valid": true }, { "description": "additional items do not match schema", "data": [ null, 2, 3, "foo" ], "valid": false } ] }, { "description": "when items is schema, additionalItems does nothing", "schema": { "items": {}, "additionalItems": false }, "tests": [ { "description": "all items match schema", "data": [ 1, 2, 3, 4, 5 ], "valid": true } ] }, { "description": "array of items with no additionalItems permitted", "schema": { "items": [{}, {}, {}], "additionalItems": false }, "tests": [ { "description": "empty array", "data": [ ], "valid": true }, { "description": "fewer number of items present (1)", "data": [ 1 ], "valid": true }, { "description": "fewer number of items present (2)", "data": [ 1, 2 ], "valid": true }, { "description": "equal number of items present", "data": [ 1, 2, 3 ], "valid": true }, { "description": "additional items are not permitted", "data": [ 1, 2, 3, 4 ], "valid": false } ] }, { "description": "additionalItems as false without items", "schema": {"additionalItems": false}, "tests": [ { "description": "items defaults to empty schema so everything is valid", "data": [ 1, 2, 3, 4, 5 ], "valid": true }, { "description": "ignores non-arrays", "data": {"foo" : "bar"}, "valid": true } ] }, { "description": "additionalItems are allowed by default", "schema": {"items": [{"type": "integer"}]}, "tests": [ { "description": "only the first item is validated", "data": [1, "foo", false], "valid": true } ] }, { "description": "additionalItems should not look in applicators, valid case", "schema": { "allOf": [ { "items": [ { "type": "integer" } ] } ], "additionalItems": { "type": "boolean" } }, "tests": [ { "description": "items defined in allOf are not examined", "data": [ 1, null ], "valid": true } ] }, { "description": "additionalItems should not look in applicators, invalid case", "schema": { "allOf": [ { "items": [ { "type": "integer" }, { "type": "string" } ] } ], "items": [ {"type": "integer" } ], "additionalItems": { "type": "boolean" } }, "tests": [ { "description": "items defined in allOf are not examined", "data": [ 1, "hello" ], "valid": false } ] }, { "description": "items validation adjusts the starting index for additionalItems", "schema": { "items": [ { "type": "string" } ], "additionalItems": { "type": "integer" } }, "tests": [ { "description": "valid items", "data": [ "x", 2, 3 ], "valid": true }, { "description": "wrong type of second item", "data": [ "x", "y" ], "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/additionalProperties.json ================================================ [ { "description": "additionalProperties being false does not allow other properties", "schema": { "properties": {"foo": {}, "bar": {}}, "patternProperties": { "^v": {} }, "additionalProperties": false }, "tests": [ { "description": "no additional properties is valid", "data": {"foo": 1}, "valid": true }, { "description": "an additional property is invalid", "data": {"foo" : 1, "bar" : 2, "quux" : "boom"}, "valid": false }, { "description": "ignores arrays", "data": [1, 2, 3], "valid": true }, { "description": "ignores strings", "data": "foobarbaz", "valid": true }, { "description": "ignores other non-objects", "data": 12, "valid": true }, { "description": "patternProperties are not additional properties", "data": {"foo":1, "vroom": 2}, "valid": true } ] }, { "description": "non-ASCII pattern with additionalProperties", "schema": { "patternProperties": {"^á": {}}, "additionalProperties": false }, "tests": [ { "description": "matching the pattern is valid", "data": {"ármányos": 2}, "valid": true }, { "description": "not matching the pattern is invalid", "data": {"élmény": 2}, "valid": false } ] }, { "description": "additionalProperties allows a schema which should validate", "schema": { "properties": {"foo": {}, "bar": {}}, "additionalProperties": {"type": "boolean"} }, "tests": [ { "description": "no additional properties is valid", "data": {"foo": 1}, "valid": true }, { "description": "an additional valid property is valid", "data": {"foo" : 1, "bar" : 2, "quux" : true}, "valid": true }, { "description": "an additional invalid property is invalid", "data": {"foo" : 1, "bar" : 2, "quux" : 12}, "valid": false } ] }, { "description": "additionalProperties can exist by itself", "schema": { "additionalProperties": {"type": "boolean"} }, "tests": [ { "description": "an additional valid property is valid", "data": {"foo" : true}, "valid": true }, { "description": "an additional invalid property is invalid", "data": {"foo" : 1}, "valid": false } ] }, { "description": "additionalProperties are allowed by default", "schema": {"properties": {"foo": {}, "bar": {}}}, "tests": [ { "description": "additional properties are allowed", "data": {"foo": 1, "bar": 2, "quux": true}, "valid": true } ] }, { "description": "additionalProperties should not look in applicators", "schema": { "allOf": [ {"properties": {"foo": {}}} ], "additionalProperties": {"type": "boolean"} }, "tests": [ { "description": "properties defined in allOf are not examined", "data": {"foo": 1, "bar": true}, "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/allOf.json ================================================ [ { "description": "allOf", "schema": { "allOf": [ { "properties": { "bar": {"type": "integer"} }, "required": ["bar"] }, { "properties": { "foo": {"type": "string"} }, "required": ["foo"] } ] }, "tests": [ { "description": "allOf", "data": {"foo": "baz", "bar": 2}, "valid": true }, { "description": "mismatch second", "data": {"foo": "baz"}, "valid": false }, { "description": "mismatch first", "data": {"bar": 2}, "valid": false }, { "description": "wrong type", "data": {"foo": "baz", "bar": "quux"}, "valid": false } ] }, { "description": "allOf with base schema", "schema": { "properties": {"bar": {"type": "integer"}}, "required": ["bar"], "allOf" : [ { "properties": { "foo": {"type": "string"} }, "required": ["foo"] }, { "properties": { "baz": {"type": "null"} }, "required": ["baz"] } ] }, "tests": [ { "description": "valid", "data": {"foo": "quux", "bar": 2, "baz": null}, "valid": true }, { "description": "mismatch base schema", "data": {"foo": "quux", "baz": null}, "valid": false }, { "description": "mismatch first allOf", "data": {"bar": 2, "baz": null}, "valid": false }, { "description": "mismatch second allOf", "data": {"foo": "quux", "bar": 2}, "valid": false }, { "description": "mismatch both", "data": {"bar": 2}, "valid": false } ] }, { "description": "allOf simple types", "schema": { "allOf": [ {"maximum": 30}, {"minimum": 20} ] }, "tests": [ { "description": "valid", "data": 25, "valid": true }, { "description": "mismatch one", "data": 35, "valid": false } ] }, { "description": "allOf with boolean schemas, all true", "schema": {"allOf": [true, true]}, "tests": [ { "description": "any value is valid", "data": "foo", "valid": true } ] }, { "description": "allOf with boolean schemas, some false", "schema": {"allOf": [true, false]}, "tests": [ { "description": "any value is invalid", "data": "foo", "valid": false } ] }, { "description": "allOf with boolean schemas, all false", "schema": {"allOf": [false, false]}, "tests": [ { "description": "any value is invalid", "data": "foo", "valid": false } ] }, { "description": "allOf with one empty schema", "schema": { "allOf": [ {} ] }, "tests": [ { "description": "any data is valid", "data": 1, "valid": true } ] }, { "description": "allOf with two empty schemas", "schema": { "allOf": [ {}, {} ] }, "tests": [ { "description": "any data is valid", "data": 1, "valid": true } ] }, { "description": "allOf with the first empty schema", "schema": { "allOf": [ {}, { "type": "number" } ] }, "tests": [ { "description": "number is valid", "data": 1, "valid": true }, { "description": "string is invalid", "data": "foo", "valid": false } ] }, { "description": "allOf with the last empty schema", "schema": { "allOf": [ { "type": "number" }, {} ] }, "tests": [ { "description": "number is valid", "data": 1, "valid": true }, { "description": "string is invalid", "data": "foo", "valid": false } ] }, { "description": "nested allOf, to check validation semantics", "schema": { "allOf": [ { "allOf": [ { "type": "null" } ] } ] }, "tests": [ { "description": "null is valid", "data": null, "valid": true }, { "description": "anything non-null is invalid", "data": 123, "valid": false } ] }, { "description": "allOf combined with anyOf, oneOf", "schema": { "allOf": [ { "multipleOf": 2 } ], "anyOf": [ { "multipleOf": 3 } ], "oneOf": [ { "multipleOf": 5 } ] }, "tests": [ { "description": "allOf: false, anyOf: false, oneOf: false", "data": 1, "valid": false }, { "description": "allOf: false, anyOf: false, oneOf: true", "data": 5, "valid": false }, { "description": "allOf: false, anyOf: true, oneOf: false", "data": 3, "valid": false }, { "description": "allOf: false, anyOf: true, oneOf: true", "data": 15, "valid": false }, { "description": "allOf: true, anyOf: false, oneOf: false", "data": 2, "valid": false }, { "description": "allOf: true, anyOf: false, oneOf: true", "data": 10, "valid": false }, { "description": "allOf: true, anyOf: true, oneOf: false", "data": 6, "valid": false }, { "description": "allOf: true, anyOf: true, oneOf: true", "data": 30, "valid": true } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/anyOf.json ================================================ [ { "description": "anyOf", "schema": { "anyOf": [ { "type": "integer" }, { "minimum": 2 } ] }, "tests": [ { "description": "first anyOf valid", "data": 1, "valid": true }, { "description": "second anyOf valid", "data": 2.5, "valid": true }, { "description": "both anyOf valid", "data": 3, "valid": true }, { "description": "neither anyOf valid", "data": 1.5, "valid": false } ] }, { "description": "anyOf with base schema", "schema": { "type": "string", "anyOf" : [ { "maxLength": 2 }, { "minLength": 4 } ] }, "tests": [ { "description": "mismatch base schema", "data": 3, "valid": false }, { "description": "one anyOf valid", "data": "foobar", "valid": true }, { "description": "both anyOf invalid", "data": "foo", "valid": false } ] }, { "description": "anyOf with boolean schemas, all true", "schema": {"anyOf": [true, true]}, "tests": [ { "description": "any value is valid", "data": "foo", "valid": true } ] }, { "description": "anyOf with boolean schemas, some true", "schema": {"anyOf": [true, false]}, "tests": [ { "description": "any value is valid", "data": "foo", "valid": true } ] }, { "description": "anyOf with boolean schemas, all false", "schema": {"anyOf": [false, false]}, "tests": [ { "description": "any value is invalid", "data": "foo", "valid": false } ] }, { "description": "anyOf complex types", "schema": { "anyOf": [ { "properties": { "bar": {"type": "integer"} }, "required": ["bar"] }, { "properties": { "foo": {"type": "string"} }, "required": ["foo"] } ] }, "tests": [ { "description": "first anyOf valid (complex)", "data": {"bar": 2}, "valid": true }, { "description": "second anyOf valid (complex)", "data": {"foo": "baz"}, "valid": true }, { "description": "both anyOf valid (complex)", "data": {"foo": "baz", "bar": 2}, "valid": true }, { "description": "neither anyOf valid (complex)", "data": {"foo": 2, "bar": "quux"}, "valid": false } ] }, { "description": "anyOf with one empty schema", "schema": { "anyOf": [ { "type": "number" }, {} ] }, "tests": [ { "description": "string is valid", "data": "foo", "valid": true }, { "description": "number is valid", "data": 123, "valid": true } ] }, { "description": "nested anyOf, to check validation semantics", "schema": { "anyOf": [ { "anyOf": [ { "type": "null" } ] } ] }, "tests": [ { "description": "null is valid", "data": null, "valid": true }, { "description": "anything non-null is invalid", "data": 123, "valid": false } ] }, { "description": "nested anyOf, to check validation semantics", "schema": { "anyOf": [ { "anyOf": [ { "type": "null" } ] } ] }, "tests": [ { "description": "null is valid", "data": null, "valid": true }, { "description": "anything non-null is invalid", "data": 123, "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/boolean_schema.json ================================================ [ { "description": "boolean schema 'true'", "schema": true, "tests": [ { "description": "number is valid", "data": 1, "valid": true }, { "description": "string is valid", "data": "foo", "valid": true }, { "description": "boolean true is valid", "data": true, "valid": true }, { "description": "boolean false is valid", "data": false, "valid": true }, { "description": "null is valid", "data": null, "valid": true }, { "description": "object is valid", "data": {"foo": "bar"}, "valid": true }, { "description": "empty object is valid", "data": {}, "valid": true }, { "description": "array is valid", "data": ["foo"], "valid": true }, { "description": "empty array is valid", "data": [], "valid": true } ] }, { "description": "boolean schema 'false'", "schema": false, "tests": [ { "description": "number is invalid", "data": 1, "valid": false }, { "description": "string is invalid", "data": "foo", "valid": false }, { "description": "boolean true is invalid", "data": true, "valid": false }, { "description": "boolean false is invalid", "data": false, "valid": false }, { "description": "null is invalid", "data": null, "valid": false }, { "description": "object is invalid", "data": {"foo": "bar"}, "valid": false }, { "description": "empty object is invalid", "data": {}, "valid": false }, { "description": "array is invalid", "data": ["foo"], "valid": false }, { "description": "empty array is invalid", "data": [], "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/const.json ================================================ [ { "description": "const validation", "schema": {"const": 2}, "tests": [ { "description": "same value is valid", "data": 2, "valid": true }, { "description": "another value is invalid", "data": 5, "valid": false }, { "description": "another type is invalid", "data": "a", "valid": false } ] }, { "description": "const with object", "schema": {"const": {"foo": "bar", "baz": "bax"}}, "tests": [ { "description": "same object is valid", "data": {"foo": "bar", "baz": "bax"}, "valid": true }, { "description": "same object with different property order is valid", "data": {"baz": "bax", "foo": "bar"}, "valid": true }, { "description": "another object is invalid", "data": {"foo": "bar"}, "valid": false }, { "description": "another type is invalid", "data": [1, 2], "valid": false } ] }, { "description": "const with array", "schema": {"const": [{ "foo": "bar" }]}, "tests": [ { "description": "same array is valid", "data": [{"foo": "bar"}], "valid": true }, { "description": "another array item is invalid", "data": [2], "valid": false }, { "description": "array with additional items is invalid", "data": [1, 2, 3], "valid": false } ] }, { "description": "const with null", "schema": {"const": null}, "tests": [ { "description": "null is valid", "data": null, "valid": true }, { "description": "not null is invalid", "data": 0, "valid": false } ] }, { "description": "const with false does not match 0", "schema": {"const": false}, "tests": [ { "description": "false is valid", "data": false, "valid": true }, { "description": "integer zero is invalid", "data": 0, "valid": false }, { "description": "float zero is invalid", "data": 0.0, "valid": false } ] }, { "description": "const with true does not match 1", "schema": {"const": true}, "tests": [ { "description": "true is valid", "data": true, "valid": true }, { "description": "integer one is invalid", "data": 1, "valid": false }, { "description": "float one is invalid", "data": 1.0, "valid": false } ] }, { "description": "const with [false] does not match [0]", "schema": {"const": [false]}, "tests": [ { "description": "[false] is valid", "data": [false], "valid": true }, { "description": "[0] is invalid", "data": [0], "valid": false }, { "description": "[0.0] is invalid", "data": [0.0], "valid": false } ] }, { "description": "const with [true] does not match [1]", "schema": {"const": [true]}, "tests": [ { "description": "[true] is valid", "data": [true], "valid": true }, { "description": "[1] is invalid", "data": [1], "valid": false }, { "description": "[1.0] is invalid", "data": [1.0], "valid": false } ] }, { "description": "const with {\"a\": false} does not match {\"a\": 0}", "schema": {"const": {"a": false}}, "tests": [ { "description": "{\"a\": false} is valid", "data": {"a": false}, "valid": true }, { "description": "{\"a\": 0} is invalid", "data": {"a": 0}, "valid": false }, { "description": "{\"a\": 0.0} is invalid", "data": {"a": 0.0}, "valid": false } ] }, { "description": "const with {\"a\": true} does not match {\"a\": 1}", "schema": {"const": {"a": true}}, "tests": [ { "description": "{\"a\": true} is valid", "data": {"a": true}, "valid": true }, { "description": "{\"a\": 1} is invalid", "data": {"a": 1}, "valid": false }, { "description": "{\"a\": 1.0} is invalid", "data": {"a": 1.0}, "valid": false } ] }, { "description": "const with 0 does not match other zero-like types", "schema": {"const": 0}, "tests": [ { "description": "false is invalid", "data": false, "valid": false }, { "description": "integer zero is valid", "data": 0, "valid": true }, { "description": "float zero is valid", "data": 0.0, "valid": true }, { "description": "empty object is invalid", "data": {}, "valid": false }, { "description": "empty array is invalid", "data": [], "valid": false }, { "description": "empty string is invalid", "data": "", "valid": false } ] }, { "description": "const with 1 does not match true", "schema": {"const": 1}, "tests": [ { "description": "true is invalid", "data": true, "valid": false }, { "description": "integer one is valid", "data": 1, "valid": true }, { "description": "float one is valid", "data": 1.0, "valid": true } ] }, { "description": "const with -2.0 matches integer and float types", "schema": {"const": -2.0}, "tests": [ { "description": "integer -2 is valid", "data": -2, "valid": true }, { "description": "integer 2 is invalid", "data": 2, "valid": false }, { "description": "float -2.0 is valid", "data": -2.0, "valid": true }, { "description": "float 2.0 is invalid", "data": 2.0, "valid": false }, { "description": "float -2.00001 is invalid", "data": -2.00001, "valid": false } ] }, { "description": "float and integers are equal up to 64-bit representation limits", "schema": {"const": 9007199254740992}, "tests": [ { "description": "integer is valid", "data": 9007199254740992, "valid": true }, { "description": "integer minus one is invalid", "data": 9007199254740991, "valid": false }, { "description": "float is valid", "data": 9007199254740992.0, "valid": true }, { "description": "float minus one is invalid", "data": 9007199254740991.0, "valid": false } ] }, { "description": "nul characters in strings", "schema": { "const": "hello\u0000there" }, "tests": [ { "description": "match string with nul", "data": "hello\u0000there", "valid": true }, { "description": "do not match string lacking nul", "data": "hellothere", "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/contains.json ================================================ [ { "description": "contains keyword validation", "schema": { "contains": {"minimum": 5} }, "tests": [ { "description": "array with item matching schema (5) is valid", "data": [3, 4, 5], "valid": true }, { "description": "array with item matching schema (6) is valid", "data": [3, 4, 6], "valid": true }, { "description": "array with two items matching schema (5, 6) is valid", "data": [3, 4, 5, 6], "valid": true }, { "description": "array without items matching schema is invalid", "data": [2, 3, 4], "valid": false }, { "description": "empty array is invalid", "data": [], "valid": false }, { "description": "not array is valid", "data": {}, "valid": true } ] }, { "description": "contains keyword with const keyword", "schema": { "contains": { "const": 5 } }, "tests": [ { "description": "array with item 5 is valid", "data": [3, 4, 5], "valid": true }, { "description": "array with two items 5 is valid", "data": [3, 4, 5, 5], "valid": true }, { "description": "array without item 5 is invalid", "data": [1, 2, 3, 4], "valid": false } ] }, { "description": "contains keyword with boolean schema true", "schema": {"contains": true}, "tests": [ { "description": "any non-empty array is valid", "data": ["foo"], "valid": true }, { "description": "empty array is invalid", "data": [], "valid": false } ] }, { "description": "contains keyword with boolean schema false", "schema": {"contains": false}, "tests": [ { "description": "any non-empty array is invalid", "data": ["foo"], "valid": false }, { "description": "empty array is invalid", "data": [], "valid": false }, { "description": "non-arrays are valid", "data": "contains does not apply to strings", "valid": true } ] }, { "description": "items + contains", "schema": { "items": { "multipleOf": 2 }, "contains": { "multipleOf": 3 } }, "tests": [ { "description": "matches items, does not match contains", "data": [ 2, 4, 8 ], "valid": false }, { "description": "does not match items, matches contains", "data": [ 3, 6, 9 ], "valid": false }, { "description": "matches both items and contains", "data": [ 6, 12 ], "valid": true }, { "description": "matches neither items nor contains", "data": [ 1, 5 ], "valid": false } ] }, { "description": "contains with false if subschema", "schema": { "contains": { "if": false, "else": true } }, "tests": [ { "description": "any non-empty array is valid", "data": ["foo"], "valid": true }, { "description": "empty array is invalid", "data": [], "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/default.json ================================================ [ { "description": "invalid type for default", "schema": { "properties": { "foo": { "type": "integer", "default": [] } } }, "tests": [ { "description": "valid when property is specified", "data": {"foo": 13}, "valid": true }, { "description": "still valid when the invalid default is used", "data": {}, "valid": true } ] }, { "description": "invalid string value for default", "schema": { "properties": { "bar": { "type": "string", "minLength": 4, "default": "bad" } } }, "tests": [ { "description": "valid when property is specified", "data": {"bar": "good"}, "valid": true }, { "description": "still valid when the invalid default is used", "data": {}, "valid": true } ] }, { "description": "the default keyword does not do anything if the property is missing", "schema": { "type": "object", "properties": { "alpha": { "type": "number", "maximum": 3, "default": 5 } } }, "tests": [ { "description": "an explicit property value is checked against maximum (passing)", "data": { "alpha": 1 }, "valid": true }, { "description": "an explicit property value is checked against maximum (failing)", "data": { "alpha": 5 }, "valid": false }, { "description": "missing properties are not filled in with the default", "data": {}, "valid": true } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/definitions.json ================================================ [ { "description": "validate definition against metaschema", "schema": {"$ref": "http://json-schema.org/draft-07/schema#"}, "tests": [ { "description": "valid definition schema", "data": { "definitions": { "foo": {"type": "integer"} } }, "valid": true }, { "description": "invalid definition schema", "data": { "definitions": { "foo": {"type": 1} } }, "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/dependencies.json ================================================ [ { "description": "dependencies", "schema": { "dependencies": {"bar": ["foo"]} }, "tests": [ { "description": "neither", "data": {}, "valid": true }, { "description": "nondependant", "data": {"foo": 1}, "valid": true }, { "description": "with dependency", "data": {"foo": 1, "bar": 2}, "valid": true }, { "description": "missing dependency", "data": {"bar": 2}, "valid": false }, { "description": "ignores arrays", "data": ["bar"], "valid": true }, { "description": "ignores strings", "data": "foobar", "valid": true }, { "description": "ignores other non-objects", "data": 12, "valid": true } ] }, { "description": "dependencies with empty array", "schema": { "dependencies": {"bar": []} }, "tests": [ { "description": "empty object", "data": {}, "valid": true }, { "description": "object with one property", "data": {"bar": 2}, "valid": true }, { "description": "non-object is valid", "data": 1, "valid": true } ] }, { "description": "multiple dependencies", "schema": { "dependencies": {"quux": ["foo", "bar"]} }, "tests": [ { "description": "neither", "data": {}, "valid": true }, { "description": "nondependants", "data": {"foo": 1, "bar": 2}, "valid": true }, { "description": "with dependencies", "data": {"foo": 1, "bar": 2, "quux": 3}, "valid": true }, { "description": "missing dependency", "data": {"foo": 1, "quux": 2}, "valid": false }, { "description": "missing other dependency", "data": {"bar": 1, "quux": 2}, "valid": false }, { "description": "missing both dependencies", "data": {"quux": 1}, "valid": false } ] }, { "description": "multiple dependencies subschema", "schema": { "dependencies": { "bar": { "properties": { "foo": {"type": "integer"}, "bar": {"type": "integer"} } } } }, "tests": [ { "description": "valid", "data": {"foo": 1, "bar": 2}, "valid": true }, { "description": "no dependency", "data": {"foo": "quux"}, "valid": true }, { "description": "wrong type", "data": {"foo": "quux", "bar": 2}, "valid": false }, { "description": "wrong type other", "data": {"foo": 2, "bar": "quux"}, "valid": false }, { "description": "wrong type both", "data": {"foo": "quux", "bar": "quux"}, "valid": false } ] }, { "description": "dependencies with boolean subschemas", "schema": { "dependencies": { "foo": true, "bar": false } }, "tests": [ { "description": "object with property having schema true is valid", "data": {"foo": 1}, "valid": true }, { "description": "object with property having schema false is invalid", "data": {"bar": 2}, "valid": false }, { "description": "object with both properties is invalid", "data": {"foo": 1, "bar": 2}, "valid": false }, { "description": "empty object is valid", "data": {}, "valid": true } ] }, { "description": "dependencies with escaped characters", "schema": { "dependencies": { "foo\nbar": ["foo\rbar"], "foo\tbar": { "minProperties": 4 }, "foo'bar": {"required": ["foo\"bar"]}, "foo\"bar": ["foo'bar"] } }, "tests": [ { "description": "valid object 1", "data": { "foo\nbar": 1, "foo\rbar": 2 }, "valid": true }, { "description": "valid object 2", "data": { "foo\tbar": 1, "a": 2, "b": 3, "c": 4 }, "valid": true }, { "description": "valid object 3", "data": { "foo'bar": 1, "foo\"bar": 2 }, "valid": true }, { "description": "invalid object 1", "data": { "foo\nbar": 1, "foo": 2 }, "valid": false }, { "description": "invalid object 2", "data": { "foo\tbar": 1, "a": 2 }, "valid": false }, { "description": "invalid object 3", "data": { "foo'bar": 1 }, "valid": false }, { "description": "invalid object 4", "data": { "foo\"bar": 2 }, "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/enum.json ================================================ [ { "description": "simple enum validation", "schema": {"enum": [1, 2, 3]}, "tests": [ { "description": "one of the enum is valid", "data": 1, "valid": true }, { "description": "something else is invalid", "data": 4, "valid": false } ] }, { "description": "heterogeneous enum validation", "schema": {"enum": [6, "foo", [], true, {"foo": 12}]}, "tests": [ { "description": "one of the enum is valid", "data": [], "valid": true }, { "description": "something else is invalid", "data": null, "valid": false }, { "description": "objects are deep compared", "data": {"foo": false}, "valid": false }, { "description": "valid object matches", "data": {"foo": 12}, "valid": true }, { "description": "extra properties in object is invalid", "data": {"foo": 12, "boo": 42}, "valid": false } ] }, { "description": "heterogeneous enum-with-null validation", "schema": { "enum": [6, null] }, "tests": [ { "description": "null is valid", "data": null, "valid": true }, { "description": "number is valid", "data": 6, "valid": true }, { "description": "something else is invalid", "data": "test", "valid": false } ] }, { "description": "enums in properties", "schema": { "type":"object", "properties": { "foo": {"enum":["foo"]}, "bar": {"enum":["bar"]} }, "required": ["bar"] }, "tests": [ { "description": "both properties are valid", "data": {"foo":"foo", "bar":"bar"}, "valid": true }, { "description": "wrong foo value", "data": {"foo":"foot", "bar":"bar"}, "valid": false }, { "description": "wrong bar value", "data": {"foo":"foo", "bar":"bart"}, "valid": false }, { "description": "missing optional property is valid", "data": {"bar":"bar"}, "valid": true }, { "description": "missing required property is invalid", "data": {"foo":"foo"}, "valid": false }, { "description": "missing all properties is invalid", "data": {}, "valid": false } ] }, { "description": "enum with escaped characters", "schema": { "enum": ["foo\nbar", "foo\rbar"] }, "tests": [ { "description": "member 1 is valid", "data": "foo\nbar", "valid": true }, { "description": "member 2 is valid", "data": "foo\rbar", "valid": true }, { "description": "another string is invalid", "data": "abc", "valid": false } ] }, { "description": "enum with false does not match 0", "schema": {"enum": [false]}, "tests": [ { "description": "false is valid", "data": false, "valid": true }, { "description": "integer zero is invalid", "data": 0, "valid": false }, { "description": "float zero is invalid", "data": 0.0, "valid": false } ] }, { "description": "enum with true does not match 1", "schema": {"enum": [true]}, "tests": [ { "description": "true is valid", "data": true, "valid": true }, { "description": "integer one is invalid", "data": 1, "valid": false }, { "description": "float one is invalid", "data": 1.0, "valid": false } ] }, { "description": "enum with 0 does not match false", "schema": {"enum": [0]}, "tests": [ { "description": "false is invalid", "data": false, "valid": false }, { "description": "integer zero is valid", "data": 0, "valid": true }, { "description": "float zero is valid", "data": 0.0, "valid": true } ] }, { "description": "enum with 1 does not match true", "schema": {"enum": [1]}, "tests": [ { "description": "true is invalid", "data": true, "valid": false }, { "description": "integer one is valid", "data": 1, "valid": true }, { "description": "float one is valid", "data": 1.0, "valid": true } ] }, { "description": "nul characters in strings", "schema": { "enum": [ "hello\u0000there" ] }, "tests": [ { "description": "match string with nul", "data": "hello\u0000there", "valid": true }, { "description": "do not match string lacking nul", "data": "hellothere", "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/exclusiveMaximum.json ================================================ [ { "description": "exclusiveMaximum validation", "schema": { "exclusiveMaximum": 3.0 }, "tests": [ { "description": "below the exclusiveMaximum is valid", "data": 2.2, "valid": true }, { "description": "boundary point is invalid", "data": 3.0, "valid": false }, { "description": "above the exclusiveMaximum is invalid", "data": 3.5, "valid": false }, { "description": "ignores non-numbers", "data": "x", "valid": true } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/exclusiveMinimum.json ================================================ [ { "description": "exclusiveMinimum validation", "schema": { "exclusiveMinimum": 1.1 }, "tests": [ { "description": "above the exclusiveMinimum is valid", "data": 1.2, "valid": true }, { "description": "boundary point is invalid", "data": 1.1, "valid": false }, { "description": "below the exclusiveMinimum is invalid", "data": 0.6, "valid": false }, { "description": "ignores non-numbers", "data": "x", "valid": true } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/format.json ================================================ [ { "description": "email format", "schema": { "format": "email" }, "tests": [ { "description": "all string formats ignore integers", "data": 12, "valid": true }, { "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { "description": "all string formats ignore objects", "data": {}, "valid": true }, { "description": "all string formats ignore arrays", "data": [], "valid": true }, { "description": "all string formats ignore booleans", "data": false, "valid": true }, { "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { "description": "idn-email format", "schema": { "format": "idn-email" }, "tests": [ { "description": "all string formats ignore integers", "data": 12, "valid": true }, { "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { "description": "all string formats ignore objects", "data": {}, "valid": true }, { "description": "all string formats ignore arrays", "data": [], "valid": true }, { "description": "all string formats ignore booleans", "data": false, "valid": true }, { "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { "description": "regex format", "schema": { "format": "regex" }, "tests": [ { "description": "all string formats ignore integers", "data": 12, "valid": true }, { "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { "description": "all string formats ignore objects", "data": {}, "valid": true }, { "description": "all string formats ignore arrays", "data": [], "valid": true }, { "description": "all string formats ignore booleans", "data": false, "valid": true }, { "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { "description": "ipv4 format", "schema": { "format": "ipv4" }, "tests": [ { "description": "all string formats ignore integers", "data": 12, "valid": true }, { "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { "description": "all string formats ignore objects", "data": {}, "valid": true }, { "description": "all string formats ignore arrays", "data": [], "valid": true }, { "description": "all string formats ignore booleans", "data": false, "valid": true }, { "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { "description": "ipv6 format", "schema": { "format": "ipv6" }, "tests": [ { "description": "all string formats ignore integers", "data": 12, "valid": true }, { "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { "description": "all string formats ignore objects", "data": {}, "valid": true }, { "description": "all string formats ignore arrays", "data": [], "valid": true }, { "description": "all string formats ignore booleans", "data": false, "valid": true }, { "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { "description": "idn-hostname format", "schema": { "format": "idn-hostname" }, "tests": [ { "description": "all string formats ignore integers", "data": 12, "valid": true }, { "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { "description": "all string formats ignore objects", "data": {}, "valid": true }, { "description": "all string formats ignore arrays", "data": [], "valid": true }, { "description": "all string formats ignore booleans", "data": false, "valid": true }, { "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { "description": "hostname format", "schema": { "format": "hostname" }, "tests": [ { "description": "all string formats ignore integers", "data": 12, "valid": true }, { "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { "description": "all string formats ignore objects", "data": {}, "valid": true }, { "description": "all string formats ignore arrays", "data": [], "valid": true }, { "description": "all string formats ignore booleans", "data": false, "valid": true }, { "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { "description": "date format", "schema": { "format": "date" }, "tests": [ { "description": "all string formats ignore integers", "data": 12, "valid": true }, { "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { "description": "all string formats ignore objects", "data": {}, "valid": true }, { "description": "all string formats ignore arrays", "data": [], "valid": true }, { "description": "all string formats ignore booleans", "data": false, "valid": true }, { "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { "description": "date-time format", "schema": { "format": "date-time" }, "tests": [ { "description": "all string formats ignore integers", "data": 12, "valid": true }, { "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { "description": "all string formats ignore objects", "data": {}, "valid": true }, { "description": "all string formats ignore arrays", "data": [], "valid": true }, { "description": "all string formats ignore booleans", "data": false, "valid": true }, { "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { "description": "time format", "schema": { "format": "time" }, "tests": [ { "description": "all string formats ignore integers", "data": 12, "valid": true }, { "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { "description": "all string formats ignore objects", "data": {}, "valid": true }, { "description": "all string formats ignore arrays", "data": [], "valid": true }, { "description": "all string formats ignore booleans", "data": false, "valid": true }, { "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { "description": "json-pointer format", "schema": { "format": "json-pointer" }, "tests": [ { "description": "all string formats ignore integers", "data": 12, "valid": true }, { "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { "description": "all string formats ignore objects", "data": {}, "valid": true }, { "description": "all string formats ignore arrays", "data": [], "valid": true }, { "description": "all string formats ignore booleans", "data": false, "valid": true }, { "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { "description": "relative-json-pointer format", "schema": { "format": "relative-json-pointer" }, "tests": [ { "description": "all string formats ignore integers", "data": 12, "valid": true }, { "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { "description": "all string formats ignore objects", "data": {}, "valid": true }, { "description": "all string formats ignore arrays", "data": [], "valid": true }, { "description": "all string formats ignore booleans", "data": false, "valid": true }, { "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { "description": "iri format", "schema": { "format": "iri" }, "tests": [ { "description": "all string formats ignore integers", "data": 12, "valid": true }, { "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { "description": "all string formats ignore objects", "data": {}, "valid": true }, { "description": "all string formats ignore arrays", "data": [], "valid": true }, { "description": "all string formats ignore booleans", "data": false, "valid": true }, { "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { "description": "iri-reference format", "schema": { "format": "iri-reference" }, "tests": [ { "description": "all string formats ignore integers", "data": 12, "valid": true }, { "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { "description": "all string formats ignore objects", "data": {}, "valid": true }, { "description": "all string formats ignore arrays", "data": [], "valid": true }, { "description": "all string formats ignore booleans", "data": false, "valid": true }, { "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { "description": "uri format", "schema": { "format": "uri" }, "tests": [ { "description": "all string formats ignore integers", "data": 12, "valid": true }, { "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { "description": "all string formats ignore objects", "data": {}, "valid": true }, { "description": "all string formats ignore arrays", "data": [], "valid": true }, { "description": "all string formats ignore booleans", "data": false, "valid": true }, { "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { "description": "uri-reference format", "schema": { "format": "uri-reference" }, "tests": [ { "description": "all string formats ignore integers", "data": 12, "valid": true }, { "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { "description": "all string formats ignore objects", "data": {}, "valid": true }, { "description": "all string formats ignore arrays", "data": [], "valid": true }, { "description": "all string formats ignore booleans", "data": false, "valid": true }, { "description": "all string formats ignore nulls", "data": null, "valid": true } ] }, { "description": "uri-template format", "schema": { "format": "uri-template" }, "tests": [ { "description": "all string formats ignore integers", "data": 12, "valid": true }, { "description": "all string formats ignore floats", "data": 13.7, "valid": true }, { "description": "all string formats ignore objects", "data": {}, "valid": true }, { "description": "all string formats ignore arrays", "data": [], "valid": true }, { "description": "all string formats ignore booleans", "data": false, "valid": true }, { "description": "all string formats ignore nulls", "data": null, "valid": true } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/id.json ================================================ [ { "description": "id inside an enum is not a real identifier", "comment": "the implementation must not be confused by an id buried in the enum", "schema": { "definitions": { "id_in_enum": { "enum": [ { "$id": "https://localhost:1234/id/my_identifier.json", "type": "null" } ] }, "real_id_in_schema": { "$id": "https://localhost:1234/id/my_identifier.json", "type": "string" }, "zzz_id_in_const": { "const": { "$id": "https://localhost:1234/id/my_identifier.json", "type": "null" } } }, "anyOf": [ { "$ref": "#/definitions/id_in_enum" }, { "$ref": "https://localhost:1234/id/my_identifier.json" } ] }, "tests": [ { "description": "exact match to enum, and type matches", "data": { "$id": "https://localhost:1234/id/my_identifier.json", "type": "null" }, "valid": true }, { "description": "match $ref to id", "data": "a string to match #/definitions/id_in_enum", "valid": true }, { "description": "no match on enum or $ref to id", "data": 1, "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/if-then-else.json ================================================ [ { "description": "ignore if without then or else", "schema": { "if": { "const": 0 } }, "tests": [ { "description": "valid when valid against lone if", "data": 0, "valid": true }, { "description": "valid when invalid against lone if", "data": "hello", "valid": true } ] }, { "description": "ignore then without if", "schema": { "then": { "const": 0 } }, "tests": [ { "description": "valid when valid against lone then", "data": 0, "valid": true }, { "description": "valid when invalid against lone then", "data": "hello", "valid": true } ] }, { "description": "ignore else without if", "schema": { "else": { "const": 0 } }, "tests": [ { "description": "valid when valid against lone else", "data": 0, "valid": true }, { "description": "valid when invalid against lone else", "data": "hello", "valid": true } ] }, { "description": "if and then without else", "schema": { "if": { "exclusiveMaximum": 0 }, "then": { "minimum": -10 } }, "tests": [ { "description": "valid through then", "data": -1, "valid": true }, { "description": "invalid through then", "data": -100, "valid": false }, { "description": "valid when if test fails", "data": 3, "valid": true } ] }, { "description": "if and else without then", "schema": { "if": { "exclusiveMaximum": 0 }, "else": { "multipleOf": 2 } }, "tests": [ { "description": "valid when if test passes", "data": -1, "valid": true }, { "description": "valid through else", "data": 4, "valid": true }, { "description": "invalid through else", "data": 3, "valid": false } ] }, { "description": "validate against correct branch, then vs else", "schema": { "if": { "exclusiveMaximum": 0 }, "then": { "minimum": -10 }, "else": { "multipleOf": 2 } }, "tests": [ { "description": "valid through then", "data": -1, "valid": true }, { "description": "invalid through then", "data": -100, "valid": false }, { "description": "valid through else", "data": 4, "valid": true }, { "description": "invalid through else", "data": 3, "valid": false } ] }, { "description": "non-interference across combined schemas", "schema": { "allOf": [ { "if": { "exclusiveMaximum": 0 } }, { "then": { "minimum": -10 } }, { "else": { "multipleOf": 2 } } ] }, "tests": [ { "description": "valid, but would have been invalid through then", "data": -100, "valid": true }, { "description": "valid, but would have been invalid through else", "data": 3, "valid": true } ] }, { "description": "if with boolean schema true", "schema": { "if": true, "then": { "const": "then" }, "else": { "const": "else" } }, "tests": [ { "description": "boolean schema true in if always chooses the then path (valid)", "data": "then", "valid": true }, { "description": "boolean schema true in if always chooses the then path (invalid)", "data": "else", "valid": false } ] }, { "description": "if with boolean schema false", "schema": { "if": false, "then": { "const": "then" }, "else": { "const": "else" } }, "tests": [ { "description": "boolean schema false in if always chooses the else path (invalid)", "data": "then", "valid": false }, { "description": "boolean schema false in if always chooses the else path (valid)", "data": "else", "valid": true } ] }, { "description": "if appears at the end when serialized (keyword processing sequence)", "schema": { "then": { "const": "yes" }, "else": { "const": "other" }, "if": { "maxLength": 4 } }, "tests": [ { "description": "yes redirects to then and passes", "data": "yes", "valid": true }, { "description": "other redirects to else and passes", "data": "other", "valid": true }, { "description": "no redirects to then and fails", "data": "no", "valid": false }, { "description": "invalid redirects to else and fails", "data": "invalid", "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/infinite-loop-detection.json ================================================ [ { "description": "evaluating the same schema location against the same data location twice is not a sign of an infinite loop", "schema": { "definitions": { "int": { "type": "integer" } }, "allOf": [ { "properties": { "foo": { "$ref": "#/definitions/int" } } }, { "additionalProperties": { "$ref": "#/definitions/int" } } ] }, "tests": [ { "description": "passing case", "data": { "foo": 1 }, "valid": true }, { "description": "failing case", "data": { "foo": "a string" }, "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/items.json ================================================ [ { "description": "a schema given for items", "schema": { "items": {"type": "integer"} }, "tests": [ { "description": "valid items", "data": [ 1, 2, 3 ], "valid": true }, { "description": "wrong type of items", "data": [1, "x"], "valid": false }, { "description": "ignores non-arrays", "data": {"foo" : "bar"}, "valid": true }, { "description": "JavaScript pseudo-array is valid", "data": { "0": "invalid", "length": 1 }, "valid": true } ] }, { "description": "an array of schemas for items", "schema": { "items": [ {"type": "integer"}, {"type": "string"} ] }, "tests": [ { "description": "correct types", "data": [ 1, "foo" ], "valid": true }, { "description": "wrong types", "data": [ "foo", 1 ], "valid": false }, { "description": "incomplete array of items", "data": [ 1 ], "valid": true }, { "description": "array with additional items", "data": [ 1, "foo", true ], "valid": true }, { "description": "empty array", "data": [ ], "valid": true }, { "description": "JavaScript pseudo-array is valid", "data": { "0": "invalid", "1": "valid", "length": 2 }, "valid": true } ] }, { "description": "items with boolean schema (true)", "schema": {"items": true}, "tests": [ { "description": "any array is valid", "data": [ 1, "foo", true ], "valid": true }, { "description": "empty array is valid", "data": [], "valid": true } ] }, { "description": "items with boolean schema (false)", "schema": {"items": false}, "tests": [ { "description": "any non-empty array is invalid", "data": [ 1, "foo", true ], "valid": false }, { "description": "empty array is valid", "data": [], "valid": true } ] }, { "description": "items with boolean schemas", "schema": { "items": [true, false] }, "tests": [ { "description": "array with one item is valid", "data": [ 1 ], "valid": true }, { "description": "array with two items is invalid", "data": [ 1, "foo" ], "valid": false }, { "description": "empty array is valid", "data": [], "valid": true } ] }, { "description": "items and subitems", "schema": { "definitions": { "item": { "type": "array", "additionalItems": false, "items": [ { "$ref": "#/definitions/sub-item" }, { "$ref": "#/definitions/sub-item" } ] }, "sub-item": { "type": "object", "required": ["foo"] } }, "type": "array", "additionalItems": false, "items": [ { "$ref": "#/definitions/item" }, { "$ref": "#/definitions/item" }, { "$ref": "#/definitions/item" } ] }, "tests": [ { "description": "valid items", "data": [ [ {"foo": null}, {"foo": null} ], [ {"foo": null}, {"foo": null} ], [ {"foo": null}, {"foo": null} ] ], "valid": true }, { "description": "too many items", "data": [ [ {"foo": null}, {"foo": null} ], [ {"foo": null}, {"foo": null} ], [ {"foo": null}, {"foo": null} ], [ {"foo": null}, {"foo": null} ] ], "valid": false }, { "description": "too many sub-items", "data": [ [ {"foo": null}, {"foo": null}, {"foo": null} ], [ {"foo": null}, {"foo": null} ], [ {"foo": null}, {"foo": null} ] ], "valid": false }, { "description": "wrong item", "data": [ {"foo": null}, [ {"foo": null}, {"foo": null} ], [ {"foo": null}, {"foo": null} ] ], "valid": false }, { "description": "wrong sub-item", "data": [ [ {}, {"foo": null} ], [ {"foo": null}, {"foo": null} ], [ {"foo": null}, {"foo": null} ] ], "valid": false }, { "description": "fewer items is valid", "data": [ [ {"foo": null} ], [ {"foo": null} ] ], "valid": true } ] }, { "description": "nested items", "schema": { "type": "array", "items": { "type": "array", "items": { "type": "array", "items": { "type": "array", "items": { "type": "number" } } } } }, "tests": [ { "description": "valid nested array", "data": [[[[1]], [[2],[3]]], [[[4], [5], [6]]]], "valid": true }, { "description": "nested array with invalid type", "data": [[[["1"]], [[2],[3]]], [[[4], [5], [6]]]], "valid": false }, { "description": "not deep enough", "data": [[[1], [2],[3]], [[4], [5], [6]]], "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/maxItems.json ================================================ [ { "description": "maxItems validation", "schema": {"maxItems": 2}, "tests": [ { "description": "shorter is valid", "data": [1], "valid": true }, { "description": "exact length is valid", "data": [1, 2], "valid": true }, { "description": "too long is invalid", "data": [1, 2, 3], "valid": false }, { "description": "ignores non-arrays", "data": "foobar", "valid": true } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/maxLength.json ================================================ [ { "description": "maxLength validation", "schema": {"maxLength": 2}, "tests": [ { "description": "shorter is valid", "data": "f", "valid": true }, { "description": "exact length is valid", "data": "fo", "valid": true }, { "description": "too long is invalid", "data": "foo", "valid": false }, { "description": "ignores non-strings", "data": 100, "valid": true }, { "description": "two supplementary Unicode code points is long enough", "data": "\uD83D\uDCA9\uD83D\uDCA9", "valid": true } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/maxProperties.json ================================================ [ { "description": "maxProperties validation", "schema": {"maxProperties": 2}, "tests": [ { "description": "shorter is valid", "data": {"foo": 1}, "valid": true }, { "description": "exact length is valid", "data": {"foo": 1, "bar": 2}, "valid": true }, { "description": "too long is invalid", "data": {"foo": 1, "bar": 2, "baz": 3}, "valid": false }, { "description": "ignores arrays", "data": [1, 2, 3], "valid": true }, { "description": "ignores strings", "data": "foobar", "valid": true }, { "description": "ignores other non-objects", "data": 12, "valid": true } ] }, { "description": "maxProperties = 0 means the object is empty", "schema": { "maxProperties": 0 }, "tests": [ { "description": "no properties is valid", "data": {}, "valid": true }, { "description": "one property is invalid", "data": { "foo": 1 }, "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/maximum.json ================================================ [ { "description": "maximum validation", "schema": {"maximum": 3.0}, "tests": [ { "description": "below the maximum is valid", "data": 2.6, "valid": true }, { "description": "boundary point is valid", "data": 3.0, "valid": true }, { "description": "above the maximum is invalid", "data": 3.5, "valid": false }, { "description": "ignores non-numbers", "data": "x", "valid": true } ] }, { "description": "maximum validation with unsigned integer", "schema": {"maximum": 300}, "tests": [ { "description": "below the maximum is invalid", "data": 299.97, "valid": true }, { "description": "boundary point integer is valid", "data": 300, "valid": true }, { "description": "boundary point float is valid", "data": 300.00, "valid": true }, { "description": "above the maximum is invalid", "data": 300.5, "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/minItems.json ================================================ [ { "description": "minItems validation", "schema": {"minItems": 1}, "tests": [ { "description": "longer is valid", "data": [1, 2], "valid": true }, { "description": "exact length is valid", "data": [1], "valid": true }, { "description": "too short is invalid", "data": [], "valid": false }, { "description": "ignores non-arrays", "data": "", "valid": true } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/minLength.json ================================================ [ { "description": "minLength validation", "schema": {"minLength": 2}, "tests": [ { "description": "longer is valid", "data": "foo", "valid": true }, { "description": "exact length is valid", "data": "fo", "valid": true }, { "description": "too short is invalid", "data": "f", "valid": false }, { "description": "ignores non-strings", "data": 1, "valid": true }, { "description": "one supplementary Unicode code point is not long enough", "data": "\uD83D\uDCA9", "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/minProperties.json ================================================ [ { "description": "minProperties validation", "schema": {"minProperties": 1}, "tests": [ { "description": "longer is valid", "data": {"foo": 1, "bar": 2}, "valid": true }, { "description": "exact length is valid", "data": {"foo": 1}, "valid": true }, { "description": "too short is invalid", "data": {}, "valid": false }, { "description": "ignores arrays", "data": [], "valid": true }, { "description": "ignores strings", "data": "", "valid": true }, { "description": "ignores other non-objects", "data": 12, "valid": true } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/minimum.json ================================================ [ { "description": "minimum validation", "schema": {"minimum": 1.1}, "tests": [ { "description": "above the minimum is valid", "data": 2.6, "valid": true }, { "description": "boundary point is valid", "data": 1.1, "valid": true }, { "description": "below the minimum is invalid", "data": 0.6, "valid": false }, { "description": "ignores non-numbers", "data": "x", "valid": true } ] }, { "description": "minimum validation with signed integer", "schema": {"minimum": -2}, "tests": [ { "description": "negative above the minimum is valid", "data": -1, "valid": true }, { "description": "positive above the minimum is valid", "data": 0, "valid": true }, { "description": "boundary point is valid", "data": -2, "valid": true }, { "description": "boundary point with float is valid", "data": -2.0, "valid": true }, { "description": "float below the minimum is invalid", "data": -2.0001, "valid": false }, { "description": "int below the minimum is invalid", "data": -3, "valid": false }, { "description": "ignores non-numbers", "data": "x", "valid": true } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/multipleOf.json ================================================ [ { "description": "by int", "schema": {"multipleOf": 2}, "tests": [ { "description": "int by int", "data": 10, "valid": true }, { "description": "int by int fail", "data": 7, "valid": false }, { "description": "ignores non-numbers", "data": "foo", "valid": true } ] }, { "description": "by number", "schema": {"multipleOf": 1.5}, "tests": [ { "description": "zero is multiple of anything", "data": 0, "valid": true }, { "description": "4.5 is multiple of 1.5", "data": 4.5, "valid": true }, { "description": "35 is not multiple of 1.5", "data": 35, "valid": false } ] }, { "description": "by small number", "schema": {"multipleOf": 0.0001}, "tests": [ { "description": "0.0075 is multiple of 0.0001", "data": 0.0075, "valid": true }, { "description": "0.00751 is not multiple of 0.0001", "data": 0.00751, "valid": false } ] }, { "description": "invalid instance should not raise error when float division = inf", "schema": {"type": "integer", "multipleOf": 0.123456789}, "tests": [ { "description": "always invalid, but naive implementations may raise an overflow error", "data": 1e308, "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/not.json ================================================ [ { "description": "not", "schema": { "not": {"type": "integer"} }, "tests": [ { "description": "allowed", "data": "foo", "valid": true }, { "description": "disallowed", "data": 1, "valid": false } ] }, { "description": "not multiple types", "schema": { "not": {"type": ["integer", "boolean"]} }, "tests": [ { "description": "valid", "data": "foo", "valid": true }, { "description": "mismatch", "data": 1, "valid": false }, { "description": "other mismatch", "data": true, "valid": false } ] }, { "description": "not more complex schema", "schema": { "not": { "type": "object", "properties": { "foo": { "type": "string" } } } }, "tests": [ { "description": "match", "data": 1, "valid": true }, { "description": "other match", "data": {"foo": 1}, "valid": true }, { "description": "mismatch", "data": {"foo": "bar"}, "valid": false } ] }, { "description": "forbidden property", "schema": { "properties": { "foo": { "not": {} } } }, "tests": [ { "description": "property present", "data": {"foo": 1, "bar": 2}, "valid": false }, { "description": "property absent", "data": {"bar": 1, "baz": 2}, "valid": true } ] }, { "description": "not with boolean schema true", "schema": {"not": true}, "tests": [ { "description": "any value is invalid", "data": "foo", "valid": false } ] }, { "description": "not with boolean schema false", "schema": {"not": false}, "tests": [ { "description": "any value is valid", "data": "foo", "valid": true } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/oneOf.json ================================================ [ { "description": "oneOf", "schema": { "oneOf": [ { "type": "integer" }, { "minimum": 2 } ] }, "tests": [ { "description": "first oneOf valid", "data": 1, "valid": true }, { "description": "second oneOf valid", "data": 2.5, "valid": true }, { "description": "both oneOf valid", "data": 3, "valid": false }, { "description": "neither oneOf valid", "data": 1.5, "valid": false } ] }, { "description": "oneOf with base schema", "schema": { "type": "string", "oneOf" : [ { "minLength": 2 }, { "maxLength": 4 } ] }, "tests": [ { "description": "mismatch base schema", "data": 3, "valid": false }, { "description": "one oneOf valid", "data": "foobar", "valid": true }, { "description": "both oneOf valid", "data": "foo", "valid": false } ] }, { "description": "oneOf with boolean schemas, all true", "schema": {"oneOf": [true, true, true]}, "tests": [ { "description": "any value is invalid", "data": "foo", "valid": false } ] }, { "description": "oneOf with boolean schemas, one true", "schema": {"oneOf": [true, false, false]}, "tests": [ { "description": "any value is valid", "data": "foo", "valid": true } ] }, { "description": "oneOf with boolean schemas, more than one true", "schema": {"oneOf": [true, true, false]}, "tests": [ { "description": "any value is invalid", "data": "foo", "valid": false } ] }, { "description": "oneOf with boolean schemas, all false", "schema": {"oneOf": [false, false, false]}, "tests": [ { "description": "any value is invalid", "data": "foo", "valid": false } ] }, { "description": "oneOf complex types", "schema": { "oneOf": [ { "properties": { "bar": {"type": "integer"} }, "required": ["bar"] }, { "properties": { "foo": {"type": "string"} }, "required": ["foo"] } ] }, "tests": [ { "description": "first oneOf valid (complex)", "data": {"bar": 2}, "valid": true }, { "description": "second oneOf valid (complex)", "data": {"foo": "baz"}, "valid": true }, { "description": "both oneOf valid (complex)", "data": {"foo": "baz", "bar": 2}, "valid": false }, { "description": "neither oneOf valid (complex)", "data": {"foo": 2, "bar": "quux"}, "valid": false } ] }, { "description": "oneOf with empty schema", "schema": { "oneOf": [ { "type": "number" }, {} ] }, "tests": [ { "description": "one valid - valid", "data": "foo", "valid": true }, { "description": "both valid - invalid", "data": 123, "valid": false } ] }, { "description": "oneOf with required", "schema": { "type": "object", "oneOf": [ { "required": ["foo", "bar"] }, { "required": ["foo", "baz"] } ] }, "tests": [ { "description": "both invalid - invalid", "data": {"bar": 2}, "valid": false }, { "description": "first valid - valid", "data": {"foo": 1, "bar": 2}, "valid": true }, { "description": "second valid - valid", "data": {"foo": 1, "baz": 3}, "valid": true }, { "description": "both valid - invalid", "data": {"foo": 1, "bar": 2, "baz" : 3}, "valid": false } ] }, { "description": "oneOf with missing optional property", "schema": { "oneOf": [ { "properties": { "bar": true, "baz": true }, "required": ["bar"] }, { "properties": { "foo": true }, "required": ["foo"] } ] }, "tests": [ { "description": "first oneOf valid", "data": {"bar": 8}, "valid": true }, { "description": "second oneOf valid", "data": {"foo": "foo"}, "valid": true }, { "description": "both oneOf valid", "data": {"foo": "foo", "bar": 8}, "valid": false }, { "description": "neither oneOf valid", "data": {"baz": "quux"}, "valid": false } ] }, { "description": "nested oneOf, to check validation semantics", "schema": { "oneOf": [ { "oneOf": [ { "type": "null" } ] } ] }, "tests": [ { "description": "null is valid", "data": null, "valid": true }, { "description": "anything non-null is invalid", "data": 123, "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/optional/bignum.json ================================================ [ { "description": "integer", "schema": { "type": "integer" }, "tests": [ { "description": "a bignum is an integer", "data": 12345678910111213141516171819202122232425262728293031, "valid": true }, { "description": "a negative bignum is an integer", "data": -12345678910111213141516171819202122232425262728293031, "valid": true } ] }, { "description": "number", "schema": { "type": "number" }, "tests": [ { "description": "a bignum is a number", "data": 98249283749234923498293171823948729348710298301928331, "valid": true }, { "description": "a negative bignum is a number", "data": -98249283749234923498293171823948729348710298301928331, "valid": true } ] }, { "description": "string", "schema": { "type": "string" }, "tests": [ { "description": "a bignum is not a string", "data": 98249283749234923498293171823948729348710298301928331, "valid": false } ] }, { "description": "integer comparison", "schema": { "maximum": 18446744073709551615 }, "tests": [ { "description": "comparison works for high numbers", "data": 18446744073709551600, "valid": true } ] }, { "description": "float comparison with high precision", "schema": { "exclusiveMaximum": 972783798187987123879878123.18878137 }, "tests": [ { "description": "comparison works for high numbers", "data": 972783798187987123879878123.188781371, "valid": false } ] }, { "description": "integer comparison", "schema": { "minimum": -18446744073709551615 }, "tests": [ { "description": "comparison works for very negative numbers", "data": -18446744073709551600, "valid": true } ] }, { "description": "float comparison with high precision on negative numbers", "schema": { "exclusiveMinimum": -972783798187987123879878123.18878137 }, "tests": [ { "description": "comparison works for very negative numbers", "data": -972783798187987123879878123.188781371, "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/optional/content.json ================================================ [ { "description": "validation of string-encoded content based on media type", "schema": { "contentMediaType": "application/json" }, "tests": [ { "description": "a valid JSON document", "data": "{\"foo\": \"bar\"}", "valid": true }, { "description": "an invalid JSON document", "data": "{:}", "valid": false }, { "description": "ignores non-strings", "data": 100, "valid": true } ] }, { "description": "validation of binary string-encoding", "schema": { "contentEncoding": "base64" }, "tests": [ { "description": "a valid base64 string", "data": "eyJmb28iOiAiYmFyIn0K", "valid": true }, { "description": "an invalid base64 string (% is not a valid character)", "data": "eyJmb28iOi%iYmFyIn0K", "valid": false }, { "description": "ignores non-strings", "data": 100, "valid": true } ] }, { "description": "validation of binary-encoded media type documents", "schema": { "contentMediaType": "application/json", "contentEncoding": "base64" }, "tests": [ { "description": "a valid base64-encoded JSON document", "data": "eyJmb28iOiAiYmFyIn0K", "valid": true }, { "description": "a validly-encoded invalid JSON document", "data": "ezp9Cg==", "valid": false }, { "description": "an invalid base64 string that is valid JSON", "data": "{}", "valid": false }, { "description": "ignores non-strings", "data": 100, "valid": true } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/optional/ecmascript-regex.json ================================================ [ { "description": "ECMA 262 regex $ does not match trailing newline", "schema": { "type": "string", "pattern": "^abc$" }, "tests": [ { "description": "matches in Python, but should not in jsonschema", "data": "abc\\n", "valid": false }, { "description": "should match", "data": "abc", "valid": true } ] }, { "description": "ECMA 262 regex converts \\t to horizontal tab", "schema": { "type": "string", "pattern": "^\\t$" }, "tests": [ { "description": "does not match", "data": "\\t", "valid": false }, { "description": "matches", "data": "\u0009", "valid": true } ] }, { "description": "ECMA 262 regex escapes control codes with \\c and upper letter", "schema": { "type": "string", "pattern": "^\\cC$" }, "tests": [ { "description": "does not match", "data": "\\cC", "valid": false }, { "description": "matches", "data": "\u0003", "valid": true } ] }, { "description": "ECMA 262 regex escapes control codes with \\c and lower letter", "schema": { "type": "string", "pattern": "^\\cc$" }, "tests": [ { "description": "does not match", "data": "\\cc", "valid": false }, { "description": "matches", "data": "\u0003", "valid": true } ] }, { "description": "ECMA 262 \\d matches ascii digits only", "schema": { "type": "string", "pattern": "^\\d$" }, "tests": [ { "description": "ASCII zero matches", "data": "0", "valid": true }, { "description": "NKO DIGIT ZERO does not match (unlike e.g. Python)", "data": "߀", "valid": false }, { "description": "NKO DIGIT ZERO (as \\u escape) does not match", "data": "\u07c0", "valid": false } ] }, { "description": "ECMA 262 \\D matches everything but ascii digits", "schema": { "type": "string", "pattern": "^\\D$" }, "tests": [ { "description": "ASCII zero does not match", "data": "0", "valid": false }, { "description": "NKO DIGIT ZERO matches (unlike e.g. Python)", "data": "߀", "valid": true }, { "description": "NKO DIGIT ZERO (as \\u escape) matches", "data": "\u07c0", "valid": true } ] }, { "description": "ECMA 262 \\w matches ascii letters only", "schema": { "type": "string", "pattern": "^\\w$" }, "tests": [ { "description": "ASCII 'a' matches", "data": "a", "valid": true }, { "description": "latin-1 e-acute does not match (unlike e.g. Python)", "data": "é", "valid": false } ] }, { "description": "ECMA 262 \\W matches everything but ascii letters", "schema": { "type": "string", "pattern": "^\\W$" }, "tests": [ { "description": "ASCII 'a' does not match", "data": "a", "valid": false }, { "description": "latin-1 e-acute matches (unlike e.g. Python)", "data": "é", "valid": true } ] }, { "description": "ECMA 262 \\s matches whitespace", "schema": { "type": "string", "pattern": "^\\s$" }, "tests": [ { "description": "ASCII space matches", "data": " ", "valid": true }, { "description": "Character tabulation matches", "data": "\t", "valid": true }, { "description": "Line tabulation matches", "data": "\u000b", "valid": true }, { "description": "Form feed matches", "data": "\u000c", "valid": true }, { "description": "latin-1 non-breaking-space matches", "data": "\u00a0", "valid": true }, { "description": "zero-width whitespace matches", "data": "\ufeff", "valid": true }, { "description": "line feed matches (line terminator)", "data": "\u000a", "valid": true }, { "description": "paragraph separator matches (line terminator)", "data": "\u2029", "valid": true }, { "description": "EM SPACE matches (Space_Separator)", "data": "\u2003", "valid": true }, { "description": "Non-whitespace control does not match", "data": "\u0001", "valid": false }, { "description": "Non-whitespace does not match", "data": "\u2013", "valid": false } ] }, { "description": "ECMA 262 \\S matches everything but whitespace", "schema": { "type": "string", "pattern": "^\\S$" }, "tests": [ { "description": "ASCII space does not match", "data": " ", "valid": false }, { "description": "Character tabulation does not match", "data": "\t", "valid": false }, { "description": "Line tabulation does not match", "data": "\u000b", "valid": false }, { "description": "Form feed does not match", "data": "\u000c", "valid": false }, { "description": "latin-1 non-breaking-space does not match", "data": "\u00a0", "valid": false }, { "description": "zero-width whitespace does not match", "data": "\ufeff", "valid": false }, { "description": "line feed does not match (line terminator)", "data": "\u000a", "valid": false }, { "description": "paragraph separator does not match (line terminator)", "data": "\u2029", "valid": false }, { "description": "EM SPACE does not match (Space_Separator)", "data": "\u2003", "valid": false }, { "description": "Non-whitespace control matches", "data": "\u0001", "valid": true }, { "description": "Non-whitespace matches", "data": "\u2013", "valid": true } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/optional/float-overflow.json ================================================ [ { "description": "all integers are multiples of 0.5, if overflow is handled", "schema": {"type": "integer", "multipleOf": 0.5}, "tests": [ { "description": "valid if optional overflow handling is implemented", "data": 1e308, "valid": true } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/optional/format/date-time.json ================================================ [ { "description": "validation of date-time strings", "schema": {"format": "date-time"}, "tests": [ { "description": "a valid date-time string", "data": "1963-06-19T08:30:06.283185Z", "valid": true }, { "description": "a valid date-time string without second fraction", "data": "1963-06-19T08:30:06Z", "valid": true }, { "description": "a valid date-time string with plus offset", "data": "1937-01-01T12:00:27.87+00:20", "valid": true }, { "description": "a valid date-time string with minus offset", "data": "1990-12-31T15:59:50.123-08:00", "valid": true }, { "description": "a invalid day in date-time string", "data": "1990-02-31T15:59:60.123-08:00", "valid": false }, { "description": "an invalid offset in date-time string", "data": "1990-12-31T15:59:60-24:00", "valid": false }, { "description": "an invalid date-time string", "data": "06/19/1963 08:30:06 PST", "valid": false }, { "description": "case-insensitive T and Z", "data": "1963-06-19t08:30:06.283185z", "valid": true }, { "description": "only RFC3339 not all of ISO 8601 are valid", "data": "2013-350T01:01:01", "valid": false }, { "description": "invalid non-padded month dates", "data": "1963-6-19T08:30:06.283185Z", "valid": false }, { "description": "invalid non-padded day dates", "data": "1963-06-1T08:30:06.283185Z", "valid": false }, { "description": "non-ascii digits should be rejected in the date portion", "data": "1963-06-1৪T00:00:00Z", "valid": false }, { "description": "non-ascii digits should be rejected in the time portion", "data": "1963-06-11T0৪:00:00Z", "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/optional/format/date.json ================================================ [ { "description": "validation of date strings", "schema": {"format": "date"}, "tests": [ { "description": "a valid date string", "data": "1963-06-19", "valid": true }, { "description": "a valid date string with 31 days in January", "data": "2020-01-31", "valid": true }, { "description": "a invalid date string with 32 days in January", "data": "2020-01-32", "valid": false }, { "description": "a valid date string with 28 days in February (normal)", "data": "2021-02-28", "valid": true }, { "description": "a invalid date string with 29 days in February (normal)", "data": "2021-02-29", "valid": false }, { "description": "a valid date string with 29 days in February (leap)", "data": "2020-02-29", "valid": true }, { "description": "a invalid date string with 30 days in February (leap)", "data": "2020-02-30", "valid": false }, { "description": "a valid date string with 31 days in March", "data": "2020-03-31", "valid": true }, { "description": "a invalid date string with 32 days in March", "data": "2020-03-32", "valid": false }, { "description": "a valid date string with 30 days in April", "data": "2020-04-30", "valid": true }, { "description": "a invalid date string with 31 days in April", "data": "2020-04-31", "valid": false }, { "description": "a valid date string with 31 days in May", "data": "2020-05-31", "valid": true }, { "description": "a invalid date string with 32 days in May", "data": "2020-05-32", "valid": false }, { "description": "a valid date string with 30 days in June", "data": "2020-06-30", "valid": true }, { "description": "a invalid date string with 31 days in June", "data": "2020-06-31", "valid": false }, { "description": "a valid date string with 31 days in July", "data": "2020-07-31", "valid": true }, { "description": "a invalid date string with 32 days in July", "data": "2020-07-32", "valid": false }, { "description": "a valid date string with 31 days in August", "data": "2020-08-31", "valid": true }, { "description": "a invalid date string with 32 days in August", "data": "2020-08-32", "valid": false }, { "description": "a valid date string with 30 days in September", "data": "2020-09-30", "valid": true }, { "description": "a invalid date string with 31 days in September", "data": "2020-09-31", "valid": false }, { "description": "a valid date string with 31 days in October", "data": "2020-10-31", "valid": true }, { "description": "a invalid date string with 32 days in October", "data": "2020-10-32", "valid": false }, { "description": "a valid date string with 30 days in November", "data": "2020-11-30", "valid": true }, { "description": "a invalid date string with 31 days in November", "data": "2020-11-31", "valid": false }, { "description": "a valid date string with 31 days in December", "data": "2020-12-31", "valid": true }, { "description": "a invalid date string with 32 days in December", "data": "2020-12-32", "valid": false }, { "description": "a invalid date string with invalid month", "data": "2020-13-01", "valid": false }, { "description": "an invalid date string", "data": "06/19/1963", "valid": false }, { "description": "only RFC3339 not all of ISO 8601 are valid", "data": "2013-350", "valid": false }, { "description": "non-padded month dates are not valid", "data": "1998-1-20", "valid": false }, { "description": "non-padded day dates are not valid", "data": "1998-01-1", "valid": false }, { "description": "invalid month", "data": "1998-13-01", "valid": false }, { "description": "invalid month-day combination", "data": "1998-04-31", "valid": false }, { "description": "2021 is not a leap year", "data": "2021-02-29", "valid": false }, { "description": "2020 is a leap year", "data": "2020-02-29", "valid": true }, { "description": "non-ascii digits should be rejected", "data": "1963-06-1৪", "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/optional/format/email.json ================================================ [ { "description": "validation of e-mail addresses", "schema": {"format": "email"}, "tests": [ { "description": "a valid e-mail address", "data": "joe.bloggs@example.com", "valid": true }, { "description": "an invalid e-mail address", "data": "2962", "valid": false }, { "description": "tilde in local part is valid", "data": "te~st@example.com", "valid": true }, { "description": "tilde before local part is valid", "data": "~test@example.com", "valid": true }, { "description": "tilde after local part is valid", "data": "test~@example.com", "valid": true }, { "description": "dot before local part is not valid", "data": ".test@example.com", "valid": false }, { "description": "dot after local part is not valid", "data": "test.@example.com", "valid": false }, { "description": "two separated dots inside local part are valid", "data": "te.s.t@example.com", "valid": true }, { "description": "two subsequent dots inside local part are not valid", "data": "te..st@example.com", "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/optional/format/hostname.json ================================================ [ { "description": "validation of host names", "schema": {"format": "hostname"}, "tests": [ { "description": "a valid host name", "data": "www.example.com", "valid": true }, { "description": "a valid punycoded IDN hostname", "data": "xn--4gbwdl.xn--wgbh1c", "valid": true }, { "description": "a host name starting with an illegal character", "data": "-a-host-name-that-starts-with--", "valid": false }, { "description": "a host name containing illegal characters", "data": "not_a_valid_host_name", "valid": false }, { "description": "a host name with a component too long", "data": "a-vvvvvvvvvvvvvvvveeeeeeeeeeeeeeeerrrrrrrrrrrrrrrryyyyyyyyyyyyyyyy-long-host-name-component", "valid": false }, { "description": "starts with hyphen", "data": "-hostname", "valid": false }, { "description": "ends with hyphen", "data": "hostname-", "valid": false }, { "description": "starts with underscore", "data": "_hostname", "valid": false }, { "description": "ends with underscore", "data": "hostname_", "valid": false }, { "description": "contains underscore", "data": "host_name", "valid": false }, { "description": "maximum label length", "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com", "valid": true }, { "description": "exceeds maximum label length", "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl.com", "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/optional/format/idn-email.json ================================================ [ { "description": "validation of an internationalized e-mail addresses", "schema": {"format": "idn-email"}, "tests": [ { "description": "a valid idn e-mail (example@example.test in Hangul)", "data": "실례@실례.테스트", "valid": true }, { "description": "an invalid idn e-mail address", "data": "2962", "valid": false }, { "description": "a valid e-mail address", "data": "joe.bloggs@example.com", "valid": true }, { "description": "an invalid e-mail address", "data": "2962", "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/optional/format/idn-hostname.json ================================================ [ { "description": "validation of internationalized host names", "schema": {"format": "idn-hostname"}, "tests": [ { "description": "a valid host name (example.test in Hangul)", "data": "실례.테스트", "valid": true }, { "description": "illegal first char U+302E Hangul single dot tone mark", "data": "〮실례.테스트", "valid": false }, { "description": "contains illegal char U+302E Hangul single dot tone mark", "data": "실〮례.테스트", "valid": false }, { "description": "a host name with a component too long", "data": "실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실례례테스트례례례례례례례례례례례례례례례례례테스트례례례례례례례례례례례례례례례례례례례테스트례례례례례례례례례례례례테스트례례실례.테스트", "valid": false }, { "description": "invalid label, correct Punycode", "comment": "https://tools.ietf.org/html/rfc5890#section-2.3.2.1 https://tools.ietf.org/html/rfc5891#section-4.4 https://tools.ietf.org/html/rfc3492#section-7.1", "data": "-> $1.00 <--", "valid": false }, { "description": "valid Chinese Punycode", "comment": "https://tools.ietf.org/html/rfc5890#section-2.3.2.1 https://tools.ietf.org/html/rfc5891#section-4.4", "data": "xn--ihqwcrb4cv8a8dqg056pqjye", "valid": true }, { "description": "invalid Punycode", "comment": "https://tools.ietf.org/html/rfc5891#section-4.4 https://tools.ietf.org/html/rfc5890#section-2.3.2.1", "data": "xn--X", "valid": false }, { "description": "U-label contains \"--\" in the 3rd and 4th position", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1 https://tools.ietf.org/html/rfc5890#section-2.3.2.1", "data": "XN--aa---o47jg78q", "valid": false }, { "description": "U-label starts with a dash", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1", "data": "-hello", "valid": false }, { "description": "U-label ends with a dash", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1", "data": "hello-", "valid": false }, { "description": "U-label starts and ends with a dash", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1", "data": "-hello-", "valid": false }, { "description": "Begins with a Spacing Combining Mark", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2", "data": "\u0903hello", "valid": false }, { "description": "Begins with a Nonspacing Mark", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2", "data": "\u0300hello", "valid": false }, { "description": "Begins with an Enclosing Mark", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2", "data": "\u0488hello", "valid": false }, { "description": "Exceptions that are PVALID, left-to-right chars", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6", "data": "\u00df\u03c2\u0f0b\u3007", "valid": true }, { "description": "Exceptions that are PVALID, right-to-left chars", "comment": "https://tools.ietf.org/html/rfc/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6", "data": "\u06fd\u06fe", "valid": true }, { "description": "Exceptions that are DISALLOWED, right-to-left chars", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6", "data": "\u0640\u07fa", "valid": false }, { "description": "Exceptions that are DISALLOWED, left-to-right chars", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6 Note: The two combining marks (U+302E and U+302F) are in the middle and not at the start", "data": "\u3031\u3032\u3033\u3034\u3035\u302e\u302f\u303b", "valid": false }, { "description": "MIDDLE DOT with no preceding 'l'", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", "data": "a\u00b7l", "valid": false }, { "description": "MIDDLE DOT with nothing preceding", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", "data": "\u00b7l", "valid": false }, { "description": "MIDDLE DOT with no following 'l'", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", "data": "l\u00b7a", "valid": false }, { "description": "MIDDLE DOT with nothing following", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", "data": "l\u00b7", "valid": false }, { "description": "MIDDLE DOT with surrounding 'l's", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", "data": "l\u00b7l", "valid": true }, { "description": "Greek KERAIA not followed by Greek", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4", "data": "\u03b1\u0375S", "valid": false }, { "description": "Greek KERAIA not followed by anything", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4", "data": "\u03b1\u0375", "valid": false }, { "description": "Greek KERAIA followed by Greek", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4", "data": "\u03b1\u0375\u03b2", "valid": true }, { "description": "Hebrew GERESH not preceded by Hebrew", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5", "data": "A\u05f3\u05d1", "valid": false }, { "description": "Hebrew GERESH not preceded by anything", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5", "data": "\u05f3\u05d1", "valid": false }, { "description": "Hebrew GERESH preceded by Hebrew", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5", "data": "\u05d0\u05f3\u05d1", "valid": true }, { "description": "Hebrew GERSHAYIM not preceded by Hebrew", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6", "data": "A\u05f4\u05d1", "valid": false }, { "description": "Hebrew GERSHAYIM not preceded by anything", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6", "data": "\u05f4\u05d1", "valid": false }, { "description": "Hebrew GERSHAYIM preceded by Hebrew", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6", "data": "\u05d0\u05f4\u05d1", "valid": true }, { "description": "KATAKANA MIDDLE DOT with no Hiragana, Katakana, or Han", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", "data": "def\u30fbabc", "valid": false }, { "description": "KATAKANA MIDDLE DOT with no other characters", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", "data": "\u30fb", "valid": false }, { "description": "KATAKANA MIDDLE DOT with Hiragana", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", "data": "\u30fb\u3041", "valid": true }, { "description": "KATAKANA MIDDLE DOT with Katakana", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", "data": "\u30fb\u30a1", "valid": true }, { "description": "KATAKANA MIDDLE DOT with Han", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", "data": "\u30fb\u4e08", "valid": true }, { "description": "Arabic-Indic digits mixed with Extended Arabic-Indic digits", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.8", "data": "\u0660\u06f0", "valid": false }, { "description": "Arabic-Indic digits not mixed with Extended Arabic-Indic digits", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.8", "data": "\u0628\u0660\u0628", "valid": true }, { "description": "Extended Arabic-Indic digits not mixed with Arabic-Indic digits", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.9", "data": "\u06f00", "valid": true }, { "description": "ZERO WIDTH JOINER not preceded by Virama", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf", "data": "\u0915\u200d\u0937", "valid": false }, { "description": "ZERO WIDTH JOINER not preceded by anything", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf", "data": "\u200d\u0937", "valid": false }, { "description": "ZERO WIDTH JOINER preceded by Virama", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf", "data": "\u0915\u094d\u200d\u0937", "valid": true }, { "description": "ZERO WIDTH NON-JOINER preceded by Virama", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.1", "data": "\u0915\u094d\u200c\u0937", "valid": true }, { "description": "ZERO WIDTH NON-JOINER not preceded by Virama but matches regexp", "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.1 https://www.w3.org/TR/alreq/#h_disjoining_enforcement", "data": "\u0628\u064a\u200c\u0628\u064a", "valid": true } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/optional/format/ipv4.json ================================================ [ { "description": "validation of IP addresses", "schema": {"format": "ipv4"}, "tests": [ { "description": "a valid IP address", "data": "192.168.0.1", "valid": true }, { "description": "an IP address with too many components", "data": "127.0.0.0.1", "valid": false }, { "description": "an IP address with out-of-range values", "data": "256.256.256.256", "valid": false }, { "description": "an IP address without 4 components", "data": "127.0", "valid": false }, { "description": "an IP address as an integer", "data": "0x7f000001", "valid": false }, { "description": "an IP address as an integer (decimal)", "data": "2130706433", "valid": false }, { "description": "leading zeroes should be rejected, as they are treated as octals", "comment": "see https://sick.codes/universal-netmask-npm-package-used-by-270000-projects-vulnerable-to-octal-input-data-server-side-request-forgery-remote-file-inclusion-local-file-inclusion-and-more-cve-2021-28918/", "data": "087.10.0.1", "valid": false }, { "description": "value without leading zero is valid", "data": "87.10.0.1", "valid": true }, { "description": "non-ascii digits should be rejected", "data": "1২7.0.0.1", "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/optional/format/ipv6.json ================================================ [ { "description": "validation of IPv6 addresses", "schema": {"format": "ipv6"}, "tests": [ { "description": "a valid IPv6 address", "data": "::1", "valid": true }, { "description": "an IPv6 address with out-of-range values", "data": "12345::", "valid": false }, { "description": "an IPv6 address with too many components", "data": "1:1:1:1:1:1:1:1:1:1:1:1:1:1:1:1", "valid": false }, { "description": "an IPv6 address containing illegal characters", "data": "::laptop", "valid": false }, { "description": "no digits is valid", "data": "::", "valid": true }, { "description": "leading colons is valid", "data": "::42:ff:1", "valid": true }, { "description": "trailing colons is valid", "data": "d6::", "valid": true }, { "description": "missing leading octet is invalid", "data": ":2:3:4:5:6:7:8", "valid": false }, { "description": "missing trailing octet is invalid", "data": "1:2:3:4:5:6:7:", "valid": false }, { "description": "missing leading octet with omitted octets later", "data": ":2:3:4::8", "valid": false }, { "description": "two sets of double colons is invalid", "data": "1::d6::42", "valid": false }, { "description": "mixed format with the ipv4 section as decimal octets", "data": "1::d6:192.168.0.1", "valid": true }, { "description": "mixed format with double colons between the sections", "data": "1:2::192.168.0.1", "valid": true }, { "description": "mixed format with ipv4 section with octet out of range", "data": "1::2:192.168.256.1", "valid": false }, { "description": "mixed format with ipv4 section with a hex octet", "data": "1::2:192.168.ff.1", "valid": false }, { "description": "mixed format with leading double colons (ipv4-mapped ipv6 address)", "data": "::ffff:192.168.0.1", "valid": true }, { "description": "triple colons is invalid", "data": "1:2:3:4:5:::8", "valid": false }, { "description": "8 octets", "data": "1:2:3:4:5:6:7:8", "valid": true }, { "description": "insufficient octets without double colons", "data": "1:2:3:4:5:6:7", "valid": false }, { "description": "no colons is invalid", "data": "1", "valid": false }, { "description": "ipv4 is not ipv6", "data": "127.0.0.1", "valid": false }, { "description": "ipv4 segment must have 4 octets", "data": "1:2:3:4:1.2.3", "valid": false }, { "description": "leading whitespace is invalid", "data": " ::1", "valid": false }, { "description": "trailing whitespace is invalid", "data": "::1 ", "valid": false }, { "description": "netmask is not a part of ipv6 address", "data": "fe80::/64", "valid": false }, { "description": "zone id is not a part of ipv6 address", "data": "fe80::a%eth1", "valid": false }, { "description": "a long valid ipv6", "data": "1000:1000:1000:1000:1000:1000:255.255.255.255", "valid": true }, { "description": "a long invalid ipv6, below length limit, first", "data": "100:100:100:100:100:100:255.255.255.255.255", "valid": false }, { "description": "a long invalid ipv6, below length limit, second", "data": "100:100:100:100:100:100:100:255.255.255.255", "valid": false }, { "description": "non-ascii digits should be rejected", "data": "1:2:3:4:5:6:7:৪", "valid": false }, { "description": "non-ascii digits should be rejected in the ipv4 portion also", "data": "1:2::192.16৪.0.1", "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/optional/format/iri-reference.json ================================================ [ { "description": "validation of IRI References", "schema": {"format": "iri-reference"}, "tests": [ { "description": "a valid IRI", "data": "http://ƒøø.ßår/?∂éœ=πîx#πîüx", "valid": true }, { "description": "a valid protocol-relative IRI Reference", "data": "//ƒøø.ßår/?∂éœ=πîx#πîüx", "valid": true }, { "description": "a valid relative IRI Reference", "data": "/âππ", "valid": true }, { "description": "an invalid IRI Reference", "data": "\\\\WINDOWS\\filëßåré", "valid": false }, { "description": "a valid IRI Reference", "data": "âππ", "valid": true }, { "description": "a valid IRI fragment", "data": "#ƒrägmênt", "valid": true }, { "description": "an invalid IRI fragment", "data": "#ƒräg\\mênt", "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/optional/format/iri.json ================================================ [ { "description": "validation of IRIs", "schema": {"format": "iri"}, "tests": [ { "description": "a valid IRI with anchor tag", "data": "http://ƒøø.ßår/?∂éœ=πîx#πîüx", "valid": true }, { "description": "a valid IRI with anchor tag and parentheses", "data": "http://ƒøø.com/blah_(wîkïpédiå)_blah#ßité-1", "valid": true }, { "description": "a valid IRI with URL-encoded stuff", "data": "http://ƒøø.ßår/?q=Test%20URL-encoded%20stuff", "valid": true }, { "description": "a valid IRI with many special characters", "data": "http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com", "valid": true }, { "description": "a valid IRI based on IPv6", "data": "http://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]", "valid": true }, { "description": "an invalid IRI based on IPv6", "data": "http://2001:0db8:85a3:0000:0000:8a2e:0370:7334", "valid": false }, { "description": "an invalid relative IRI Reference", "data": "/abc", "valid": false }, { "description": "an invalid IRI", "data": "\\\\WINDOWS\\filëßåré", "valid": false }, { "description": "an invalid IRI though valid IRI reference", "data": "âππ", "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/optional/format/json-pointer.json ================================================ [ { "description": "validation of JSON-pointers (JSON String Representation)", "schema": {"format": "json-pointer"}, "tests": [ { "description": "a valid JSON-pointer", "data": "/foo/bar~0/baz~1/%a", "valid": true }, { "description": "not a valid JSON-pointer (~ not escaped)", "data": "/foo/bar~", "valid": false }, { "description": "valid JSON-pointer with empty segment", "data": "/foo//bar", "valid": true }, { "description": "valid JSON-pointer with the last empty segment", "data": "/foo/bar/", "valid": true }, { "description": "valid JSON-pointer as stated in RFC 6901 #1", "data": "", "valid": true }, { "description": "valid JSON-pointer as stated in RFC 6901 #2", "data": "/foo", "valid": true }, { "description": "valid JSON-pointer as stated in RFC 6901 #3", "data": "/foo/0", "valid": true }, { "description": "valid JSON-pointer as stated in RFC 6901 #4", "data": "/", "valid": true }, { "description": "valid JSON-pointer as stated in RFC 6901 #5", "data": "/a~1b", "valid": true }, { "description": "valid JSON-pointer as stated in RFC 6901 #6", "data": "/c%d", "valid": true }, { "description": "valid JSON-pointer as stated in RFC 6901 #7", "data": "/e^f", "valid": true }, { "description": "valid JSON-pointer as stated in RFC 6901 #8", "data": "/g|h", "valid": true }, { "description": "valid JSON-pointer as stated in RFC 6901 #9", "data": "/i\\j", "valid": true }, { "description": "valid JSON-pointer as stated in RFC 6901 #10", "data": "/k\"l", "valid": true }, { "description": "valid JSON-pointer as stated in RFC 6901 #11", "data": "/ ", "valid": true }, { "description": "valid JSON-pointer as stated in RFC 6901 #12", "data": "/m~0n", "valid": true }, { "description": "valid JSON-pointer used adding to the last array position", "data": "/foo/-", "valid": true }, { "description": "valid JSON-pointer (- used as object member name)", "data": "/foo/-/bar", "valid": true }, { "description": "valid JSON-pointer (multiple escaped characters)", "data": "/~1~0~0~1~1", "valid": true }, { "description": "valid JSON-pointer (escaped with fraction part) #1", "data": "/~1.1", "valid": true }, { "description": "valid JSON-pointer (escaped with fraction part) #2", "data": "/~0.1", "valid": true }, { "description": "not a valid JSON-pointer (URI Fragment Identifier) #1", "data": "#", "valid": false }, { "description": "not a valid JSON-pointer (URI Fragment Identifier) #2", "data": "#/", "valid": false }, { "description": "not a valid JSON-pointer (URI Fragment Identifier) #3", "data": "#a", "valid": false }, { "description": "not a valid JSON-pointer (some escaped, but not all) #1", "data": "/~0~", "valid": false }, { "description": "not a valid JSON-pointer (some escaped, but not all) #2", "data": "/~0/~", "valid": false }, { "description": "not a valid JSON-pointer (wrong escape character) #1", "data": "/~2", "valid": false }, { "description": "not a valid JSON-pointer (wrong escape character) #2", "data": "/~-1", "valid": false }, { "description": "not a valid JSON-pointer (multiple characters not escaped)", "data": "/~~", "valid": false }, { "description": "not a valid JSON-pointer (isn't empty nor starts with /) #1", "data": "a", "valid": false }, { "description": "not a valid JSON-pointer (isn't empty nor starts with /) #2", "data": "0", "valid": false }, { "description": "not a valid JSON-pointer (isn't empty nor starts with /) #3", "data": "a/a", "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/optional/format/regex.json ================================================ [ { "description": "validation of regular expressions", "schema": {"format": "regex"}, "tests": [ { "description": "a valid regular expression", "data": "([abc])+\\s+$", "valid": true }, { "description": "a regular expression with unclosed parens is invalid", "data": "^(abc]", "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/optional/format/relative-json-pointer.json ================================================ [ { "description": "validation of Relative JSON Pointers (RJP)", "schema": {"format": "relative-json-pointer"}, "tests": [ { "description": "a valid upwards RJP", "data": "1", "valid": true }, { "description": "a valid downwards RJP", "data": "0/foo/bar", "valid": true }, { "description": "a valid up and then down RJP, with array index", "data": "2/0/baz/1/zip", "valid": true }, { "description": "a valid RJP taking the member or index name", "data": "0#", "valid": true }, { "description": "an invalid RJP that is a valid JSON Pointer", "data": "/foo/bar", "valid": false }, { "description": "negative prefix", "data": "-1/foo/bar", "valid": false }, { "description": "## is not a valid json-pointer", "data": "0##", "valid": false }, { "description": "zero cannot be followed by other digits, plus json-pointer", "data": "01/a", "valid": false }, { "description": "zero cannot be followed by other digits, plus octothorpe", "data": "01#", "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/optional/format/time.json ================================================ [ { "description": "validation of time strings", "schema": {"format": "time"}, "tests": [ { "description": "a valid time string", "data": "08:30:06Z", "valid": true }, { "description": "a valid time string with leap second, Zulu", "data": "23:59:60Z", "valid": true }, { "description": "invalid leap second, Zulu (wrong hour)", "data": "22:59:60Z", "valid": false }, { "description": "invalid leap second, Zulu (wrong minute)", "data": "23:58:60Z", "valid": false }, { "description": "valid leap second, zero time-offset", "data": "23:59:60+00:00", "valid": true }, { "description": "invalid leap second, zero time-offset (wrong hour)", "data": "22:59:60+00:00", "valid": false }, { "description": "invalid leap second, zero time-offset (wrong minute)", "data": "23:58:60+00:00", "valid": false }, { "description": "valid leap second, positive time-offset", "data": "01:29:60+01:30", "valid": true }, { "description": "valid leap second, large positive time-offset", "data": "23:29:60+23:30", "valid": true }, { "description": "invalid leap second, positive time-offset (wrong hour)", "data": "23:59:60+01:00", "valid": false }, { "description": "invalid leap second, positive time-offset (wrong minute)", "data": "23:59:60+00:30", "valid": false }, { "description": "valid leap second, negative time-offset", "data": "15:59:60-08:00", "valid": true }, { "description": "valid leap second, large negative time-offset", "data": "00:29:60-23:30", "valid": true }, { "description": "invalid leap second, negative time-offset (wrong hour)", "data": "23:59:60-01:00", "valid": false }, { "description": "invalid leap second, negative time-offset (wrong minute)", "data": "23:59:60-00:30", "valid": false }, { "description": "a valid time string with second fraction", "data": "23:20:50.52Z", "valid": true }, { "description": "a valid time string with precise second fraction", "data": "08:30:06.283185Z", "valid": true }, { "description": "a valid time string with plus offset", "data": "08:30:06+00:20", "valid": true }, { "description": "a valid time string with minus offset", "data": "08:30:06-08:00", "valid": true }, { "description": "a valid time string with case-insensitive Z", "data": "08:30:06z", "valid": true }, { "description": "an invalid time string with invalid hour", "data": "24:00:00Z", "valid": false }, { "description": "an invalid time string with invalid minute", "data": "00:60:00Z", "valid": false }, { "description": "an invalid time string with invalid second", "data": "00:00:61Z", "valid": false }, { "description": "an invalid time string with invalid leap second (wrong hour)", "data": "22:59:60Z", "valid": false }, { "description": "an invalid time string with invalid leap second (wrong minute)", "data": "23:58:60Z", "valid": false }, { "description": "an invalid time string with invalid time numoffset hour", "data": "01:02:03+24:00", "valid": false }, { "description": "an invalid time string with invalid time numoffset minute", "data": "01:02:03+00:60", "valid": false }, { "description": "an invalid time string with invalid time with both Z and numoffset", "data": "01:02:03Z+00:30", "valid": false }, { "description": "an invalid offset indicator", "data": "08:30:06 PST", "valid": false }, { "description": "only RFC3339 not all of ISO 8601 are valid", "data": "01:01:01,1111", "valid": false }, { "description": "no time offset", "data": "12:00:00", "valid": false }, { "description": "non-ascii digits should be rejected", "data": "1২:00:00Z", "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/optional/format/uri-reference.json ================================================ [ { "description": "validation of URI References", "schema": {"format": "uri-reference"}, "tests": [ { "description": "a valid URI", "data": "http://foo.bar/?baz=qux#quux", "valid": true }, { "description": "a valid protocol-relative URI Reference", "data": "//foo.bar/?baz=qux#quux", "valid": true }, { "description": "a valid relative URI Reference", "data": "/abc", "valid": true }, { "description": "an invalid URI Reference", "data": "\\\\WINDOWS\\fileshare", "valid": false }, { "description": "a valid URI Reference", "data": "abc", "valid": true }, { "description": "a valid URI fragment", "data": "#fragment", "valid": true }, { "description": "an invalid URI fragment", "data": "#frag\\ment", "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/optional/format/uri-template.json ================================================ [ { "description": "format: uri-template", "schema": {"format": "uri-template"}, "tests": [ { "description": "a valid uri-template", "data": "http://example.com/dictionary/{term:1}/{term}", "valid": true }, { "description": "an invalid uri-template", "data": "http://example.com/dictionary/{term:1}/{term", "valid": false }, { "description": "a valid uri-template without variables", "data": "http://example.com/dictionary", "valid": true }, { "description": "a valid relative uri-template", "data": "dictionary/{term:1}/{term}", "valid": true } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/optional/format/uri.json ================================================ [ { "description": "validation of URIs", "schema": {"format": "uri"}, "tests": [ { "description": "a valid URL with anchor tag", "data": "http://foo.bar/?baz=qux#quux", "valid": true }, { "description": "a valid URL with anchor tag and parentheses", "data": "http://foo.com/blah_(wikipedia)_blah#cite-1", "valid": true }, { "description": "a valid URL with URL-encoded stuff", "data": "http://foo.bar/?q=Test%20URL-encoded%20stuff", "valid": true }, { "description": "a valid puny-coded URL ", "data": "http://xn--nw2a.xn--j6w193g/", "valid": true }, { "description": "a valid URL with many special characters", "data": "http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com", "valid": true }, { "description": "a valid URL based on IPv4", "data": "http://223.255.255.254", "valid": true }, { "description": "a valid URL with ftp scheme", "data": "ftp://ftp.is.co.za/rfc/rfc1808.txt", "valid": true }, { "description": "a valid URL for a simple text file", "data": "http://www.ietf.org/rfc/rfc2396.txt", "valid": true }, { "description": "a valid URL ", "data": "ldap://[2001:db8::7]/c=GB?objectClass?one", "valid": true }, { "description": "a valid mailto URI", "data": "mailto:John.Doe@example.com", "valid": true }, { "description": "a valid newsgroup URI", "data": "news:comp.infosystems.www.servers.unix", "valid": true }, { "description": "a valid tel URI", "data": "tel:+1-816-555-1212", "valid": true }, { "description": "a valid URN", "data": "urn:oasis:names:specification:docbook:dtd:xml:4.1.2", "valid": true }, { "description": "an invalid protocol-relative URI Reference", "data": "//foo.bar/?baz=qux#quux", "valid": false }, { "description": "an invalid relative URI Reference", "data": "/abc", "valid": false }, { "description": "an invalid URI", "data": "\\\\WINDOWS\\fileshare", "valid": false }, { "description": "an invalid URI though valid URI reference", "data": "abc", "valid": false }, { "description": "an invalid URI with spaces", "data": "http:// shouldfail.com", "valid": false }, { "description": "an invalid URI with spaces and missing scheme", "data": ":// should fail", "valid": false }, { "description": "an invalid URI with comma in scheme", "data": "bar,baz:foo", "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/optional/format/uuid.json ================================================ [ { "description": "uuid format", "schema": { "format": "uuid" }, "tests": [ { "description": "all upper-case", "data": "2EB8AA08-AA98-11EA-B4AA-73B441D16380", "valid": true }, { "description": "all lower-case", "data": "2eb8aa08-aa98-11ea-b4aa-73b441d16380", "valid": true }, { "description": "mixed case", "data": "2eb8aa08-AA98-11ea-B4Aa-73B441D16380", "valid": true }, { "description": "all zeroes is valid", "data": "00000000-0000-0000-0000-000000000000", "valid": true }, { "description": "wrong length", "data": "2eb8aa08-aa98-11ea-b4aa-73b441d1638", "valid": false }, { "description": "missing section", "data": "2eb8aa08-aa98-11ea-73b441d16380", "valid": false }, { "description": "bad characters (not hex)", "data": "2eb8aa08-aa98-11ea-b4ga-73b441d16380", "valid": false }, { "description": "no dashes", "data": "2eb8aa08aa9811eab4aa73b441d16380", "valid": false }, { "description": "too few dashes", "data": "2eb8aa08aa98-11ea-b4aa73b441d16380", "valid": false }, { "description": "too many dashes", "data": "2eb8-aa08-aa98-11ea-b4aa73b44-1d16380", "valid": false }, { "description": "dashes in the wrong spot", "data": "2eb8aa08aa9811eab4aa73b441d16380----", "valid": false }, { "description": "valid version 4", "data": "98d80576-482e-427f-8434-7f86890ab222", "valid": true }, { "description": "valid version 5", "data": "99c17cbb-656f-564a-940f-1a4568f03487", "valid": true }, { "description": "hypothetical version 6", "data": "99c17cbb-656f-664a-940f-1a4568f03487", "valid": true }, { "description": "hypothetical version 15", "data": "99c17cbb-656f-f64a-940f-1a4568f03487", "valid": true } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/optional/non-bmp-regex.json ================================================ [ { "description": "Proper UTF-16 surrogate pair handling: pattern", "comment": "Optional because .Net doesn't correctly handle 32-bit Unicode characters", "schema": { "pattern": "^🐲*$" }, "tests": [ { "description": "matches empty", "data": "", "valid": true }, { "description": "matches single", "data": "🐲", "valid": true }, { "description": "matches two", "data": "🐲🐲", "valid": true }, { "description": "doesn't match one", "data": "🐉", "valid": false }, { "description": "doesn't match two", "data": "🐉🐉", "valid": false }, { "description": "doesn't match one ASCII", "data": "D", "valid": false }, { "description": "doesn't match two ASCII", "data": "DD", "valid": false } ] }, { "description": "Proper UTF-16 surrogate pair handling: patternProperties", "comment": "Optional because .Net doesn't correctly handle 32-bit Unicode characters", "schema": { "patternProperties": { "^🐲*$": { "type": "integer" } } }, "tests": [ { "description": "matches empty", "data": { "": 1 }, "valid": true }, { "description": "matches single", "data": { "🐲": 1 }, "valid": true }, { "description": "matches two", "data": { "🐲🐲": 1 }, "valid": true }, { "description": "doesn't match one", "data": { "🐲": "hello" }, "valid": false }, { "description": "doesn't match two", "data": { "🐲🐲": "hello" }, "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/optional/unicode.json ================================================ [ { "description": "unicode semantics should be used for all pattern matching", "schema": { "pattern": "\\wcole" }, "tests": [ { "description": "literal unicode character in json string", "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", "valid": true }, { "description": "unicode character in hex format in string", "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'\u00e9cole, l'église et la patinoire; mais la vraie vie était sur la patinoire.", "valid": true }, { "description": "unicode matching is case-sensitive", "data": "LES HIVERS DE MON ENFANCE ÉTAIENT DES SAISONS LONGUES, LONGUES. NOUS VIVIONS EN TROIS LIEUX: L'ÉCOLE, L'ÉGLISE ET LA PATINOIRE; MAIS LA VRAIE VIE ÉTAIT SUR LA PATINOIRE.", "valid": false } ] }, { "description": "unicode characters do not match ascii ranges", "schema": { "pattern": "[a-z]cole" }, "tests": [ { "description": "literal unicode character in json string", "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", "valid": false }, { "description": "unicode character in hex format in string", "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'\u00e9cole, l'église et la patinoire; mais la vraie vie était sur la patinoire.", "valid": false }, { "description": "ascii characters match", "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", "valid": true } ] }, { "description": "unicode digits are more than 0 through 9", "schema": { "pattern": "^\\d+$" }, "tests": [ { "description": "ascii digits", "data": "42", "valid": true }, { "description": "ascii non-digits", "data": "-%#", "valid": false }, { "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", "data": "৪২", "valid": true } ] }, { "description": "unicode semantics should be used for all patternProperties matching", "schema": { "type": "object", "patternProperties": { "\\wcole": true }, "additionalProperties": false }, "tests": [ { "description": "literal unicode character in json string", "data": { "l'école": "pas de vraie vie" }, "valid": true }, { "description": "unicode character in hex format in string", "data": { "l'\u00e9cole": "pas de vraie vie" }, "valid": true }, { "description": "unicode matching is case-sensitive", "data": { "L'ÉCOLE": "PAS DE VRAIE VIE" }, "valid": false } ] }, { "description": "unicode characters do not match ascii ranges", "schema": { "type": "object", "patternProperties": { "[a-z]cole": true }, "additionalProperties": false }, "tests": [ { "description": "literal unicode character in json string", "data": { "l'école": "pas de vraie vie" }, "valid": false }, { "description": "unicode character in hex format in string", "data": { "l'\u00e9cole": "pas de vraie vie" }, "valid": false }, { "description": "ascii characters match", "data": { "l'ecole": "pas de vraie vie" }, "valid": true } ] }, { "description": "unicode digits are more than 0 through 9", "schema": { "type": "object", "patternProperties": { "^\\d+$": true }, "additionalProperties": false }, "tests": [ { "description": "ascii digits", "data": { "42": "life, the universe, and everything" }, "valid": true }, { "description": "ascii non-digits", "data": { "-%#": "spending the year dead for tax reasons" }, "valid": false }, { "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", "data": { "৪২": "khajit has wares if you have coin" }, "valid": true } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/pattern.json ================================================ [ { "description": "pattern validation", "schema": {"pattern": "^a*$"}, "tests": [ { "description": "a matching pattern is valid", "data": "aaa", "valid": true }, { "description": "a non-matching pattern is invalid", "data": "abc", "valid": false }, { "description": "ignores booleans", "data": true, "valid": true }, { "description": "ignores integers", "data": 123, "valid": true }, { "description": "ignores floats", "data": 1.0, "valid": true }, { "description": "ignores objects", "data": {}, "valid": true }, { "description": "ignores arrays", "data": [], "valid": true }, { "description": "ignores null", "data": null, "valid": true } ] }, { "description": "pattern is not anchored", "schema": {"pattern": "a+"}, "tests": [ { "description": "matches a substring", "data": "xxaayy", "valid": true } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/patternProperties.json ================================================ [ { "description": "patternProperties validates properties matching a regex", "schema": { "patternProperties": { "f.*o": {"type": "integer"} } }, "tests": [ { "description": "a single valid match is valid", "data": {"foo": 1}, "valid": true }, { "description": "multiple valid matches is valid", "data": {"foo": 1, "foooooo" : 2}, "valid": true }, { "description": "a single invalid match is invalid", "data": {"foo": "bar", "fooooo": 2}, "valid": false }, { "description": "multiple invalid matches is invalid", "data": {"foo": "bar", "foooooo" : "baz"}, "valid": false }, { "description": "ignores arrays", "data": ["foo"], "valid": true }, { "description": "ignores strings", "data": "foo", "valid": true }, { "description": "ignores other non-objects", "data": 12, "valid": true } ] }, { "description": "multiple simultaneous patternProperties are validated", "schema": { "patternProperties": { "a*": {"type": "integer"}, "aaa*": {"maximum": 20} } }, "tests": [ { "description": "a single valid match is valid", "data": {"a": 21}, "valid": true }, { "description": "a simultaneous match is valid", "data": {"aaaa": 18}, "valid": true }, { "description": "multiple matches is valid", "data": {"a": 21, "aaaa": 18}, "valid": true }, { "description": "an invalid due to one is invalid", "data": {"a": "bar"}, "valid": false }, { "description": "an invalid due to the other is invalid", "data": {"aaaa": 31}, "valid": false }, { "description": "an invalid due to both is invalid", "data": {"aaa": "foo", "aaaa": 31}, "valid": false } ] }, { "description": "regexes are not anchored by default and are case sensitive", "schema": { "patternProperties": { "[0-9]{2,}": { "type": "boolean" }, "X_": { "type": "string" } } }, "tests": [ { "description": "non recognized members are ignored", "data": { "answer 1": "42" }, "valid": true }, { "description": "recognized members are accounted for", "data": { "a31b": null }, "valid": false }, { "description": "regexes are case sensitive", "data": { "a_x_3": 3 }, "valid": true }, { "description": "regexes are case sensitive, 2", "data": { "a_X_3": 3 }, "valid": false } ] }, { "description": "patternProperties with boolean schemas", "schema": { "patternProperties": { "f.*": true, "b.*": false } }, "tests": [ { "description": "object with property matching schema true is valid", "data": {"foo": 1}, "valid": true }, { "description": "object with property matching schema false is invalid", "data": {"bar": 2}, "valid": false }, { "description": "object with both properties is invalid", "data": {"foo": 1, "bar": 2}, "valid": false }, { "description": "object with a property matching both true and false is invalid", "data": {"foobar":1}, "valid": false }, { "description": "empty object is valid", "data": {}, "valid": true } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/properties.json ================================================ [ { "description": "object properties validation", "schema": { "properties": { "foo": {"type": "integer"}, "bar": {"type": "string"} } }, "tests": [ { "description": "both properties present and valid is valid", "data": {"foo": 1, "bar": "baz"}, "valid": true }, { "description": "one property invalid is invalid", "data": {"foo": 1, "bar": {}}, "valid": false }, { "description": "both properties invalid is invalid", "data": {"foo": [], "bar": {}}, "valid": false }, { "description": "doesn't invalidate other properties", "data": {"quux": []}, "valid": true }, { "description": "ignores arrays", "data": [], "valid": true }, { "description": "ignores other non-objects", "data": 12, "valid": true } ] }, { "description": "properties, patternProperties, additionalProperties interaction", "schema": { "properties": { "foo": {"type": "array", "maxItems": 3}, "bar": {"type": "array"} }, "patternProperties": {"f.o": {"minItems": 2}}, "additionalProperties": {"type": "integer"} }, "tests": [ { "description": "property validates property", "data": {"foo": [1, 2]}, "valid": true }, { "description": "property invalidates property", "data": {"foo": [1, 2, 3, 4]}, "valid": false }, { "description": "patternProperty invalidates property", "data": {"foo": []}, "valid": false }, { "description": "patternProperty validates nonproperty", "data": {"fxo": [1, 2]}, "valid": true }, { "description": "patternProperty invalidates nonproperty", "data": {"fxo": []}, "valid": false }, { "description": "additionalProperty ignores property", "data": {"bar": []}, "valid": true }, { "description": "additionalProperty validates others", "data": {"quux": 3}, "valid": true }, { "description": "additionalProperty invalidates others", "data": {"quux": "foo"}, "valid": false } ] }, { "description": "properties with boolean schema", "schema": { "properties": { "foo": true, "bar": false } }, "tests": [ { "description": "no property present is valid", "data": {}, "valid": true }, { "description": "only 'true' property present is valid", "data": {"foo": 1}, "valid": true }, { "description": "only 'false' property present is invalid", "data": {"bar": 2}, "valid": false }, { "description": "both properties present is invalid", "data": {"foo": 1, "bar": 2}, "valid": false } ] }, { "description": "properties with escaped characters", "schema": { "properties": { "foo\nbar": {"type": "number"}, "foo\"bar": {"type": "number"}, "foo\\bar": {"type": "number"}, "foo\rbar": {"type": "number"}, "foo\tbar": {"type": "number"}, "foo\fbar": {"type": "number"} } }, "tests": [ { "description": "object with all numbers is valid", "data": { "foo\nbar": 1, "foo\"bar": 1, "foo\\bar": 1, "foo\rbar": 1, "foo\tbar": 1, "foo\fbar": 1 }, "valid": true }, { "description": "object with strings is invalid", "data": { "foo\nbar": "1", "foo\"bar": "1", "foo\\bar": "1", "foo\rbar": "1", "foo\tbar": "1", "foo\fbar": "1" }, "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/propertyNames.json ================================================ [ { "description": "propertyNames validation", "schema": { "propertyNames": {"maxLength": 3} }, "tests": [ { "description": "all property names valid", "data": { "f": {}, "foo": {} }, "valid": true }, { "description": "some property names invalid", "data": { "foo": {}, "foobar": {} }, "valid": false }, { "description": "object without properties is valid", "data": {}, "valid": true }, { "description": "ignores arrays", "data": [1, 2, 3, 4], "valid": true }, { "description": "ignores strings", "data": "foobar", "valid": true }, { "description": "ignores other non-objects", "data": 12, "valid": true } ] }, { "description": "propertyNames validation with pattern", "schema": { "propertyNames": { "pattern": "^a+$" } }, "tests": [ { "description": "matching property names valid", "data": { "a": {}, "aa": {}, "aaa": {} }, "valid": true }, { "description": "non-matching property name is invalid", "data": { "aaA": {} }, "valid": false }, { "description": "object without properties is valid", "data": {}, "valid": true } ] }, { "description": "propertyNames with boolean schema true", "schema": {"propertyNames": true}, "tests": [ { "description": "object with any properties is valid", "data": {"foo": 1}, "valid": true }, { "description": "empty object is valid", "data": {}, "valid": true } ] }, { "description": "propertyNames with boolean schema false", "schema": {"propertyNames": false}, "tests": [ { "description": "object with any properties is invalid", "data": {"foo": 1}, "valid": false }, { "description": "empty object is valid", "data": {}, "valid": true } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/ref.json ================================================ [ { "description": "root pointer ref", "schema": { "properties": { "foo": {"$ref": "#"} }, "additionalProperties": false }, "tests": [ { "description": "match", "data": {"foo": false}, "valid": true }, { "description": "recursive match", "data": {"foo": {"foo": false}}, "valid": true }, { "description": "mismatch", "data": {"bar": false}, "valid": false }, { "description": "recursive mismatch", "data": {"foo": {"bar": false}}, "valid": false } ] }, { "description": "relative pointer ref to object", "schema": { "properties": { "foo": {"type": "integer"}, "bar": {"$ref": "#/properties/foo"} } }, "tests": [ { "description": "match", "data": {"bar": 3}, "valid": true }, { "description": "mismatch", "data": {"bar": true}, "valid": false } ] }, { "description": "relative pointer ref to array", "schema": { "items": [ {"type": "integer"}, {"$ref": "#/items/0"} ] }, "tests": [ { "description": "match array", "data": [1, 2], "valid": true }, { "description": "mismatch array", "data": [1, "foo"], "valid": false } ] }, { "description": "escaped pointer ref", "schema": { "definitions": { "tilde~field": {"type": "integer"}, "slash/field": {"type": "integer"}, "percent%field": {"type": "integer"} }, "properties": { "tilde": {"$ref": "#/definitions/tilde~0field"}, "slash": {"$ref": "#/definitions/slash~1field"}, "percent": {"$ref": "#/definitions/percent%25field"} } }, "tests": [ { "description": "slash invalid", "data": {"slash": "aoeu"}, "valid": false }, { "description": "tilde invalid", "data": {"tilde": "aoeu"}, "valid": false }, { "description": "percent invalid", "data": {"percent": "aoeu"}, "valid": false }, { "description": "slash valid", "data": {"slash": 123}, "valid": true }, { "description": "tilde valid", "data": {"tilde": 123}, "valid": true }, { "description": "percent valid", "data": {"percent": 123}, "valid": true } ] }, { "description": "nested refs", "schema": { "definitions": { "a": {"type": "integer"}, "b": {"$ref": "#/definitions/a"}, "c": {"$ref": "#/definitions/b"} }, "allOf": [{ "$ref": "#/definitions/c" }] }, "tests": [ { "description": "nested ref valid", "data": 5, "valid": true }, { "description": "nested ref invalid", "data": "a", "valid": false } ] }, { "description": "ref overrides any sibling keywords", "schema": { "definitions": { "reffed": { "type": "array" } }, "properties": { "foo": { "$ref": "#/definitions/reffed", "maxItems": 2 } } }, "tests": [ { "description": "ref valid", "data": { "foo": [] }, "valid": true }, { "description": "ref valid, maxItems ignored", "data": { "foo": [ 1, 2, 3] }, "valid": true }, { "description": "ref invalid", "data": { "foo": "string" }, "valid": false } ] }, { "description": "$ref prevents a sibling $id from changing the base uri", "schema": { "$id": "http://localhost:1234/sibling_id/base/", "definitions": { "foo": { "$id": "http://localhost:1234/sibling_id/foo.json", "minimum": 2 }, "base_foo": { "$comment": "this canonical uri is http://localhost:1234/sibling_id/base/foo.json", "$id": "foo.json", "minimum": 5 } }, "allOf": [ { "$comment": "$ref resolves to http://localhost:1234/sibling_id/base/foo.json, not ttp://localhost:1234/sibling_id/foo.json", "$id": "http://localhost:1234/sibling_id/", "$ref": "foo.json" } ] }, "tests": [ { "description": "$ref resolves to /definitions/foo, data validates", "data": 10, "valid": true }, { "description": "$ref resolves to /definitions/foo, data does not validate", "data": 1, "valid": false } ] }, { "description": "remote ref, containing refs itself", "schema": {"$ref": "http://json-schema.org/draft-07/schema#"}, "tests": [ { "description": "remote ref valid", "data": {"minLength": 1}, "valid": true }, { "description": "remote ref invalid", "data": {"minLength": -1}, "valid": false } ] }, { "description": "property named $ref that is not a reference", "schema": { "properties": { "$ref": {"type": "string"} } }, "tests": [ { "description": "property named $ref valid", "data": {"$ref": "a"}, "valid": true }, { "description": "property named $ref invalid", "data": {"$ref": 2}, "valid": false } ] }, { "description": "property named $ref, containing an actual $ref", "schema": { "properties": { "$ref": {"$ref": "#/definitions/is-string"} }, "definitions": { "is-string": { "type": "string" } } }, "tests": [ { "description": "property named $ref valid", "data": {"$ref": "a"}, "valid": true }, { "description": "property named $ref invalid", "data": {"$ref": 2}, "valid": false } ] }, { "description": "$ref to boolean schema true", "schema": { "allOf": [{ "$ref": "#/definitions/bool" }], "definitions": { "bool": true } }, "tests": [ { "description": "any value is valid", "data": "foo", "valid": true } ] }, { "description": "$ref to boolean schema false", "schema": { "allOf": [{ "$ref": "#/definitions/bool" }], "definitions": { "bool": false } }, "tests": [ { "description": "any value is invalid", "data": "foo", "valid": false } ] }, { "description": "Recursive references between schemas", "schema": { "$id": "http://localhost:1234/tree", "description": "tree of nodes", "type": "object", "properties": { "meta": {"type": "string"}, "nodes": { "type": "array", "items": {"$ref": "node"} } }, "required": ["meta", "nodes"], "definitions": { "node": { "$id": "http://localhost:1234/node", "description": "node", "type": "object", "properties": { "value": {"type": "number"}, "subtree": {"$ref": "tree"} }, "required": ["value"] } } }, "tests": [ { "description": "valid tree", "data": { "meta": "root", "nodes": [ { "value": 1, "subtree": { "meta": "child", "nodes": [ {"value": 1.1}, {"value": 1.2} ] } }, { "value": 2, "subtree": { "meta": "child", "nodes": [ {"value": 2.1}, {"value": 2.2} ] } } ] }, "valid": true }, { "description": "invalid tree", "data": { "meta": "root", "nodes": [ { "value": 1, "subtree": { "meta": "child", "nodes": [ {"value": "string is invalid"}, {"value": 1.2} ] } }, { "value": 2, "subtree": { "meta": "child", "nodes": [ {"value": 2.1}, {"value": 2.2} ] } } ] }, "valid": false } ] }, { "description": "refs with quote", "schema": { "properties": { "foo\"bar": {"$ref": "#/definitions/foo%22bar"} }, "definitions": { "foo\"bar": {"type": "number"} } }, "tests": [ { "description": "object with numbers is valid", "data": { "foo\"bar": 1 }, "valid": true }, { "description": "object with strings is invalid", "data": { "foo\"bar": "1" }, "valid": false } ] }, { "description": "Location-independent identifier", "schema": { "allOf": [{ "$ref": "#foo" }], "definitions": { "A": { "$id": "#foo", "type": "integer" } } }, "tests": [ { "data": 1, "description": "match", "valid": true }, { "data": "a", "description": "mismatch", "valid": false } ] }, { "description": "Location-independent identifier with base URI change in subschema", "schema": { "$id": "http://localhost:1234/root", "allOf": [{ "$ref": "http://localhost:1234/nested.json#foo" }], "definitions": { "A": { "$id": "nested.json", "definitions": { "B": { "$id": "#foo", "type": "integer" } } } } }, "tests": [ { "data": 1, "description": "match", "valid": true }, { "data": "a", "description": "mismatch", "valid": false } ] }, { "description": "naive replacement of $ref with its destination is not correct", "schema": { "definitions": { "a_string": { "type": "string" } }, "enum": [ { "$ref": "#/definitions/a_string" } ] }, "tests": [ { "description": "do not evaluate the $ref inside the enum, matching any string", "data": "this is a string", "valid": false }, { "description": "do not evaluate the $ref inside the enum, definition exact match", "data": { "type": "string" }, "valid": false }, { "description": "match the enum exactly", "data": { "$ref": "#/definitions/a_string" }, "valid": true } ] }, { "description": "refs with relative uris and defs", "schema": { "$id": "http://example.com/schema-relative-uri-defs1.json", "properties": { "foo": { "$id": "schema-relative-uri-defs2.json", "definitions": { "inner": { "properties": { "bar": { "type": "string" } } } }, "allOf": [ { "$ref": "#/definitions/inner" } ] } }, "allOf": [ { "$ref": "schema-relative-uri-defs2.json" } ] }, "tests": [ { "description": "invalid on inner field", "data": { "foo": { "bar": 1 }, "bar": "a" }, "valid": false }, { "description": "invalid on outer field", "data": { "foo": { "bar": "a" }, "bar": 1 }, "valid": false }, { "description": "valid on both fields", "data": { "foo": { "bar": "a" }, "bar": "a" }, "valid": true } ] }, { "description": "relative refs with absolute uris and defs", "schema": { "$id": "http://example.com/schema-refs-absolute-uris-defs1.json", "properties": { "foo": { "$id": "http://example.com/schema-refs-absolute-uris-defs2.json", "definitions": { "inner": { "properties": { "bar": { "type": "string" } } } }, "allOf": [ { "$ref": "#/definitions/inner" } ] } }, "allOf": [ { "$ref": "schema-refs-absolute-uris-defs2.json" } ] }, "tests": [ { "description": "invalid on inner field", "data": { "foo": { "bar": 1 }, "bar": "a" }, "valid": false }, { "description": "invalid on outer field", "data": { "foo": { "bar": "a" }, "bar": 1 }, "valid": false }, { "description": "valid on both fields", "data": { "foo": { "bar": "a" }, "bar": "a" }, "valid": true } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/refRemote.json ================================================ [ { "description": "remote ref", "schema": {"$ref": "http://localhost:1234/integer.json"}, "tests": [ { "description": "remote ref valid", "data": 1, "valid": true }, { "description": "remote ref invalid", "data": "a", "valid": false } ] }, { "description": "fragment within remote ref", "schema": {"$ref": "http://localhost:1234/subSchemas.json#/integer"}, "tests": [ { "description": "remote fragment valid", "data": 1, "valid": true }, { "description": "remote fragment invalid", "data": "a", "valid": false } ] }, { "description": "ref within remote ref", "schema": { "$ref": "http://localhost:1234/subSchemas.json#/refToInteger" }, "tests": [ { "description": "ref within ref valid", "data": 1, "valid": true }, { "description": "ref within ref invalid", "data": "a", "valid": false } ] }, { "description": "base URI change", "schema": { "$id": "http://localhost:1234/", "items": { "$id": "baseUriChange/", "items": {"$ref": "folderInteger.json"} } }, "tests": [ { "description": "base URI change ref valid", "data": [[1]], "valid": true }, { "description": "base URI change ref invalid", "data": [["a"]], "valid": false } ] }, { "description": "base URI change - change folder", "schema": { "$id": "http://localhost:1234/scope_change_defs1.json", "type" : "object", "properties": { "list": {"$ref": "#/definitions/baz"} }, "definitions": { "baz": { "$id": "baseUriChangeFolder/", "type": "array", "items": {"$ref": "folderInteger.json"} } } }, "tests": [ { "description": "number is valid", "data": {"list": [1]}, "valid": true }, { "description": "string is invalid", "data": {"list": ["a"]}, "valid": false } ] }, { "description": "base URI change - change folder in subschema", "schema": { "$id": "http://localhost:1234/scope_change_defs2.json", "type" : "object", "properties": { "list": {"$ref": "#/definitions/baz/definitions/bar"} }, "definitions": { "baz": { "$id": "baseUriChangeFolderInSubschema/", "definitions": { "bar": { "type": "array", "items": {"$ref": "folderInteger.json"} } } } } }, "tests": [ { "description": "number is valid", "data": {"list": [1]}, "valid": true }, { "description": "string is invalid", "data": {"list": ["a"]}, "valid": false } ] }, { "description": "root ref in remote ref", "schema": { "$id": "http://localhost:1234/object", "type": "object", "properties": { "name": {"$ref": "name.json#/definitions/orNull"} } }, "tests": [ { "description": "string is valid", "data": { "name": "foo" }, "valid": true }, { "description": "null is valid", "data": { "name": null }, "valid": true }, { "description": "object is invalid", "data": { "name": { "name": null } }, "valid": false } ] }, { "description": "remote ref with ref to definitions", "schema": { "$id": "http://localhost:1234/schema-remote-ref-ref-defs1.json", "allOf": [ { "$ref": "ref-and-definitions.json" } ] }, "tests": [ { "description": "invalid", "data": { "bar": 1 }, "valid": false }, { "description": "valid", "data": { "bar": "a" }, "valid": true } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/required.json ================================================ [ { "description": "required validation", "schema": { "properties": { "foo": {}, "bar": {} }, "required": ["foo"] }, "tests": [ { "description": "present required property is valid", "data": {"foo": 1}, "valid": true }, { "description": "non-present required property is invalid", "data": {"bar": 1}, "valid": false }, { "description": "ignores arrays", "data": [], "valid": true }, { "description": "ignores strings", "data": "", "valid": true }, { "description": "ignores other non-objects", "data": 12, "valid": true } ] }, { "description": "required default validation", "schema": { "properties": { "foo": {} } }, "tests": [ { "description": "not required by default", "data": {}, "valid": true } ] }, { "description": "required with empty array", "schema": { "properties": { "foo": {} }, "required": [] }, "tests": [ { "description": "property not required", "data": {}, "valid": true } ] }, { "description": "required with escaped characters", "schema": { "required": [ "foo\nbar", "foo\"bar", "foo\\bar", "foo\rbar", "foo\tbar", "foo\fbar" ] }, "tests": [ { "description": "object with all properties present is valid", "data": { "foo\nbar": 1, "foo\"bar": 1, "foo\\bar": 1, "foo\rbar": 1, "foo\tbar": 1, "foo\fbar": 1 }, "valid": true }, { "description": "object with some properties missing is invalid", "data": { "foo\nbar": "1", "foo\"bar": "1" }, "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/type.json ================================================ [ { "description": "integer type matches integers", "schema": {"type": "integer"}, "tests": [ { "description": "an integer is an integer", "data": 1, "valid": true }, { "description": "a float is not an integer", "data": 1.1, "valid": false }, { "description": "a string is not an integer", "data": "foo", "valid": false }, { "description": "a string is still not an integer, even if it looks like one", "data": "1", "valid": false }, { "description": "an object is not an integer", "data": {}, "valid": false }, { "description": "an array is not an integer", "data": [], "valid": false }, { "description": "a boolean is not an integer", "data": true, "valid": false }, { "description": "null is not an integer", "data": null, "valid": false } ] }, { "description": "number type matches numbers", "schema": {"type": "number"}, "tests": [ { "description": "an integer is a number", "data": 1, "valid": true }, { "description": "a float with zero fractional part is a number (and an integer)", "data": 1.0, "valid": true }, { "description": "a float is a number", "data": 1.1, "valid": true }, { "description": "a string is not a number", "data": "foo", "valid": false }, { "description": "a string is still not a number, even if it looks like one", "data": "1", "valid": false }, { "description": "an object is not a number", "data": {}, "valid": false }, { "description": "an array is not a number", "data": [], "valid": false }, { "description": "a boolean is not a number", "data": true, "valid": false }, { "description": "null is not a number", "data": null, "valid": false } ] }, { "description": "string type matches strings", "schema": {"type": "string"}, "tests": [ { "description": "1 is not a string", "data": 1, "valid": false }, { "description": "a float is not a string", "data": 1.1, "valid": false }, { "description": "a string is a string", "data": "foo", "valid": true }, { "description": "a string is still a string, even if it looks like a number", "data": "1", "valid": true }, { "description": "an empty string is still a string", "data": "", "valid": true }, { "description": "an object is not a string", "data": {}, "valid": false }, { "description": "an array is not a string", "data": [], "valid": false }, { "description": "a boolean is not a string", "data": true, "valid": false }, { "description": "null is not a string", "data": null, "valid": false } ] }, { "description": "object type matches objects", "schema": {"type": "object"}, "tests": [ { "description": "an integer is not an object", "data": 1, "valid": false }, { "description": "a float is not an object", "data": 1.1, "valid": false }, { "description": "a string is not an object", "data": "foo", "valid": false }, { "description": "an object is an object", "data": {}, "valid": true }, { "description": "an array is not an object", "data": [], "valid": false }, { "description": "a boolean is not an object", "data": true, "valid": false }, { "description": "null is not an object", "data": null, "valid": false } ] }, { "description": "array type matches arrays", "schema": {"type": "array"}, "tests": [ { "description": "an integer is not an array", "data": 1, "valid": false }, { "description": "a float is not an array", "data": 1.1, "valid": false }, { "description": "a string is not an array", "data": "foo", "valid": false }, { "description": "an object is not an array", "data": {}, "valid": false }, { "description": "an array is an array", "data": [], "valid": true }, { "description": "a boolean is not an array", "data": true, "valid": false }, { "description": "null is not an array", "data": null, "valid": false } ] }, { "description": "boolean type matches booleans", "schema": {"type": "boolean"}, "tests": [ { "description": "an integer is not a boolean", "data": 1, "valid": false }, { "description": "zero is not a boolean", "data": 0, "valid": false }, { "description": "a float is not a boolean", "data": 1.1, "valid": false }, { "description": "a string is not a boolean", "data": "foo", "valid": false }, { "description": "an empty string is not a boolean", "data": "", "valid": false }, { "description": "an object is not a boolean", "data": {}, "valid": false }, { "description": "an array is not a boolean", "data": [], "valid": false }, { "description": "true is a boolean", "data": true, "valid": true }, { "description": "false is a boolean", "data": false, "valid": true }, { "description": "null is not a boolean", "data": null, "valid": false } ] }, { "description": "null type matches only the null object", "schema": {"type": "null"}, "tests": [ { "description": "an integer is not null", "data": 1, "valid": false }, { "description": "a float is not null", "data": 1.1, "valid": false }, { "description": "zero is not null", "data": 0, "valid": false }, { "description": "a string is not null", "data": "foo", "valid": false }, { "description": "an empty string is not null", "data": "", "valid": false }, { "description": "an object is not null", "data": {}, "valid": false }, { "description": "an array is not null", "data": [], "valid": false }, { "description": "true is not null", "data": true, "valid": false }, { "description": "false is not null", "data": false, "valid": false }, { "description": "null is null", "data": null, "valid": true } ] }, { "description": "multiple types can be specified in an array", "schema": {"type": ["integer", "string"]}, "tests": [ { "description": "an integer is valid", "data": 1, "valid": true }, { "description": "a string is valid", "data": "foo", "valid": true }, { "description": "a float is invalid", "data": 1.1, "valid": false }, { "description": "an object is invalid", "data": {}, "valid": false }, { "description": "an array is invalid", "data": [], "valid": false }, { "description": "a boolean is invalid", "data": true, "valid": false }, { "description": "null is invalid", "data": null, "valid": false } ] }, { "description": "type as array with one item", "schema": { "type": ["string"] }, "tests": [ { "description": "string is valid", "data": "foo", "valid": true }, { "description": "number is invalid", "data": 123, "valid": false } ] }, { "description": "type: array or object", "schema": { "type": ["array", "object"] }, "tests": [ { "description": "array is valid", "data": [1,2,3], "valid": true }, { "description": "object is valid", "data": {"foo": 123}, "valid": true }, { "description": "number is invalid", "data": 123, "valid": false }, { "description": "string is invalid", "data": "foo", "valid": false }, { "description": "null is invalid", "data": null, "valid": false } ] }, { "description": "type: array, object or null", "schema": { "type": ["array", "object", "null"] }, "tests": [ { "description": "array is valid", "data": [1,2,3], "valid": true }, { "description": "object is valid", "data": {"foo": 123}, "valid": true }, { "description": "null is valid", "data": null, "valid": true }, { "description": "number is invalid", "data": 123, "valid": false }, { "description": "string is invalid", "data": "foo", "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/uniqueItems.json ================================================ [ { "description": "uniqueItems validation", "schema": {"uniqueItems": true}, "tests": [ { "description": "unique array of integers is valid", "data": [1, 2], "valid": true }, { "description": "non-unique array of integers is invalid", "data": [1, 1], "valid": false }, { "description": "numbers are unique if mathematically unequal", "data": [1.0, 1.00, 1], "valid": false }, { "description": "false is not equal to zero", "data": [0, false], "valid": true }, { "description": "true is not equal to one", "data": [1, true], "valid": true }, { "description": "unique array of objects is valid", "data": [{"foo": "bar"}, {"foo": "baz"}], "valid": true }, { "description": "non-unique array of objects is invalid", "data": [{"foo": "bar"}, {"foo": "bar"}], "valid": false }, { "description": "unique array of nested objects is valid", "data": [ {"foo": {"bar" : {"baz" : true}}}, {"foo": {"bar" : {"baz" : false}}} ], "valid": true }, { "description": "non-unique array of nested objects is invalid", "data": [ {"foo": {"bar" : {"baz" : true}}}, {"foo": {"bar" : {"baz" : true}}} ], "valid": false }, { "description": "unique array of arrays is valid", "data": [["foo"], ["bar"]], "valid": true }, { "description": "non-unique array of arrays is invalid", "data": [["foo"], ["foo"]], "valid": false }, { "description": "1 and true are unique", "data": [1, true], "valid": true }, { "description": "0 and false are unique", "data": [0, false], "valid": true }, { "description": "[1] and [true] are unique", "data": [[1], [true]], "valid": true }, { "description": "[0] and [false] are unique", "data": [[0], [false]], "valid": true }, { "description": "nested [1] and [true] are unique", "data": [[[1], "foo"], [[true], "foo"]], "valid": true }, { "description": "nested [0] and [false] are unique", "data": [[[0], "foo"], [[false], "foo"]], "valid": true }, { "description": "unique heterogeneous types are valid", "data": [{}, [1], true, null, 1, "{}"], "valid": true }, { "description": "non-unique heterogeneous types are invalid", "data": [{}, [1], true, null, {}, 1], "valid": false }, { "description": "different objects are unique", "data": [{"a": 1, "b": 2}, {"a": 2, "b": 1}], "valid": true }, { "description": "objects are non-unique despite key order", "data": [{"a": 1, "b": 2}, {"b": 2, "a": 1}], "valid": false }, { "description": "{\"a\": false} and {\"a\": 0} are unique", "data": [{"a": false}, {"a": 0}], "valid": true }, { "description": "{\"a\": true} and {\"a\": 1} are unique", "data": [{"a": true}, {"a": 1}], "valid": true } ] }, { "description": "uniqueItems with an array of items", "schema": { "items": [{"type": "boolean"}, {"type": "boolean"}], "uniqueItems": true }, "tests": [ { "description": "[false, true] from items array is valid", "data": [false, true], "valid": true }, { "description": "[true, false] from items array is valid", "data": [true, false], "valid": true }, { "description": "[false, false] from items array is not valid", "data": [false, false], "valid": false }, { "description": "[true, true] from items array is not valid", "data": [true, true], "valid": false }, { "description": "unique array extended from [false, true] is valid", "data": [false, true, "foo", "bar"], "valid": true }, { "description": "unique array extended from [true, false] is valid", "data": [true, false, "foo", "bar"], "valid": true }, { "description": "non-unique array extended from [false, true] is not valid", "data": [false, true, "foo", "foo"], "valid": false }, { "description": "non-unique array extended from [true, false] is not valid", "data": [true, false, "foo", "foo"], "valid": false } ] }, { "description": "uniqueItems with an array of items and additionalItems=false", "schema": { "items": [{"type": "boolean"}, {"type": "boolean"}], "uniqueItems": true, "additionalItems": false }, "tests": [ { "description": "[false, true] from items array is valid", "data": [false, true], "valid": true }, { "description": "[true, false] from items array is valid", "data": [true, false], "valid": true }, { "description": "[false, false] from items array is not valid", "data": [false, false], "valid": false }, { "description": "[true, true] from items array is not valid", "data": [true, true], "valid": false }, { "description": "extra items are invalid even if unique", "data": [false, true, null], "valid": false } ] }, { "description": "uniqueItems=false validation", "schema": { "uniqueItems": false }, "tests": [ { "description": "unique array of integers is valid", "data": [1, 2], "valid": true }, { "description": "non-unique array of integers is valid", "data": [1, 1], "valid": true }, { "description": "numbers are unique if mathematically unequal", "data": [1.0, 1.00, 1], "valid": true }, { "description": "false is not equal to zero", "data": [0, false], "valid": true }, { "description": "true is not equal to one", "data": [1, true], "valid": true }, { "description": "unique array of objects is valid", "data": [{"foo": "bar"}, {"foo": "baz"}], "valid": true }, { "description": "non-unique array of objects is valid", "data": [{"foo": "bar"}, {"foo": "bar"}], "valid": true }, { "description": "unique array of nested objects is valid", "data": [ {"foo": {"bar" : {"baz" : true}}}, {"foo": {"bar" : {"baz" : false}}} ], "valid": true }, { "description": "non-unique array of nested objects is valid", "data": [ {"foo": {"bar" : {"baz" : true}}}, {"foo": {"bar" : {"baz" : true}}} ], "valid": true }, { "description": "unique array of arrays is valid", "data": [["foo"], ["bar"]], "valid": true }, { "description": "non-unique array of arrays is valid", "data": [["foo"], ["foo"]], "valid": true }, { "description": "1 and true are unique", "data": [1, true], "valid": true }, { "description": "0 and false are unique", "data": [0, false], "valid": true }, { "description": "unique heterogeneous types are valid", "data": [{}, [1], true, null, 1], "valid": true }, { "description": "non-unique heterogeneous types are valid", "data": [{}, [1], true, null, {}, 1], "valid": true } ] }, { "description": "uniqueItems=false with an array of items", "schema": { "items": [{"type": "boolean"}, {"type": "boolean"}], "uniqueItems": false }, "tests": [ { "description": "[false, true] from items array is valid", "data": [false, true], "valid": true }, { "description": "[true, false] from items array is valid", "data": [true, false], "valid": true }, { "description": "[false, false] from items array is valid", "data": [false, false], "valid": true }, { "description": "[true, true] from items array is valid", "data": [true, true], "valid": true }, { "description": "unique array extended from [false, true] is valid", "data": [false, true, "foo", "bar"], "valid": true }, { "description": "unique array extended from [true, false] is valid", "data": [true, false, "foo", "bar"], "valid": true }, { "description": "non-unique array extended from [false, true] is valid", "data": [false, true, "foo", "foo"], "valid": true }, { "description": "non-unique array extended from [true, false] is valid", "data": [true, false, "foo", "foo"], "valid": true } ] }, { "description": "uniqueItems=false with an array of items and additionalItems=false", "schema": { "items": [{"type": "boolean"}, {"type": "boolean"}], "uniqueItems": false, "additionalItems": false }, "tests": [ { "description": "[false, true] from items array is valid", "data": [false, true], "valid": true }, { "description": "[true, false] from items array is valid", "data": [true, false], "valid": true }, { "description": "[false, false] from items array is valid", "data": [false, false], "valid": true }, { "description": "[true, true] from items array is valid", "data": [true, true], "valid": true }, { "description": "extra items are invalid even if unique", "data": [false, true, null], "valid": false } ] } ] ================================================ FILE: test/JSON-Schema-Test-Suite/tests/draft7/unknownKeyword.json ================================================ [ { "description": "$id inside an unknown keyword is not a real identifier", "comment": "the implementation must not be confused by an $id in locations we do not know how to parse", "schema": { "definitions": { "id_in_unknown0": { "not": { "array_of_schemas": [ { "$id": "https://localhost:1234/unknownKeyword/my_identifier.json", "type": "null" } ] } }, "real_id_in_schema": { "$id": "https://localhost:1234/unknownKeyword/my_identifier.json", "type": "string" }, "id_in_unknown1": { "not": { "object_of_schemas": { "foo": { "$id": "https://localhost:1234/unknownKeyword/my_identifier.json", "type": "integer" } } } } }, "anyOf": [ { "$ref": "#/definitions/id_in_unknown0" }, { "$ref": "#/definitions/id_in_unknown1" }, { "$ref": "https://localhost:1234/unknownKeyword/my_identifier.json" } ] }, "tests": [ { "description": "type matches second anyOf, which has a real schema in it", "data": "a string", "valid": true }, { "description": "type matches non-schema in first anyOf", "data": null, "valid": false }, { "description": "type matches non-schema in third anyOf", "data": 1, "valid": false } ] } ] ================================================ FILE: test/binary-validation.cpp ================================================ // bson-validate.cpp #include #include #include static int error_count = 0; #define EXPECT_EQ(a, b) \ do { \ if (a != b) { \ std::cerr << "Failed: '" << a << "' != '" << b << "'\n"; \ error_count++; \ } \ } while (0) #define EXPECT_THROW(foo) \ { \ bool ok = false; \ try { \ foo; \ } catch (std::exception &) { \ ok = true; \ } \ if (ok == false) { \ error_count++; \ } \ } using json = nlohmann::json; using validator = nlohmann::json_schema::json_validator; // check binary data validation const json bson_schema = json::parse(R"( { "type": "object", "properties": { "standard_string": { "type": "string" }, "binary_data": { "type": "string", "contentEncoding": "binary" } }, "additionalProperties": false } )"); const json array_of_types = json::parse(R"( { "type": "object", "properties": { "something": { "type": ["string", "number", "boolean"], "contentEncoding": "binary" } } } )"); const json array_of_types_without_binary = json::parse(R"( { "type": "object", "properties": { "something": { "type": ["string", "number", "boolean"] } } } )"); class store_ptr_err_handler : public nlohmann::json_schema::basic_error_handler { void error(const nlohmann::json::json_pointer &ptr, const json &, const std::string &message) override { nlohmann::json_schema::basic_error_handler::error(ptr, "", message); std::cerr << "ERROR: '" << ptr << "' - '" << "" << "': " << message << "\n"; failed_pointers.push_back(ptr); } public: std::vector failed_pointers; void reset() override { nlohmann::json_schema::basic_error_handler::reset(); failed_pointers.clear(); } }; static void content(const std::string &contentEncoding, const std::string &contentMediaType, const json &instance) { std::cerr << "mediaType: '" << contentMediaType << "', encoding: '" << contentEncoding << "'\n"; if (contentEncoding == "binary") { if (instance.type() != json::value_t::binary) { throw std::invalid_argument{"expected binary data"}; } } else { if (instance.type() == json::value_t::binary) { throw std::invalid_argument{"expected string, but get binary"}; } } } int main() { validator val(nullptr, nullptr, content); // create some bson doc json::binary_t arr; std::string as_binary = "hello world"; std::copy(as_binary.begin(), as_binary.end(), std::back_inserter(arr)); json binary = json::binary(arr); store_ptr_err_handler err; ///////////////////////////////////// val.set_root_schema(bson_schema); // all right val.validate({{"standard_string", "some string"}, {"binary_data", binary}}, err); EXPECT_EQ(err.failed_pointers.size(), 0); err.reset(); // invalid binary data val.validate({{"binary_data", "string, but expect binary data"}}, err); EXPECT_EQ(err.failed_pointers.size(), 1); EXPECT_EQ(err.failed_pointers[0].to_string(), "/binary_data"); err.reset(); // also check that simple string not accept binary data val.validate({{"standard_string", binary}, {"binary_data", binary}}, err); EXPECT_EQ(err.failed_pointers.size(), 1); EXPECT_EQ(err.failed_pointers[0].to_string(), "/standard_string"); err.reset(); ///////////////////////////////////// // check with array of types // check simple types val.set_root_schema(array_of_types); val.validate({{"something", 1}}, err); val.validate({{"something", false}}, err); // TODO when we set `string` in array and set `contentEncoding` = "binary" - what it means? We expected string or binary? // Or we expect only binary? Now if you set `contentEncoding` = "binary", then it means that you expect only binary data, // not string // val.validate({{"something", "string"}}, err); -> produce error about type EXPECT_EQ(err.failed_pointers.size(), 0); err.reset(); // check binary data val.validate({{"something", binary}}, err); EXPECT_EQ(err.failed_pointers.size(), 0); err.reset(); ///////////////////////////////////// // and check that you can't set binary data if contentEncoding don't set val.set_root_schema(array_of_types_without_binary); val.validate({{"something", binary}}, err); EXPECT_EQ(err.failed_pointers.size(), 1); EXPECT_EQ(err.failed_pointers[0].to_string(), "/something"); err.reset(); // check that without content callback you get exception with schema with contentEncoding or contentMeditType validator val_no_content; EXPECT_THROW(val_no_content.set_root_schema(bson_schema)); return error_count; } ================================================ FILE: test/errors.cpp ================================================ #include #include static int error_count; #define EXPECT_EQ(a, b) \ do { \ if (a != b) { \ std::cerr << "Failed: '" << a << "' != '" << b << "'\n"; \ error_count++; \ } \ } while (0) using nlohmann::json; using nlohmann::json_schema::json_validator; namespace { // The schema is defined based upon a string literal static json person_schema = R"( { "$schema": "http://json-schema.org/draft-07/schema#", "title": "A person", "properties": { "name": { "description": "Name", "type": "string" }, "age": { "description": "Age of the person", "type": "number", "minimum": 2, "maximum": 200 }, "phones": { "type": "array", "items": { "type": "number" } } }, "required": [ "name", "age" ], "additionalProperties": false, "type": "object" })"_json; class store_ptr_err_handler : public nlohmann::json_schema::basic_error_handler { void error(const nlohmann::json::json_pointer &ptr, const json &instance, const std::string &message) override { nlohmann::json_schema::basic_error_handler::error(ptr, instance, message); std::cerr << "ERROR: '" << ptr << "' - '" << instance << "': " << message << "\n"; failed_pointers.push_back(ptr); } public: std::vector failed_pointers; void reset() override { nlohmann::json_schema::basic_error_handler::reset(); failed_pointers.clear(); } }; } // namespace int main(void) { json_validator validator; try { validator.set_root_schema(person_schema); // insert root-schema } catch (const std::exception &e) { std::cerr << "Validation of schema failed, here is why: " << e.what() << "\n"; return EXIT_FAILURE; } store_ptr_err_handler err; validator.validate({{"age", 42}, {"name", "John"}}, err); // OK EXPECT_EQ(err.failed_pointers.size(), 0); err.reset(); validator.validate({{"age", 42}}, err); // no name EXPECT_EQ(err.failed_pointers.size(), 1); EXPECT_EQ(err.failed_pointers[0].to_string(), ""); err.reset(); validator.validate({{"street", "Boulevard"}}, err); // no name and no age EXPECT_EQ(err.failed_pointers.size(), 3); EXPECT_EQ(err.failed_pointers[0].to_string(), ""); EXPECT_EQ(err.failed_pointers[1].to_string(), ""); EXPECT_EQ(err.failed_pointers[2].to_string(), ""); err.reset(); validator.validate({{"age", 42}, {"name", 12}}, err); // name must be a string EXPECT_EQ(err.failed_pointers.size(), 1); EXPECT_EQ(err.failed_pointers[0].to_string(), "/name"); err.reset(); validator.validate({ {"age", 42}, {"name", "John"}, {"phones", {1234, "223"}}, }, err); // name must be a string EXPECT_EQ(err.failed_pointers.size(), 1); EXPECT_EQ(err.failed_pointers[0].to_string(), "/phones/1"); err.reset(); validator.validate({ {"age", 42}, {"name", "John"}, {"phones", {0}}, {"post-code", 12345}, }, err); // name must be a string EXPECT_EQ(err.failed_pointers.size(), 1); EXPECT_EQ(err.failed_pointers[0].to_string(), ""); err.reset(); return error_count; } ================================================ FILE: test/id-ref.cpp ================================================ #include #include #include using nlohmann::json; auto schema_draft = R"( { "$id": "http://example.com/root.json", "definitions": { "A": { "$id": "#foo" }, "B": { "$id": "other.json", "definitions": { "X": { "$id": "#bar" }, "Y": { "$id": "t/inner.json" } } }, "C": { "$id": "urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f", "definitions": { "Z": { "$id": "#bar" }, "9": { "$id": "http://example.com/drole.json" } } } } } )"_json; /* # (document root) http://example.com/root.json http://example.com/root.json# #/definitions/A http://example.com/root.json#foo http://example.com/root.json#/definitions/A #/definitions/B http://example.com/other.json http://example.com/other.json# http://example.com/root.json#/definitions/B #/definitions/B/definitions/X http://example.com/other.json#bar http://example.com/other.json#/definitions/X http://example.com/root.json#/definitions/B/definitions/X #/definitions/B/definitions/Y http://example.com/t/inner.json http://example.com/t/inner.json# http://example.com/other.json#/definitions/Y http://example.com/root.json#/definitions/B/definitions/Y #/definitions/C urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f# http://example.com/root.json#/definitions/C */ auto schema = R"( { "id": "http://localhost:1234/scope_change_defs2.json", "type" : "object", "properties": { "list": {"$ref": "#/definitions/baz/definitions/bar"} }, "definitions": { "baz": { "id": "folder/", "definitions": { "bar": { "type": "array", "items": {"$ref": "folderInteger.json"} } } } } })"_json; class json_schema_validator { public: std::vector schemas_; std::map schema_store_; public: void insert_schema(json &s, std::vector base_uris) { auto id = s.find("$id"); if (id != s.end()) base_uris.push_back(base_uris.back().derive(id.value())); for (auto &u : base_uris) schema_store_[u] = &s; for (auto i = s.begin(); i != s.end(); ++i) { switch (i.value().type()) { case json::value_t::object: { // child is object, thus a schema std::vector subschema_uri = base_uris; for (auto &ss : subschema_uri) ss = ss.append(nlohmann::json_uri::escape(i.key())); insert_schema(i.value(), subschema_uri); } break; case json::value_t::string: // this schema is a reference if (i.key() == "$ref") { auto id = base_uris.back().derive(i.value()); i.value() = id.to_string(); } break; default: break; } } } }; int main(void) { json_schema_validator store; store.insert_schema(schema_draft, {{"#"}}); for (auto &i : store.schema_store_) { std::cerr << i.first << " " << *i.second << "\n"; } return 0; } ================================================ FILE: test/issue-100/CMakeLists.txt ================================================ add_test_simple_schema(Issue::100 ${CMAKE_CURRENT_SOURCE_DIR}/schema.json ${CMAKE_CURRENT_SOURCE_DIR}/instance.json) set_tests_properties(Issue::100 PROPERTIES WILL_FAIL 1) ================================================ FILE: test/issue-100/instance.json ================================================ { "Prop1": 1, "Prop2": [] } ================================================ FILE: test/issue-100/schema.json ================================================ { "$id": "http://xxx.local/schemas/mySchema.json", "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "properties": { "Prop1": { "type": "integer", "$comment": "Just a comment" }, "Prop2": { "$ref": "#random_ref" } } } ================================================ FILE: test/issue-101/CMakeLists.txt ================================================ add_test_simple_schema(Issue::101 ${CMAKE_CURRENT_SOURCE_DIR}/schema.json ${CMAKE_CURRENT_SOURCE_DIR}/instance.json) set_tests_properties(Issue::101 PROPERTIES WILL_FAIL 1) ================================================ FILE: test/issue-101/instance.json ================================================ {"top": 1} ================================================ FILE: test/issue-101/schema.json ================================================ { "$id": "http://xxx.local/schemas/mySchema.json", "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "properties": { "top": { "type": "integer" }, "required": ["top"] } } ================================================ FILE: test/issue-105-verbose-combination-errors.cpp ================================================ #include "nlohmann/json-schema.hpp" #include "nlohmann/json.hpp" #include #include #include #include //============================================================================== // Test macros //============================================================================== #define LOG_ERROR(LOG_ERROR__ARGS) \ std::cerr << __FILE__ << ":" << __LINE__ << ": " << LOG_ERROR__ARGS << std::endl #define EXPECT_THROW_WITH_MESSAGE(EXPRESSION, MESSAGE) \ do { \ try { \ EXPRESSION; \ LOG_ERROR("Expected exception not thrown with matching regex: \"" << MESSAGE << "\""); \ ++g_error_count; \ } catch (const std::exception &error) { \ const std::regex error_re{MESSAGE}; \ if (!std::regex_search(error.what(), error_re)) { \ LOG_ERROR("Expected exception with matching regex: \"" << MESSAGE << "\", but got this instead: " << error.what()); \ ++g_error_count; \ } \ } \ } while (false) #define ASSERT_OR_EXPECT_EQ(FIRST_THING, SECOND_THING, RETURN_IN_CASE_OF_ERROR) \ do { \ if ((FIRST_THING) != (SECOND_THING)) { \ LOG_ERROR("The two values of " << (FIRST_THING) << " (" #FIRST_THING << ") and " << (SECOND_THING) << " (" #SECOND_THING << ") should be equal"); \ if (RETURN_IN_CASE_OF_ERROR) { \ return; \ } \ } \ } while (false) #define ASSERT_EQ(FIRST_THING, SECOND_THING) ASSERT_OR_EXPECT_EQ(FIRST_THING, SECOND_THING, true) #define EXPECT_EQ(FIRST_THING, SECOND_THING) ASSERT_OR_EXPECT_EQ(FIRST_THING, SECOND_THING, true) #define EXPECT_MATCH(STRING, REGEX) \ do { \ if (!std::regex_search((STRING), std::regex{(REGEX)})) { \ LOG_ERROR("String \"" << (STRING) << "\" doesn't match with regex: \"" << (REGEX) << "\""); \ ++g_error_count; \ } \ } while (false) namespace { //============================================================================== // Test environment //============================================================================== int g_error_count = 0; //============================================================================== // The schema used for testing //============================================================================== const std::string g_schema_template = R"( { "properties": { "first": { "%COMBINATION_FIRST_LEVEL%": [ { "properties": { "second": { "%COMBINATION_SECOND_LEVEL%": [ { "minimum": 5, "type": "integer" }, { "multipleOf": 2, "type": "integer" } ] } }, "type": "object" }, { "minimum": 20, "type": "integer" }, { "minLength": 10, "type": "string" } ] } }, "type": "object" } )"; auto generateSchema(const std::string &first_combination, const std::string &second_combination) -> nlohmann::json { static const std::regex first_replace_re{"%COMBINATION_FIRST_LEVEL%"}; static const std::regex second_replace_re{"%COMBINATION_SECOND_LEVEL%"}; std::string intermediate = std::regex_replace(g_schema_template, first_replace_re, first_combination); return nlohmann::json::parse(std::regex_replace(intermediate, second_replace_re, second_combination)); } //============================================================================== // Error handler to catch all the errors generated by the validator - also inside the combinations //============================================================================== class MyErrorHandler : public nlohmann::json_schema::error_handler { public: struct ErrorEntry { nlohmann::json::json_pointer ptr; nlohmann::json intance; std::string message; }; using ErrorEntryList = std::vector; auto getErrors() const -> const ErrorEntryList & { return m_error_list; } private: auto error(const nlohmann::json::json_pointer &ptr, const nlohmann::json &instance, const std::string &message) -> void override { m_error_list.push_back(ErrorEntry{ptr, instance, message}); } ErrorEntryList m_error_list; }; //============================================================================== // Error string helpers //============================================================================== auto operator<<(std::string first, const std::string &second) -> std::string { first += ".*"; first += second; return first; } auto rootError(const std::string &combination_type, std::size_t number_of_subschemas) -> std::string { return "no subschema has succeeded, but one of them is required to validate. Type: " + combination_type + ", number of failed subschemas: " + std::to_string(number_of_subschemas); } auto combinationError(const std::string &combination_type, std::size_t test_case_number) -> std::string { return "[combination: " + combination_type + " / case#" + std::to_string(test_case_number) + "]"; } //============================================================================== // Validator function - for simplicity //============================================================================== auto validate(const nlohmann::json &schema, const nlohmann::json &instance, nlohmann::json_schema::error_handler *error_handler = nullptr) -> void { nlohmann::json_schema::json_validator validator; validator.set_root_schema(schema); if (error_handler) { validator.validate(instance, *error_handler); } else { validator.validate(instance); } } //============================================================================== // The test cases //============================================================================== auto simpleTest(const std::string &first_combination, const std::string &second_combination) -> void { const nlohmann::json schema = generateSchema(first_combination, second_combination); EXPECT_THROW_WITH_MESSAGE(validate(schema, nlohmann::json{{"first", {{"second", 1}}}}), rootError(first_combination, 3)); if (second_combination == "oneOf") { EXPECT_THROW_WITH_MESSAGE(validate(schema, nlohmann::json{{"first", {{"second", 8}}}}), rootError(first_combination, 3)); } EXPECT_THROW_WITH_MESSAGE(validate(schema, nlohmann::json{{"first", 10}}), rootError(first_combination, 3)); EXPECT_THROW_WITH_MESSAGE(validate(schema, nlohmann::json{{"first", "short"}}), rootError(first_combination, 3)); } auto verboseTest(const std::string &first_combination, const std::string &second_combination) -> void { const nlohmann::json schema = generateSchema(first_combination, second_combination); { MyErrorHandler error_handler; validate(schema, nlohmann::json{{"first", {{"second", 1}}}}, &error_handler); const MyErrorHandler::ErrorEntryList &error_list = error_handler.getErrors(); EXPECT_EQ(error_list.size(), 6); EXPECT_EQ(error_list[0].ptr, nlohmann::json::json_pointer{"/first"}); EXPECT_MATCH(error_list[0].message, rootError(first_combination, 3)); EXPECT_EQ(error_list[1].ptr, nlohmann::json::json_pointer{"/first/second"}); EXPECT_MATCH(error_list[1].message, combinationError(first_combination, 0) << rootError(second_combination, 2)); EXPECT_EQ(error_list[2].ptr, nlohmann::json::json_pointer{"/first/second"}); EXPECT_MATCH(error_list[2].message, combinationError(first_combination, 0) << combinationError(second_combination, 0) << "instance is below minimum of 5"); EXPECT_EQ(error_list[3].ptr, nlohmann::json::json_pointer{"/first/second"}); EXPECT_MATCH(error_list[3].message, combinationError(first_combination, 0) << combinationError(second_combination, 1) << "instance is not a multiple of 2.0"); EXPECT_EQ(error_list[4].ptr, nlohmann::json::json_pointer{"/first"}); EXPECT_MATCH(error_list[4].message, combinationError(first_combination, 1) << "unexpected instance type"); EXPECT_EQ(error_list[5].ptr, nlohmann::json::json_pointer{"/first"}); EXPECT_MATCH(error_list[5].message, combinationError(first_combination, 2) << "unexpected instance type"); } { MyErrorHandler error_handler; validate(schema, nlohmann::json{{"first", {{"second", "not-an-integer"}}}}, &error_handler); const MyErrorHandler::ErrorEntryList &error_list = error_handler.getErrors(); EXPECT_EQ(error_list.size(), 6); EXPECT_EQ(error_list[0].ptr, nlohmann::json::json_pointer{"/first"}); EXPECT_MATCH(error_list[0].message, rootError(first_combination, 3)); EXPECT_EQ(error_list[1].ptr, nlohmann::json::json_pointer{"/first/second"}); EXPECT_MATCH(error_list[1].message, combinationError(first_combination, 0) << rootError(second_combination, 2)); EXPECT_EQ(error_list[2].ptr, nlohmann::json::json_pointer{"/first/second"}); EXPECT_MATCH(error_list[2].message, combinationError(first_combination, 0) << combinationError(second_combination, 0) << "unexpected instance type"); EXPECT_EQ(error_list[3].ptr, nlohmann::json::json_pointer{"/first/second"}); EXPECT_MATCH(error_list[3].message, combinationError(first_combination, 0) << combinationError(second_combination, 1) << "unexpected instance type"); EXPECT_EQ(error_list[4].ptr, nlohmann::json::json_pointer{"/first"}); EXPECT_MATCH(error_list[4].message, combinationError(first_combination, 1) << "unexpected instance type"); EXPECT_EQ(error_list[5].ptr, nlohmann::json::json_pointer{"/first"}); EXPECT_MATCH(error_list[5].message, combinationError(first_combination, 2) << "unexpected instance type"); } if (second_combination == "oneOf") { MyErrorHandler error_handler; validate(schema, nlohmann::json{{"first", {{"second", 8}}}}, &error_handler); const MyErrorHandler::ErrorEntryList &error_list = error_handler.getErrors(); EXPECT_EQ(error_list.size(), 4); EXPECT_EQ(error_list[0].ptr, nlohmann::json::json_pointer{"/first"}); EXPECT_MATCH(error_list[0].message, rootError(first_combination, 3)); EXPECT_EQ(error_list[1].ptr, nlohmann::json::json_pointer{"/first/second"}); EXPECT_MATCH(error_list[1].message, combinationError(first_combination, 0) << "more than one subschema has succeeded, but exactly one of them is required to validate"); EXPECT_EQ(error_list[2].ptr, nlohmann::json::json_pointer{"/first"}); EXPECT_MATCH(error_list[2].message, combinationError(first_combination, 1) << "unexpected instance type"); EXPECT_EQ(error_list[3].ptr, nlohmann::json::json_pointer{"/first"}); EXPECT_MATCH(error_list[3].message, combinationError(first_combination, 2) << "unexpected instance type"); } { MyErrorHandler error_handler; validate(schema, nlohmann::json{{"first", 10}}, &error_handler); const MyErrorHandler::ErrorEntryList &error_list = error_handler.getErrors(); EXPECT_EQ(error_list.size(), 4); EXPECT_EQ(error_list[0].ptr, nlohmann::json::json_pointer{"/first"}); EXPECT_MATCH(error_list[0].message, rootError(first_combination, 3)); EXPECT_EQ(error_list[1].ptr, nlohmann::json::json_pointer{"/first"}); EXPECT_MATCH(error_list[1].message, combinationError(first_combination, 0) << "unexpected instance type"); EXPECT_EQ(error_list[2].ptr, nlohmann::json::json_pointer{"/first"}); EXPECT_MATCH(error_list[2].message, combinationError(first_combination, 1) << "instance is below minimum of 20"); EXPECT_EQ(error_list[3].ptr, nlohmann::json::json_pointer{"/first"}); EXPECT_MATCH(error_list[3].message, combinationError(first_combination, 2) << "unexpected instance type"); } { MyErrorHandler error_handler; validate(schema, nlohmann::json{{"first", "short"}}, &error_handler); const MyErrorHandler::ErrorEntryList &error_list = error_handler.getErrors(); EXPECT_EQ(error_list.size(), 4); EXPECT_EQ(error_list[0].ptr, nlohmann::json::json_pointer{"/first"}); EXPECT_MATCH(error_list[0].message, rootError(first_combination, 3)); EXPECT_EQ(error_list[1].ptr, nlohmann::json::json_pointer{"/first"}); EXPECT_MATCH(error_list[1].message, combinationError(first_combination, 0) << "unexpected instance type"); EXPECT_EQ(error_list[2].ptr, nlohmann::json::json_pointer{"/first"}); EXPECT_MATCH(error_list[2].message, combinationError(first_combination, 1) << "unexpected instance type"); EXPECT_EQ(error_list[3].ptr, nlohmann::json::json_pointer{"/first"}); EXPECT_MATCH(error_list[3].message, combinationError(first_combination, 2) << "instance is too short as per minLength:10"); } } } // namespace //============================================================================== // MAIN - calling the test cases //============================================================================== auto main() -> int { simpleTest("anyOf", "anyOf"); simpleTest("anyOf", "oneOf"); simpleTest("oneOf", "anyOf"); simpleTest("oneOf", "oneOf"); verboseTest("anyOf", "anyOf"); verboseTest("anyOf", "oneOf"); verboseTest("oneOf", "anyOf"); verboseTest("oneOf", "oneOf"); return g_error_count; } ================================================ FILE: test/issue-117-format-error.cpp ================================================ // issue-00-format-error.cpp #include "nlohmann/json-schema.hpp" #include "nlohmann/json.hpp" #include static int error_count = 0; #define CHECK_THROW(x, msg) \ { \ bool fail = false; \ try { \ x; \ } catch (std::exception &) { \ fail = true; \ } \ if (fail == false) { \ ++error_count; \ std::cout << msg << std::endl; \ } \ } #define CHECK_NO_THROW(x, msg) \ { \ bool fail = false; \ std::string exception_error; \ try { \ x; \ } catch (std::exception & e) { \ fail = true; \ exception_error = e.what(); \ } \ if (fail == true) { \ ++error_count; \ std::cout << msg << ": " << exception_error << std::endl; \ } \ } using json = nlohmann::json; using validator = nlohmann::json_schema::json_validator; json schema_with_format = json::parse(R"( { "type": "object", "properties": { "str": { "type": "string", "format": "placeholder" } } } )"); int main() { // check that if we get validator without format checker we get error at schema loading validator without_format_checker; CHECK_THROW(without_format_checker.set_root_schema(schema_with_format), "validator without format checker must fail at schema loading"); // check that with format checker all works fine validator with_format_checker{nullptr, [](const std::string &, const std::string &) {}}; CHECK_NO_THROW(with_format_checker.set_root_schema(schema_with_format), "schema must be succesed by validator with format checker"); CHECK_NO_THROW(with_format_checker.validate(json{{"str", "placeholder"}}), "validator must not throw while validation schema with format"); return error_count; } ================================================ FILE: test/issue-12/CMakeLists.txt ================================================ add_test_simple_schema(Issue::12 ${CMAKE_CURRENT_SOURCE_DIR}/schema.json ${CMAKE_CURRENT_SOURCE_DIR}/instance.json) ================================================ FILE: test/issue-12/instance.json ================================================ { "x": 1503681668603 } ================================================ FILE: test/issue-12/schema.json ================================================ { "$schema": "http://json-schema.org/draft-04/schema#", "properties": { "x": { "type": "integer", "minimum": 1000000000000, "maximum": 2000000000000 } } } ================================================ FILE: test/issue-143/CMakeLists.txt ================================================ add_test_simple_schema(Issue::143-1 ${CMAKE_CURRENT_SOURCE_DIR}/schema.json ${CMAKE_CURRENT_SOURCE_DIR}/instance-fail-1.json) add_test_simple_schema(Issue::143-a ${CMAKE_CURRENT_SOURCE_DIR}/schema.json ${CMAKE_CURRENT_SOURCE_DIR}/instance-fail-a.json) add_test_simple_schema(Issue::143-ok ${CMAKE_CURRENT_SOURCE_DIR}/schema.json ${CMAKE_CURRENT_SOURCE_DIR}/instance.json) set_tests_properties(Issue::143-1 Issue::143-a PROPERTIES WILL_FAIL 1) ================================================ FILE: test/issue-143/instance-fail-1.json ================================================ { "ref1": "a", "refa": "a" } ================================================ FILE: test/issue-143/instance-fail-a.json ================================================ { "ref1": 12, "refa": 12 } ================================================ FILE: test/issue-143/instance.json ================================================ { "ref1": 12, "refa": "a" } ================================================ FILE: test/issue-143/schema.json ================================================ { "type": "object", "properties": { "unknown_keyword_storage": { "1": { "type": "number" }, "a": { "type": "string" } }, "ref1": { "$ref": "#/properties/unknown_keyword_storage/1" }, "refa": { "$ref": "#/properties/unknown_keyword_storage/a" } }, "additionalProperties": false } ================================================ FILE: test/issue-149-entry-selection.cpp ================================================ #include #include using nlohmann::json; using nlohmann::json_uri; using nlohmann::json_schema::json_validator; namespace { static int error_count; #define EXPECT_EQ(a, b) \ do { \ if (a != b) { \ std::cerr << "Failed: '" << a << "' != '" << b << "'\n"; \ error_count++; \ } \ } while (0) // The schema is defined based upon a string literal static json person_schema = R"( { "$schema": "http://json-schema.org/draft-07/schema#", "type": "integer", "definitions": { "A": { "type": "object", "properties": { "b": { "$ref": "#/definitions/B" } } }, "B": { "type": "integer" } } })"_json; class store_err_handler : public nlohmann::json_schema::basic_error_handler { void error(const nlohmann::json::json_pointer &ptr, const json &instance, const std::string &message) override { nlohmann::json_schema::basic_error_handler::error(ptr, instance, message); std::cerr << "ERROR: '" << ptr << "' - '" << instance << "': " << message << "\n"; failed.push_back(ptr); } public: std::vector failed; void reset() override { nlohmann::json_schema::basic_error_handler::reset(); failed.clear(); } }; } // namespace static json_validator validator(person_schema); int main(void) { store_err_handler err; validator.validate(1, err); // OK EXPECT_EQ(err.failed.size(), 0); err.reset(); validator.validate("1", err); // no name EXPECT_EQ(err.failed.size(), 1); err.reset(); validator.validate(1, err, json_uri("#/definitions/B")); EXPECT_EQ(err.failed.size(), 0); err.reset(); validator.validate("1", err, json_uri("#/definitions/B")); EXPECT_EQ(err.failed.size(), 1); err.reset(); validator.validate({{"b", 1}}, err, json_uri("#/definitions/A")); EXPECT_EQ(err.failed.size(), 0); err.reset(); validator.validate({{"b", "1"}}, err, json_uri("#/definitions/A")); EXPECT_EQ(err.failed.size(), 1); err.reset(); return error_count; } ================================================ FILE: test/issue-189-default-values.cpp ================================================ #include #include using nlohmann::json; using nlohmann::json_uri; using nlohmann::json_schema::json_validator; static const json rectangle_schema = R"( { "$schema": "http://json-schema.org/draft-07/schema#", "properties": { "width": { "$ref": "#/definitions/length", "default": 20 }, "height": { "$ref": "#/definitions/length" } }, "definitions": { "length": { "type": "integer", "default": 10 } } })"_json; static const json quad_schema = R"( { "$schema": "http://json-schema.org/draft-07/schema#", "properties": { "width": { "$ref": "#/properties/height", "default": 20 }, "height": { "$ref": "#/definitions/length" }, "depth": { "$ref": "default_schema#/definitions/defaultLength" }, "time": { "$ref": "#/definitions/time" } }, "definitions": { "length": { "$ref": "default_schema#/definitions/defaultLength", "default": 10 }, "time": { "type": "integer", "default": 15 } } })"_json; static const json default_schema = R"( { "$schema": "http://json-schema.org/draft-07/schema#", "definitions": { "defaultLength": { "default": 5 } } })"_json; static void loader(const json_uri &uri, json &schema) { schema = default_schema; } int main(void) { json_validator validator(loader); validator.set_root_schema(quad_schema); { json empty_quad = R"({})"_json; const auto default_patch = validator.validate(empty_quad); const auto actual = empty_quad.patch(default_patch); const auto expected = R"({"height":10,"width":20,"depth":5,"time":15})"_json; if (actual != expected) { std::cerr << "Patch with defaults contains wrong value: '" << actual << "' instead of expected '" << expected.dump() << "'" << std::endl; return 1; } } validator.set_root_schema(rectangle_schema); { json empty_rectangle = R"({})"_json; const auto default_patch = validator.validate(empty_rectangle); const auto actual = empty_rectangle.patch(default_patch); // height must be 10 according to the default specified in the length definition while width must be 10 overridden by the width element const auto expected = R"({"height":10,"width":20})"_json; if (actual != expected) { std::cerr << "Patch with defaults contains wrong value: '" << actual << "' instead of expected '" << expected.dump() << "'" << std::endl; return 1; } } return 0; } ================================================ FILE: test/issue-209/CMakeLists.txt ================================================ add_test_simple_schema(Issue::209 ${CMAKE_CURRENT_SOURCE_DIR}/entities.schema.json ${CMAKE_CURRENT_SOURCE_DIR}/instance.json) ================================================ FILE: test/issue-209/color.schema.json ================================================ { "$schema": "http://json-schema.org/draft-07/schema#", "$id": "https://example.invalid/color.schema.json", "title": "color", "description": "X11/HTML/CSS color name as a JSON string", "type": "string", "enum": [ "White", "Black", "Red" ] } ================================================ FILE: test/issue-209/entities.schema.json ================================================ { "$schema": "http://json-schema.org/draft-07/schema#", "$id": "https://example.invalid/entities.schema.json", "title": "Entities", "type": "array", "items": { "type": "object", "required": [ "name" ], "properties": { "name": { "type": "string" }, "fg": { "$ref": "color.schema.json", "default": "Black" } } } } ================================================ FILE: test/issue-209/instance.json ================================================ [ { "name": "player", "fg": "White" }, { "name": "enemy", "fg": "Red" } ] ================================================ FILE: test/issue-229-oneof-default-values.cpp ================================================ #include #include using nlohmann::json; using nlohmann::json_uri; using nlohmann::json_schema::json_validator; static const json default_schema = R"( { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "oneOf": [ { "type": "object", "properties": { "name": { "enum": "foo" }, "code": { "const": 1, "default": 1 } } }, { "type": "object", "properties": { "name": { "enum": "bar" }, "code": { "const": 2, "default": 2 } } } ] })"_json; static void loader(const json_uri &uri, json &schema) { schema = default_schema; } int main(void) { json_validator validator(loader); validator.set_root_schema(default_schema); json data = R"({"name": "bar"})"_json; json expected = R"( [ { "op": "add", "path": "/code", "value": 2 } ] )"_json; json patch = validator.validate(data); if (patch != expected) { std::cerr << "Patch contains wrong operation: '" << patch.dump() << "' instead of expected '" << expected.dump() << "'" << std::endl; return 1; } return 0; } ================================================ FILE: test/issue-243-root-default-values.cpp ================================================ #include #include using nlohmann::json; using nlohmann::json_uri; using nlohmann::json_schema::json_validator; static const json root_default = R"( { "$schema": "http://json-schema.org/draft-07/schema#", "properties": { "width": { "type": "integer" } }, "default": { "width": 42 } })"_json; int main(void) { json_validator validator{}; validator.set_root_schema(root_default); { json nul_json; if (!nul_json.is_null()) { return 1; } const auto default_patch = validator.validate(nul_json); if (default_patch.is_null()) { std::cerr << "Patch is null but should contain operation to add defaults to root" << std::endl; return 1; } const auto actual = nul_json.patch(default_patch); const auto expected = R"({"width": 42})"_json; if (actual != expected) { std::cerr << "Patch of defaults is wrong for root schema: '" << actual.dump() << "' instead of expected '" << expected.dump() << "'" << std::endl; } } return 0; } ================================================ FILE: test/issue-25-default-values.cpp ================================================ #include #include using nlohmann::json; using nlohmann::json_schema::json_validator; static const json person_schema = R"( { "$schema": "http://json-schema.org/draft-07/schema#", "title": "A person", "properties": { "name": { "description": "Name", "type": "string" }, "age": { "description": "Age of the person", "type": "number", "minimum": 2, "maximum": 200 }, "address": { "type": "object", "default": {}, "properties": { "street": { "type": "string", "default": "Abbey Road" } } }, "work address": { "type": "object", "default": null, "properties": { "street": { "type": "string", "default": "Abbey Road" } } }, "other address": { "type": "object", "properties": { "street": { "type": "string", "default": "Abbey Road" } } } }, "required": [ "name", "age" ], "additionalProperties": false, "type": "object" })"_json; int main(void) { json_validator validator{}; validator.set_root_schema(person_schema); { // add address which is optional that should generate a diff containing a default street json person_emtpy_address = R"({ "name": "Hans", "age": 69, "address": {} })"_json; const auto default_patch = validator.validate(person_emtpy_address); if (!default_patch.is_array()) { std::cerr << "Patch with defaults is expected to be an array" << std::endl; return 1; } if (default_patch.size() != 1) { std::cerr << "Patch with defaults is expected to contain one opperation" << std::endl; return 1; } const auto &single_op = default_patch[0]; if (!single_op.contains("op")) { std::cerr << "Patch with defaults is expected to contain opperation entry" << std::endl; return 1; } if (single_op["op"].get() != "add") { std::cerr << "Patch with defaults is expected to contain add opperation" << std::endl; return 1; } if (!single_op.contains("path")) { std::cerr << "Patch with defaults is expected to contain a path" << std::endl; return 1; } const auto &readPath = single_op["path"].get(); if (readPath != "/address/street") { std::cerr << "Patch with defaults contains wrong path. It is " << readPath << " and should be " << "/address/street" << std::endl; return 1; } if (!single_op.contains("value")) { std::cerr << "Patch with defaults is expected to contain a value" << std::endl; return 1; } if (single_op["value"].get() != "Abbey Road") { std::cerr << "Patch with defaults contains wrong value" << std::endl; return 1; } } { // add address which is optional that should generate a diff containing a empty object // but not work address which is null or other address which has no default json person_missing_address = R"({ "name": "Hans", "age": 69 })"_json; const auto default_patch = validator.validate(person_missing_address); if (!default_patch.is_array()) { std::cerr << "Patch with defaults is expected to be an array" << std::endl; return 1; } if (default_patch.size() != 1) { std::cerr << "Patch with defaults is expected to contain one opperation" << std::endl; return 1; } const auto &single_op = default_patch[0]; if (!single_op.contains("op")) { std::cerr << "Patch with defaults is expected to contain opperation entry" << std::endl; return 1; } if (single_op["op"].get() != "add") { std::cerr << "Patch with defaults is expected to contain add opperation" << std::endl; return 1; } if (!single_op.contains("path")) { std::cerr << "Patch with defaults is expected to contain a path" << std::endl; return 1; } const auto &readPath = single_op["path"].get(); if (readPath != "/address") { std::cerr << "Patch with defaults contains wrong path. It is " << readPath << " and should be " << "/address" << std::endl; return 1; } if (!single_op.contains("value")) { std::cerr << "Patch with defaults is expected to contain a value" << std::endl; return 1; } if (!single_op["value"].is_object() || !single_op["value"].empty()) { std::cerr << "Patch with defaults contains wrong value" << std::endl; return 1; } } return 0; } ================================================ FILE: test/issue-255-error-message-limit-precision.cpp ================================================ #include #include using nlohmann::json; using nlohmann::json_schema::json_validator; static const json schema = R"( { "$schema": "http://json-schema.org/draft-07/schema#", "$id": "arc.schema.json", "properties": { "angle": { "type": "number", "description": "Radians, from -π to π.", "minimum": -3.14159265358979323846, "maximum": 3.14159265358979323846 } } })"_json; class custom_error_handler : public nlohmann::json_schema::basic_error_handler { void error(const nlohmann::json::json_pointer &ptr, const json &instance, const std::string &message) override { if (message != "instance exceeds maximum of 3.141592653589793") throw std::invalid_argument("Precision print does not work."); } }; int main(void) { json_validator validator; auto instance = R"({ "angle": 3.1415927410125732 })"_json; validator.set_root_schema(schema); custom_error_handler err; validator.validate(instance, err); return 0; } ================================================ FILE: test/issue-27/CMakeLists.txt ================================================ add_test_simple_schema(Issue::27 ${CMAKE_CURRENT_SOURCE_DIR}/schema.json ${CMAKE_CURRENT_SOURCE_DIR}/instance.json) set_tests_properties(Issue::27 PROPERTIES WILL_FAIL 1) ================================================ FILE: test/issue-27/README ================================================ Numbers higher that UINT32_MAX ================================================ FILE: test/issue-27/instance.json ================================================ {"gps_time": 4294967296} ================================================ FILE: test/issue-27/schema.json ================================================ { "properties": { "gps_time": { "type": "number", "minimum": 0, "maximum": 4294967295 } }, "required": [ "gps_time" ], "type": "object" } ================================================ FILE: test/issue-293.cpp ================================================ #include "nlohmann/json-schema.hpp" using nlohmann::json_schema::json_validator; template int should_throw(const nlohmann::json &schema, T value) { try { json_validator(schema).validate(value); } catch (const std::exception &ex) { return 0; } return 1; } int main(void) { json_validator({{"type", "number"}, {"multipleOf", 0.001}}).validate(0.3 - 0.2); json_validator({{"type", "number"}, {"multipleOf", 3.3}}).validate(8.0 - 1.4); json_validator({{"type", "number"}, {"multipleOf", 1000.01}}).validate((1000.03 - 0.02) * 15.0); json_validator({{"type", "number"}, {"multipleOf", 0.001}}).validate(0.030999999999999993); json_validator({{"type", "number"}, {"multipleOf", 0.100000}}).validate(1.9); json_validator({{"type", "number"}, {"multipleOf", 100000.1}}).validate(9000009); int exc_count = 0; exc_count += should_throw({{"type", "number"}, {"multipleOf", 0.001}}, 0.3 - 0.2005); exc_count += should_throw({{"type", "number"}, {"multipleOf", 1000.02}}, (1000.03 - 0.02) * 15.0); exc_count += should_throw({{"type", "number"}, {"multipleOf", 100000.11}}, 9000009); return exc_count; } ================================================ FILE: test/issue-311/CMakeLists.txt ================================================ add_test_simple_schema(Issue::311 ${CMAKE_CURRENT_SOURCE_DIR}/schema.json ${CMAKE_CURRENT_SOURCE_DIR}/instance.json) ================================================ FILE: test/issue-311/instance.json ================================================ { "element": [1], "element2": "test" } ================================================ FILE: test/issue-311/schema.json ================================================ { "type": "object", "properties": { "element": { "$ref": "#/$defs/element" }, "element2": { "$ref": "#/$defs/element/items/0/$defs/element2" } }, "$defs": { "element": { "type": "array", "items": [ { "$defs": { "element2": { "type": "string" } }, "type": "number" } ] } } } ================================================ FILE: test/issue-48/CMakeLists.txt ================================================ add_test_simple_schema(Issue::48 ${CMAKE_CURRENT_SOURCE_DIR}/schema.json ${CMAKE_CURRENT_SOURCE_DIR}/instance.json) ================================================ FILE: test/issue-48/instance.json ================================================ 1.2 ================================================ FILE: test/issue-48/schema.json ================================================ { "multipleOf": 0.1 } ================================================ FILE: test/issue-54/CMakeLists.txt ================================================ add_test_simple_schema(Issue::54 ${CMAKE_CURRENT_SOURCE_DIR}/schema.json ${CMAKE_CURRENT_SOURCE_DIR}/instance.json) ================================================ FILE: test/issue-54/instance.json ================================================ 0 ================================================ FILE: test/issue-54/schema.json ================================================ { "type": "integer", "minimum": -2 } ================================================ FILE: test/issue-70-root-schema-constructor.cpp ================================================ #include #include static int error_count; #define EXPECT_EQ(a, b) \ do { \ if (a != b) { \ std::cerr << "Failed: '" << a << "' != '" << b << "'\n"; \ error_count++; \ } \ } while (0) using nlohmann::json; using nlohmann::json_schema::json_validator; namespace { // The schema is defined based upon a string literal static json person_schema = R"( { "$schema": "http://json-schema.org/draft-07/schema#", "title": "A person", "properties": { "name": { "description": "Name", "type": "string" }, "age": { "description": "Age of the person", "type": "number", "minimum": 2, "maximum": 200 }, "phones": { "type": "array", "items": { "type": "number" } } }, "required": [ "name", "age" ], "additionalProperties": false, "type": "object" })"_json; class store_ptr_err_handler : public nlohmann::json_schema::basic_error_handler { void error(const nlohmann::json::json_pointer &ptr, const json &instance, const std::string &message) override { nlohmann::json_schema::basic_error_handler::error(ptr, instance, message); std::cerr << "ERROR: '" << ptr << "' - '" << instance << "': " << message << "\n"; failed_pointers.push_back(ptr); } public: std::vector failed_pointers; void reset() override { nlohmann::json_schema::basic_error_handler::reset(); failed_pointers.clear(); } }; } // namespace static json_validator validator(person_schema); int main(void) { store_ptr_err_handler err; validator.validate({{"age", 42}, {"name", "John"}}, err); // OK EXPECT_EQ(err.failed_pointers.size(), 0); err.reset(); validator.validate({{"age", 42}}, err); // no name EXPECT_EQ(err.failed_pointers.size(), 1); EXPECT_EQ(err.failed_pointers[0].to_string(), ""); err.reset(); validator.validate({{"street", "Boulevard"}}, err); // no name and no age EXPECT_EQ(err.failed_pointers.size(), 3); EXPECT_EQ(err.failed_pointers[0].to_string(), ""); EXPECT_EQ(err.failed_pointers[1].to_string(), ""); EXPECT_EQ(err.failed_pointers[2].to_string(), ""); err.reset(); validator.validate({{"age", 42}, {"name", 12}}, err); // name must be a string EXPECT_EQ(err.failed_pointers.size(), 1); EXPECT_EQ(err.failed_pointers[0].to_string(), "/name"); err.reset(); validator.validate({ {"age", 42}, {"name", "John"}, {"phones", {1234, "223"}}, }, err); // name must be a string EXPECT_EQ(err.failed_pointers.size(), 1); EXPECT_EQ(err.failed_pointers[0].to_string(), "/phones/1"); err.reset(); validator.validate({ {"age", 42}, {"name", "John"}, {"phones", {0}}, {"post-code", 12345}, }, err); // name must be a string EXPECT_EQ(err.failed_pointers.size(), 1); EXPECT_EQ(err.failed_pointers[0].to_string(), ""); err.reset(); return error_count; } ================================================ FILE: test/issue-70.cpp ================================================ #include using nlohmann::json; using nlohmann::json_schema::json_validator; static const json person_schema = R"( { "$schema": "http://json-schema.org/draft-07/schema#", "title": "A person", "properties": { "name": { "description": "Name", "type": "string" }, "age": { "description": "Age of the person", "type": "number", "minimum": 2, "maximum": 200 }, "phones": { "type": "array", "items": { "type": "number" } } }, "required": [ "name", "age" ], "additionalProperties": false, "type": "object" })"_json; int main(void) { json_validator validator; validator.set_root_schema(person_schema); validator.set_root_schema(person_schema); return 0; } ================================================ FILE: test/issue-75/CMakeLists.txt ================================================ add_test_simple_schema(Issue::75 ${CMAKE_CURRENT_SOURCE_DIR}/schema.json ${CMAKE_CURRENT_SOURCE_DIR}/instance.json) ================================================ FILE: test/issue-75/TypeId.json ================================================ { "data" : { "TypeId" : { "type" : "string", "description" : "POD type of data matching bmf::data::TypeId enum", "enum" : [ "CHAR", "UCHAR", "SHORT", "USHORT", "INT", "UINT", "LONG", "ULONG", "FLOAT", "DOUBLE" ] } } } ================================================ FILE: test/issue-75/instance.json ================================================ ["INT", "LONG"] ================================================ FILE: test/issue-75/schema.json ================================================ { "type" : "array", "items": { "$ref": "TypeId.json#/data/TypeId" } } ================================================ FILE: test/issue-9/CMakeLists.txt ================================================ add_test_simple_schema(Issue::9 ${CMAKE_CURRENT_SOURCE_DIR}/base.json ${CMAKE_CURRENT_SOURCE_DIR}/instance.json) ================================================ FILE: test/issue-9/bar.json ================================================ { "$schema": "http://json-schema.org/draft-04/schema#", "description": "Describes bar", "type": "object", "required": [ "name" ], "properties": { "name": { "type": "string" } } } ================================================ FILE: test/issue-9/base.json ================================================ { "$schema": "http://json-schema.org/draft-04/schema#", "description": "Describes foo", "type": "object", "allOf": [ { "$ref": "bar.json" }, { "$ref": "foo/foo.json" } ] } ================================================ FILE: test/issue-9/foo/baz/baz.json ================================================ { "$schema": "http://json-schema.org/draft-04/schema#", "description": "Describes baz", "$ref": "qux/qux.json" } ================================================ FILE: test/issue-9/foo/baz/qux/qux.json ================================================ { "$schema": "http://json-schema.org/draft-04/schema#", "description": "Describes qux", "type": "object", "required": [ "name" ], "properties": { "name": { "type": "string" } } } ================================================ FILE: test/issue-9/foo/foo.json ================================================ { "$schema": "http://json-schema.org/draft-04/schema#", "description": "Describes foo", "$ref": "baz/baz.json" } ================================================ FILE: test/issue-9/instance.json ================================================ { "name": "name" } ================================================ FILE: test/issue-93/CMakeLists.txt ================================================ add_executable(issue-93 issue-93.cpp) target_link_libraries(issue-93 nlohmann_json_schema_validator) add_test(NAME issue-93 COMMAND issue-93 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) ================================================ FILE: test/issue-93/blueprints.schema.json ================================================ { "type":"array", "items": { "type":"object", "properties": { "renderable": { "$ref":"/components.schema.json#/Renderable" } } } } ================================================ FILE: test/issue-93/components.schema.json ================================================ { "Renderable": { "type":"object", "properties": { "fg":{ "$ref":"/types/color.schema.json" }, "bg":{ "$ref":"/types/color.schema.json" } } } } ================================================ FILE: test/issue-93/issue-93.cpp ================================================ #include #include #include using nlohmann::json; using nlohmann::json_uri; using nlohmann::json_schema::json_validator; static const auto expected_patch = R"( [{"op":"add","path":"/0/renderable/bg","value":"Black"}] )"_json; static const auto instance = R"( [ { "name":"player", "renderable": { "fg":"White" } } ] )"_json; static void loader(const json_uri &uri, json &schema) { std::string filename = "./" + uri.path(); std::ifstream lf(filename); if (!lf.good()) throw std::invalid_argument("could not open " + uri.url() + " tried with " + filename); try { lf >> schema; } catch (const std::exception &e) { throw e; } } int main(void) { json_validator validator(loader); std::fstream f("blueprints.schema.json"); json schema; f >> schema; validator.set_root_schema(schema); auto missing_default_patch = validator.validate(instance); std::cerr << missing_default_patch << "\n"; std::cerr << expected_patch << "\n"; return missing_default_patch != expected_patch; } ================================================ FILE: test/issue-93/types/color.schema.json ================================================ { "type":"string", "default":"Black" } ================================================ FILE: test/issue-96/CMakeLists.txt ================================================ add_test_simple_schema(Issue::96 ${CMAKE_CURRENT_SOURCE_DIR}/schema.json ${CMAKE_CURRENT_SOURCE_DIR}/instance.json) set_tests_properties(Issue::96 PROPERTIES WILL_FAIL 1) ================================================ FILE: test/issue-96/instance.json ================================================ {"top": {"value": 101}} ================================================ FILE: test/issue-96/schema.json ================================================ { "$id": "http://xxx.local/schemas/mySchema.json", "$schema": "http://json-schema.org/draft-07/schema#", "definitions": { "topDef": { "$id": "#topDef_ref", "type": "object", "properties": { "value": { "type": "integer", "maximum": 100 } } } }, "type": "object", "properties": { "top": { "$ref": "#/definitions/topDef" } } } ================================================ FILE: test/issue-98.cpp ================================================ #include int main(void) { nlohmann::json nlBase{{"$ref", "#/unknown/keywords"}}; nlohmann::json_schema::json_validator validator; try { validator.set_root_schema(nlBase); // this line will log the caught exception } catch (const std::exception &e) { if (std::string("after all files have been parsed, '' has still the following undefined references: [/unknown/keywords]") == e.what()) return EXIT_SUCCESS; } return EXIT_FAILURE; } ================================================ FILE: test/json-patch.cpp ================================================ #include "../src/json-patch.hpp" #include using nlohmann::json_patch; #define OK(code) \ do { \ try { \ code; \ } catch (const std::exception &e) { \ std::cerr << "UNEXPECTED FAILED: " << e.what() << "\n"; \ return 1; \ } \ } while (0) #define KO(code) \ do { \ try { \ code; \ std::cerr << "UNEXPECTED SUCCESS.\n"; \ return 1; \ } catch (const std::exception &e) { \ std::cerr << "EXPECTED FAIL: " << e.what() << "\n"; \ } \ } while (0) int main(void) { OK(json_patch p1(R"([{"op":"add","path":"/0/renderable/bg","value":"Black"}])"_json)); OK(json_patch p1(R"([{"op":"replace","path":"/0/renderable/bg","value":"Black"}])"_json)); OK(json_patch p1(R"([{"op":"remove","path":"/0/renderable/bg"}])"_json)); // value not needed KO(json_patch p1(R"([{"op":"remove","path":"/0/renderable/bg", "value":"Black"}])"_json)); // value missing KO(json_patch p1(R"([{"op":"add","path":"/0/renderable/bg"}])"_json)); // value missing KO(json_patch p1(R"([{"op":"replace","path":"/0/renderable/bg"}])"_json)); // wrong op KO(json_patch p1(R"([{"op":"ad","path":"/0/renderable/bg","value":"Black"}])"_json)); // invalid json-pointer KO(json_patch p1(R"([{"op":"add","path":"0/renderable/bg","value":"Black"}])"_json)); return 0; } ================================================ FILE: test/json-schema-validate.cpp ================================================ /* * JSON schema validator for JSON for modern C++ * * Copyright (c) 2016-2019 Patrick Boettcher . * * SPDX-License-Identifier: MIT * */ #include #include #include using nlohmann::json; using nlohmann::json_uri; using nlohmann::json_schema::json_validator; static void usage(const char *name) { std::cerr << "Usage: " << name << " < \n"; exit(EXIT_FAILURE); } static void loader(const json_uri &uri, json &schema) { std::string filename = "./" + uri.path(); std::ifstream lf(filename); if (!lf.good()) throw std::invalid_argument("could not open " + uri.url() + " tried with " + filename); try { lf >> schema; } catch (const std::exception &e) { throw e; } } class custom_error_handler : public nlohmann::json_schema::basic_error_handler { void error(const nlohmann::json::json_pointer &ptr, const json &instance, const std::string &message) override { nlohmann::json_schema::basic_error_handler::error(ptr, instance, message); std::cerr << "ERROR: '" << ptr << "' - '" << instance << "': " << message << "\n"; } }; int main(int argc, char *argv[]) { if (argc != 2) usage(argv[0]); std::ifstream f(argv[1]); if (!f.good()) { std::cerr << "could not open " << argv[1] << " for reading\n"; usage(argv[0]); } // 1) Read the schema for the document you want to validate json schema; try { f >> schema; } catch (const std::exception &e) { std::cerr << e.what() << " at " << f.tellg() << " - while parsing the schema\n"; return EXIT_FAILURE; } // 2) create the validator and json_validator validator(loader, nlohmann::json_schema::default_string_format_check); try { // insert this schema as the root to the validator // this resolves remote-schemas, sub-schemas and references via the given loader-function validator.set_root_schema(schema); } catch (const std::exception &e) { std::cerr << "setting root schema failed\n"; std::cerr << e.what() << "\n"; } // 3) do the actual validation of the document json document; try { std::cin >> document; } catch (const std::exception &e) { std::cerr << "json parsing failed: " << e.what() << " at offset: " << std::cin.tellg() << "\n"; return EXIT_FAILURE; } custom_error_handler err; validator.validate(document, err); if (err) { std::cerr << "schema validation failed\n"; return EXIT_FAILURE; } std::cerr << "document is valid\n"; return EXIT_SUCCESS; } ================================================ FILE: test/string-format-check-test.cpp ================================================ #include #include /** @return number of failed tests */ size_t testStringFormat(const std::string &format, const std::vector> &stringValidTests) { size_t numberOfErrors = 0; for (auto stringValid = stringValidTests.begin(); stringValid != stringValidTests.end(); ++stringValid) { std::cout << "[INFO] Testing " << format << ": " << stringValid->first << "\n"; try { nlohmann::json_schema::default_string_format_check(format, stringValid->first); if (!stringValid->second) { ++numberOfErrors; std::cerr << "[ERROR] String with " << format << " format '" << stringValid->first << "' validated even though it should NOT!\n"; } } catch (std::exception &exception) { std::cout << "[INFO] Validation failed with: " << exception.what() << "\n"; if (stringValid->second) { ++numberOfErrors; std::cerr << "[ERROR] String with " << format << " format '" << stringValid->first << "' did NOT validate even though it should!\n"; } } } return numberOfErrors; } int main() { size_t numberOfErrors = 0; const std::vector> dateTimeChecks{ {"1985-04-12T23:20:50.52Z", true}, {"1996-12-19T16:39:57-08:00", true}, {"1990-12-31T23:59:60Z", true}, {"1990-12-31T15:59:60-08:00", true}, {"1937-01-01T12:00:27.87+00:20", true}, {"1985-4-12T23:20:50.52Z", false}, {"1985-04-12T23:20:50.52", false}, {"1985-04-12T24:00:00", false}, {"", false}, {"2019-04-30T11:11:11+01:00", true}, {"2019-04-31T11:11:11+01:00", false}, {"2019-02-28T11:11:11+01:00", true}, {"2019-02-29T11:11:11+01:00", false}, {"2020-02-29T11:11:11+01:00", true}, {"2020-02-30T11:11:11+01:00", false}, {"2020-02-29T23:59:59+01:00", true}, {"2020-02-29T23:59:60+01:00", false}, {"2020-02-29T23:59:60+00:00", true}, {"2020-02-29T23:60:59+01:00", false}, {"2019-09-30T11:11:11+01:00", true}, {"2019-09-31T11:11:11+01:00", false}, {"2019-09-30T11:11:11+23:59", true}, {"2019-09-30T11:11:11+24:00", false}}; numberOfErrors += testStringFormat("date-time", dateTimeChecks); const std::vector> ipv4Checks{ {"", false}, {"x99.99.99.99", false}, {"99.99.99.99x", false}, {"192.168.0.1", true}, {"127.0.0", false}, {"127.0.0.1", true}, {"127.0.0.0.1", false}, {"255.255.255.255", true}, {"255.255.255.256", false}, {"255.255.256.255", false}, {"255.256.255.255", false}, {"256.255.255.255", false}, {"256.256.256.256", false}, {"0x7f000001", false}}; numberOfErrors += testStringFormat("ipv4", ipv4Checks); const std::vector> uriChecks{ {"http://www.google.com/search?q=regular%20expression", true}, {"http://www.google.com/", true}, {"http://www.google.com/search?q=regular%20expression", true}, {"www.google.com", false}, {"http://www.google.comj", true}, {"ldap://[2001:db8::7]/c=GB?objectClass?one", true}, {"mailto:John.Doe@example.com", true}, {"news:comp.infosystems.www.servers.unix", true}, {"https://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top", true}, {"tel:+1-816-555-1212", true}, {"telnet://192.0.2.16:80/", true}, {"urn:oasis:names:specification:docbook:dtd:xml:4.1.2", true}}; numberOfErrors += testStringFormat("uri", uriChecks); return numberOfErrors; } ================================================ FILE: test/test-pipe-in.sh ================================================ #!/bin/bash # all argument are considered as a program to call (with its arguments), # the last argument is read from stdin via '<' set -e arr=( "$@" ) input=${arr[${#arr[@]}-1]} unset 'arr[${#arr[@]}-1]' ${arr[@]} < $input ================================================ FILE: test/uri.cpp ================================================ /* * JSON schema validator for JSON for modern C++ * * Copyright (c) 2016-2019 Patrick Boettcher . * * SPDX-License-Identifier: MIT * */ #include #include #include using nlohmann::json; using nlohmann::json_uri; static int errors; static void EXPECT_EQ(const std::string &a, const std::string &b) { if (a != b) { std::cerr << "Failed: '" << a << "' != '" << b << "'\n"; errors++; } } static void EXPECT_EQ(const nlohmann::json_uri &a, const std::string &b) { EXPECT_EQ(a.to_string(), b); } static void paths(json_uri start, const std::string &full, const std::string &full_path, const std::string &no_path) { EXPECT_EQ(start, full + " # "); auto a = start.derive("other.json"); EXPECT_EQ(a, full_path + "/other.json # "); auto b = a.derive("base.json"); EXPECT_EQ(b, full_path + "/base.json # "); auto c = b.derive("subdir/base.json"); EXPECT_EQ(c, full_path + "/subdir/base.json # "); auto d = c.derive("subdir2/base.json"); EXPECT_EQ(d, full_path + "/subdir/subdir2/base.json # "); auto e = c.derive("/subdir2/base.json"); EXPECT_EQ(e, no_path + "/subdir2/base.json # "); auto f = c.derive("new.json"); EXPECT_EQ(f, full_path + "/subdir/new.json # "); auto g = c.derive("/new.json"); EXPECT_EQ(g, no_path + "/new.json # "); } static void pointer_plain_name(json_uri start, const std::string &full, const std::string &full_path, const std::string &no_path) { auto a = start.derive("#/json/path"); EXPECT_EQ(a, full + " # /json/path"); a = start.derive("#/json/special_%22"); EXPECT_EQ(a, full + " # /json/special_\""); a = a.derive("#foo"); EXPECT_EQ(a, full + " # foo"); a = a.derive("#foo/looks_like_json/poiner/but/isnt"); EXPECT_EQ(a, full + " # foo/looks_like_json/poiner/but/isnt"); EXPECT_EQ(a.identifier(), "foo/looks_like_json/poiner/but/isnt"); EXPECT_EQ(a.pointer().to_string(), ""); a = a.derive("#/looks_like_json/poiner/and/it/is"); EXPECT_EQ(a, full + " # /looks_like_json/poiner/and/it/is"); EXPECT_EQ(a.pointer().to_string(), "/looks_like_json/poiner/and/it/is"); EXPECT_EQ(a.identifier(), ""); } int main(void) { json_uri empty(""); paths(empty, "", "", ""); json_uri http("http://json-schema.org/draft-07/schema#"); paths(http, "http://json-schema.org/draft-07/schema", "http://json-schema.org/draft-07", "http://json-schema.org"); pointer_plain_name(http, "http://json-schema.org/draft-07/schema", "http://json-schema.org/draft-07", "http://json-schema.org"); return errors; }