LCOV - code coverage report
Current view: top level - jsonSchema - JsonSchema.hpp (source / functions) Coverage Total Hit
Test: final-coverage.info Lines: 100.0 % 6 6
Test Date: 2025-02-14 17:40:40 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /*
       2              :  ___________________________________________
       3              : |    _     ___                        _     |
       4              : |   | |   |__ \                      | |    |
       5              : |   | |__    ) |__ _  __ _  ___ _ __ | |_   |
       6              : |   | '_ \  / // _` |/ _` |/ _ \ '_ \| __|  |  HTTP/2 AGENT FOR MOCK TESTING
       7              : |   | | | |/ /| (_| | (_| |  __/ | | | |_   |  Version 0.0.z
       8              : |   |_| |_|____\__,_|\__, |\___|_| |_|\__|  |  https://github.com/testillano/h2agent
       9              : |                     __/ |                 |
      10              : |                    |___/                  |
      11              : |___________________________________________|
      12              : 
      13              : Licensed under the MIT License <http://opensource.org/licenses/MIT>.
      14              : SPDX-License-Identifier: MIT
      15              : Copyright (c) 2021 Eduardo Ramos
      16              : 
      17              : Permission is hereby  granted, free of charge, to any  person obtaining a copy
      18              : of this software and associated  documentation files (the "Software"), to deal
      19              : in the Software  without restriction, including without  limitation the rights
      20              : to  use, copy,  modify, merge,  publish, distribute,  sublicense, and/or  sell
      21              : copies  of  the Software,  and  to  permit persons  to  whom  the Software  is
      22              : furnished to do so, subject to the following conditions:
      23              : 
      24              : The above copyright notice and this permission notice shall be included in all
      25              : copies or substantial portions of the Software.
      26              : 
      27              : THE SOFTWARE  IS PROVIDED "AS  IS", WITHOUT WARRANTY  OF ANY KIND,  EXPRESS OR
      28              : IMPLIED,  INCLUDING BUT  NOT  LIMITED TO  THE  WARRANTIES OF  MERCHANTABILITY,
      29              : FITNESS FOR  A PARTICULAR PURPOSE AND  NONINFRINGEMENT. IN NO EVENT  SHALL THE
      30              : AUTHORS  OR COPYRIGHT  HOLDERS  BE  LIABLE FOR  ANY  CLAIM,  DAMAGES OR  OTHER
      31              : LIABILITY, WHETHER IN AN ACTION OF  CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      32              : OUT OF OR IN CONNECTION WITH THE SOFTWARE  OR THE USE OR OTHER DEALINGS IN THE
      33              : SOFTWARE.
      34              : */
      35              : 
      36              : #pragma once
      37              : 
      38              : // Standard
      39              : #include <string>
      40              : 
      41              : // Project
      42              : //#include <nlohmann/json.hpp>
      43              : #include <nlohmann/json-schema.hpp>
      44              : 
      45              : 
      46              : namespace h2agent
      47              : {
      48              : namespace jsonschema
      49              : {
      50              : 
      51              : class JsonSchema
      52              : {
      53              :     bool available_{};
      54              : 
      55              :     nlohmann::json json_{};
      56              :     nlohmann::json_schema::json_validator validator_{};
      57              : 
      58              : public:
      59              :     /**
      60              :     * Default constructor
      61              :     */
      62         1383 :     JsonSchema() : available_(false) {;}
      63         1286 :     ~JsonSchema() {;}
      64              : 
      65              :     // setters
      66              : 
      67              :     /**
      68              :     * Set json document schema
      69              :     *
      70              :     * @param j Json document schema
      71              :     *
      72              :     * @return Successful if a valid schema was configured
      73              :     */
      74              :     bool setJson(const nlohmann::json& j);
      75              : 
      76              :     // getters
      77              : 
      78              :     /**
      79              :     * Returns successful if a valid schema was configured
      80              :     *
      81              :     * @return Boolean about successful schema load
      82              :     */
      83            6 :     bool isAvailable() const {
      84            6 :         return available_;
      85              :     }
      86              : 
      87              :     /**
      88              :     * Get json document schema
      89              :     *
      90              :     * @return Json document schema
      91              :     */
      92           10 :     const nlohmann::json& getJson() const
      93              :     {
      94           10 :         return json_;
      95              :     }
      96              : 
      97              :     /**
      98              :     * Validates json document against schema.
      99              :     *
     100              :     * @param j Json document to validate
     101              :     * @param error Error passed by reference
     102              :     *
     103              :     * @return boolean about if json document is valid against json schema
     104              :     */
     105              :     bool validate(const nlohmann::json& j, std::string &error) const;
     106              : };
     107              : 
     108              : }
     109              : }
     110              : 
        

Generated by: LCOV version 2.0-1