Added schema validation command line flags
This commit is contained in:
@@ -200,6 +200,13 @@ the configuration file to `clang-uml` using `stdin`, e.g.:
|
|||||||
yq 'explode(.)' .clang-uml | clang-uml --config -
|
yq 'explode(.)' .clang-uml | clang-uml --config -
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Schema validation error is thrown, but the configuration file is correct
|
||||||
|
Current version of `clang-uml` performs automatic configuration file
|
||||||
|
schema validation, and exits if the configuration file is invalid.
|
||||||
|
|
||||||
|
In case there is a bug in the schema validation, the schema validation
|
||||||
|
step can be skipped by providing `--no-validate` command line option.
|
||||||
|
|
||||||
## Class diagrams
|
## Class diagrams
|
||||||
|
|
||||||
### "fatal error: 'stddef.h' file not found"
|
### "fatal error: 'stddef.h' file not found"
|
||||||
|
|||||||
@@ -131,6 +131,10 @@ cli_flow_t cli_handler::parse(int argc, const char **argv)
|
|||||||
"Skip metadata (e.g. clang-uml version) from diagrams");
|
"Skip metadata (e.g. clang-uml version) from diagrams");
|
||||||
app.add_flag("--print-start-from", print_start_from,
|
app.add_flag("--print-start-from", print_start_from,
|
||||||
"Print all possible 'start_from' values for a given diagram");
|
"Print all possible 'start_from' values for a given diagram");
|
||||||
|
app.add_flag("--no-validate", no_validate,
|
||||||
|
"Do not perform configuration file schema validation");
|
||||||
|
app.add_flag("--validate-only", validate_only,
|
||||||
|
"Perform configuration file schema validation and exit");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
app.parse(argc, argv);
|
app.parse(argc, argv);
|
||||||
@@ -245,7 +249,13 @@ cli_flow_t cli_handler::load_config()
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
config = clanguml::config::load(
|
config = clanguml::config::load(
|
||||||
config_path, paths_relative_to_pwd, no_metadata);
|
config_path, paths_relative_to_pwd, no_metadata, !no_validate);
|
||||||
|
if (validate_only) {
|
||||||
|
LOG_INFO("Configuration file {} is valid.", config_path);
|
||||||
|
|
||||||
|
return cli_flow_t::kExit;
|
||||||
|
}
|
||||||
|
|
||||||
return cli_flow_t::kContinue;
|
return cli_flow_t::kContinue;
|
||||||
}
|
}
|
||||||
catch (std::runtime_error &e) {
|
catch (std::runtime_error &e) {
|
||||||
|
|||||||
@@ -183,6 +183,8 @@ public:
|
|||||||
std::optional<std::string> show_template;
|
std::optional<std::string> show_template;
|
||||||
std::vector<clanguml::common::generator_type_t> generators{
|
std::vector<clanguml::common::generator_type_t> generators{
|
||||||
clanguml::common::generator_type_t::plantuml};
|
clanguml::common::generator_type_t::plantuml};
|
||||||
|
bool no_validate{false};
|
||||||
|
bool validate_only{false};
|
||||||
|
|
||||||
clanguml::config::config config;
|
clanguml::config::config config;
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,10 @@
|
|||||||
|
|
||||||
namespace clanguml {
|
namespace clanguml {
|
||||||
|
|
||||||
|
namespace cli {
|
||||||
|
struct runtime_config;
|
||||||
|
} // namespace cli
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Configuration file related classes
|
* @brief Configuration file related classes
|
||||||
*
|
*
|
||||||
@@ -472,7 +476,7 @@ struct inheritable_diagram_options {
|
|||||||
* @embed{diagram_config_hierarchy_class.svg}
|
* @embed{diagram_config_hierarchy_class.svg}
|
||||||
*/
|
*/
|
||||||
struct diagram : public inheritable_diagram_options {
|
struct diagram : public inheritable_diagram_options {
|
||||||
virtual ~diagram() = default;
|
~diagram() override = default;
|
||||||
|
|
||||||
virtual common::model::diagram_t type() const = 0;
|
virtual common::model::diagram_t type() const = 0;
|
||||||
|
|
||||||
@@ -622,11 +626,12 @@ struct config : public inheritable_diagram_options {
|
|||||||
* the configuration file or to the current
|
* the configuration file or to the current
|
||||||
* directory (`$PWD`)
|
* directory (`$PWD`)
|
||||||
* @param no_metadata Whether the diagram should skip metadata at the end
|
* @param no_metadata Whether the diagram should skip metadata at the end
|
||||||
|
* @param validate If true, perform schema validation
|
||||||
* @return Configuration instance
|
* @return Configuration instance
|
||||||
*/
|
*/
|
||||||
config load(const std::string &config_file,
|
config load(const std::string &config_file,
|
||||||
std::optional<bool> paths_relative_to_pwd = {},
|
std::optional<bool> paths_relative_to_pwd = {},
|
||||||
std::optional<bool> no_metadata = {});
|
std::optional<bool> no_metadata = {}, bool validate = true);
|
||||||
|
|
||||||
} // namespace config
|
} // namespace config
|
||||||
|
|
||||||
|
|||||||
@@ -64,6 +64,10 @@ types:
|
|||||||
- class
|
- class
|
||||||
- enum
|
- enum
|
||||||
- concept
|
- concept
|
||||||
|
- method
|
||||||
|
- function
|
||||||
|
- function_template
|
||||||
|
- lambda
|
||||||
relationship_filter_t: !variant
|
relationship_filter_t: !variant
|
||||||
- extension
|
- extension
|
||||||
- inheritance
|
- inheritance
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "cli/cli_handler.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "diagram_templates.h"
|
#include "diagram_templates.h"
|
||||||
#include "schema.h"
|
#include "schema.h"
|
||||||
@@ -831,7 +832,8 @@ void resolve_option_path(YAML::Node &doc, const std::string &option)
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
config load(const std::string &config_file,
|
config load(const std::string &config_file,
|
||||||
std::optional<bool> paths_relative_to_pwd, std::optional<bool> no_metadata)
|
std::optional<bool> paths_relative_to_pwd, std::optional<bool> no_metadata,
|
||||||
|
bool validate)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
auto schema = YAML::Load(clanguml::config::schema_str);
|
auto schema = YAML::Load(clanguml::config::schema_str);
|
||||||
@@ -930,15 +932,17 @@ config load(const std::string &config_file,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto schema_errors = schema_validator.validate(doc);
|
if (validate) {
|
||||||
|
auto schema_errors = schema_validator.validate(doc);
|
||||||
|
|
||||||
if (schema_errors.size() > 0) {
|
if (!schema_errors.empty()) {
|
||||||
// print validation errors
|
// print validation errors
|
||||||
for (const auto &err : schema_errors) {
|
for (const auto &err : schema_errors) {
|
||||||
LOG_ERROR("Schema error: {}", err.description());
|
LOG_ERROR("Schema error: {}", err.description());
|
||||||
|
}
|
||||||
|
|
||||||
|
throw YAML::Exception({}, "Invalid configuration schema");
|
||||||
}
|
}
|
||||||
|
|
||||||
throw YAML::Exception({}, "Invalid configuration schema");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto d = doc.as<config>();
|
auto d = doc.as<config>();
|
||||||
|
|||||||
@@ -12,9 +12,8 @@ include:
|
|||||||
subclasses:
|
subclasses:
|
||||||
- clanguml::common::model::decorated_element
|
- clanguml::common::model::decorated_element
|
||||||
- clanguml::common::model::source_location
|
- clanguml::common::model::source_location
|
||||||
include:
|
relationships:
|
||||||
relationships:
|
- inheritance
|
||||||
- inheritance
|
|
||||||
exclude:
|
exclude:
|
||||||
relationships:
|
relationships:
|
||||||
- dependency
|
- dependency
|
||||||
|
|||||||
Reference in New Issue
Block a user