Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format validation not working #117

Open
federico-mendoza opened this issue Jan 10, 2025 · 4 comments
Open

Format validation not working #117

federico-mendoza opened this issue Jan 10, 2025 · 4 comments

Comments

@federico-mendoza
Copy link

Hi, we've bumped into an issue introduced in v0.2.0. Apparently format validation got unsupported.

I've attached some testing contrasting v0.1.0 and v0.3.0 responses to a body with purposefully wrong formats for uuid and uri fields defined in the schema, and I can see that v0.1.0 is flagging the non compliant field fine and failing the test as it should, where v0.3.0 is not checking the format and passing the tests OK.

Was this change intended? Is there maybe another way of validating format in 0.3.0?

v0.1.0_UUID_URI_validation.log
v0.3.0_UUID_URI_validation.log

@daveshanley
Copy link
Member

There was a upgrade in v0.2.0 to use the latest version of the json schema library we use (this is what performs the UUID check).

v0.2.0 release notes:

No new features, but does upgrade latest deps (libopenapi) https://github.com/santhosh-tekuri/jsonschema to v0.6.1 Which improves all schema handling. A few tune ups were required, error messages are slightly different now and there is less noise in the machine.

@federico-mendoza
Copy link
Author

There was a upgrade in v0.2.0 to use the latest version of the json schema library we use (this is what performs the UUID check).

v0.2.0 release notes:

No new features, but does upgrade latest deps (libopenapi) https://github.com/santhosh-tekuri/jsonschema to v0.6.1 Which improves all schema handling. A few tune ups were required, error messages are slightly different now and there is less noise in the machine.

Hi, looking at the latest version of https://github.com/santhosh-tekuri/jsonschema (v0.6.1) I've noticed there was a change in default behaviour for format testing that is affecting previous functionality on this lib, in particular format validation.

According to the message in this discussion santhosh-tekuri/jsonschema#172 format validation was enabled by default for v5, where the default behaviour for v6 is disabled.
To reenable the previous behaviour Compiler.AssertFormat has to be called after compiler creation.

compiler := jsonschema.NewCompiler() compiler.UseRegexpEngine(options.RegexEngine) // Ensure any configured regex engine is used. compiler.AssertFormat()

The documentation for compiler.AssertFormat indicates that the default behaviour was changed.

It might also be worth looking at AssertContent and AssertVocabs which may also be relevant.

@MRawlings
Copy link

Fed is potentially out for a while, so I'll also follow this as well.
just to note there are some line-breaks missing in the code section above.

    compiler := jsonschema.NewCompiler() 
    compiler.UseRegexpEngine(options.RegexEngine) // Ensure any configured regex engine is used. 
    compiler.AssertFormat()

@MRawlings
Copy link

MRawlings commented Jan 23, 2025

Just to record the following currently reinstates the capability to perform String/Format validation by allowing the capability to be configured.

Maybe getting that capability included would enable this issue to be resolved.

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

No branches or pull requests

3 participants