ZenWave360/json-schema-ref-parser-jvm

Overwriting JSONPath defaults produces side effects

eloo-abi opened this issue · 2 comments

Hi,

i have just discovered your library to resolve references in json file i want to parse and validate manually.
So far this worked pretty good but then out of nowhere one different test in my project has failed.

The project is a SpringBoot project and i also use "jsonPath" for validating responses bodies and there it seems that one call in your project produces a lot of side effects.

In general the problem is "setting the defaults" for jayway json path to "something" customized.
https://github.com/ZenWave360/json-schema-ref-parser-jvm/blob/main/src/main/java/io/zenwave360/jsonrefparser/parser/Parser.java#L86

So my code using your library looks like this

            $RefParser refParser = new $RefParser(resource.getContentAsString(Charset.defaultCharset()));
            Object json = refParser.parse().dereference().getRefs().jsonContext.json();

and i was able to fix/revert this customization with "resetting" the defaults of the jsonpath lib

            Configuration.setDefaults(DefaultsImpl.INSTANCE);

The side effect was detected in this test code

        webTestClient.get().uri("v3/api-docs/event-api")
            .exchange()
            .expectStatus().isOk()
            .expectBody()
            .jsonPath("paths['/messaging/events'].get.parameters[?(@.name=='type')].examples").exists()

The issue here was that the jsonPath mathing was not working anymore.

I guess the best way would be to not overwrite such defaults because this could everytime lead to side effects und better use a dedicated configuration for your customizations.

Best regards

Hi @eloo-abi

thanks a lot for your detailed report, it makes sense...

I happens that the project I use this library uses the same jackson customizations as the library... 🙄

I will get into this soon

hey @eloo-abi
thanks a lot for taking the time to report this..
the fix has been released as part of version v0.8.4
cheers!