Skip to content

Conversation

@tinygiant98
Copy link

@tinygiant98 tinygiant98 commented Jan 23, 2026

This plugin candidate implements a javascript-based json schema validator (Another Json Validator). JS was selected because it's the language of the web and generally kept up to date better than pure-cpp versions (the latest stable cpp version was still at draft 7, js versions are up to date to the soon-to-be-released v1), making updating to current json-schema.org releases much easier.

Info, documentation and examples are in the readme.

This PR requires nwnx-builder to be republished.

Comment on lines 1 to 7
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/ajv_bundle_data.h"
COMMAND xxd -i "ajv_runtime.min.js" "${CMAKE_CURRENT_BINARY_DIR}/ajv_bundle_data.h"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/external/ajv/dist"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/external/ajv/dist/ajv_runtime.min.js"
VERBATIM
)
Copy link
Member

@Daztek Daztek Jan 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we not run this locally and just bundle ajv_bundle_data.h in the tree? We'd get rid of the xxd dependency and wouldn't have cmake doing this each compile

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can. However, I included this here to make updating the ajv bundle easier if and when there is an ajv or quickjs update as it didn't seem too heavy a load to run during the target build process. A quickjs update isn't all that necessary, but ajv (and its associated bundle) could be updated relatively often to support the latest schema (both of the support systems have scripts for updating them). If the static header is compiled and included, then the xxd requirement in the builder would go away, but it would levy an additional local environmental requirement (xxd or similar) on the updater's machine.

The options as I see them are:

  1. Remove this compilation step and levy the local environmental requirement for compilation on the updater's machine before commit.

  2. Remove this compilation step and add the compilation as a GHA step if/when updated ajv files are committed.

  3. Leave as is.

I'm fine with any of them. I'm going to assume (1) is your preferred choice, so I'll move in that direction today, removing the xxd requirement from the builder, modifying the ajv update script and editing the cmakelists and readme. Let me know if that's an incorrect assumption and I'll correct course. Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the ajv repo on github and npm it doesn't look like it's updated that often, last time was in 2024ish. So just having the ajv_bundle_data.h in the tree seems best to me, if there happens to be an update someone can just PR it

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in 6c4f00f.

@@ -23,7 +23,7 @@ RUN buildDeps="build-essential \
autoconf \
automake \
bison \
ccache" \
ccache \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please readd the double quote or everything'll explode at some point :D

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in b35d3f6.

/// @return A json object containing validation results.
json NWNX_Schema_ValidateInstanceByID(json jInstance, string sSchemaId, int nVerbosity = NWNX_SCHEMA_OUTPUT_VERBOSITY_NORMAL);

int NWNX_Schema_GetIsRegistered(string sSchemaId) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nit: braces should be on their own line

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in 19211fc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You missed nwnx_schema.nss I think!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, I think that's the first time I've ever written an .nss file with inline braces. Fixed in 6fc9498.

static json JSValueToJSON(JSValue val);

void SchemaUnload() __attribute__((destructor));
void SchemaUnload() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nit: braces should be on their own line

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in 19211fc.

@@ -0,0 +1,25 @@
add_shared_plugin(Schema
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add_plugin() didn't work here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in de0cef6.

@@ -0,0 +1,25 @@
add_shared_plugin(Schema
"Schema.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/external/ajv/dist/ajv_bundle_data.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

${CMAKE_CURRENT_SOURCE_DIR}/ is probably not needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in de0cef6.

Comment on lines 13 to 15
${CMAKE_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in de0cef6.

CONFIG_VERSION="2026"
)

set_target_properties(Schema PROPERTIES LINK_FLAGS "-rdynamic")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in de0cef6.

js_std_init_handlers(global_rt);
js_std_add_helpers(global_ctx, 0, NULL);

const char* js = R"(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this, and the others like it, can be static constexpr const char* so they're basically compile time constants

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in afa8a9a.

@Daztek
Copy link
Member

Daztek commented Jan 25, 2026

Before I forget, don't forget to add your plugin under the New Plugins header in CHANGELOG.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants