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

Allow file names in mappings to end in .json5 #2405

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

samueldcs
Copy link

@samueldcs samueldcs commented Sep 30, 2023

Addresses #2397.
WireMock already supports json5, but files ending in extensions other than json are ignored. I've changed this behavior to also load json5 files, both from remote and local sources.

Submitter checklist

  • Recommended: Join WireMock Slack to get any help in #help-contributing or a project-specific channel like #wiremock-java
  • The PR request is well described and justified, including the body and the references
  • The PR title represents the desired changelog entry
  • The repository's code style is followed (see the contributing guide)
  • Test coverage that demonstrates that the change works as expected

@samueldcs samueldcs requested a review from a team as a code owner September 30, 2023 18:31
Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

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

Looks good to me, thank you!

Copy link
Member

Choose a reason for hiding this comment

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

Could we expand this to confirm support for all the JSON5 features documented at json5.org?

Copy link
Author

Choose a reason for hiding this comment

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

Uh-oh! It doesn't seem every feature is supported with the current ObjectMapper configuration.
A quick read through Jackson's documentation seems to indicate that most (though not all) JSON5 features are supported. Is it okay if I mess with WireMock's ObjectMapper to enable the missing options, and maybe document the current limitations?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I think let's write tests for each and enable everything we can. IIRC it's only one or two things that aren't supported by Jackson.

Copy link
Author

Choose a reason for hiding this comment

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

I've covered all the JSON5 features I could get working. A few notes:

  • In accordance to this StackOverflow answer, I've found that quite a few JSON5 features are not yet supported by Jackson. I couldn't find any kind of roadmap suggesting that'll change anytime soon
  • Perhaps we should upgrade from configuring JsonParser.Feature to enabling JsonReadFeature according to the jackson docs, but I guess that's another PR

Copy link
Member

Choose a reason for hiding this comment

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

I feel like these are likely to be lesser used features. I think it would be reasonable to make a note in the docs about these caveats but still claim support for JSON5.

@oleg-nenashev oleg-nenashev changed the title allow file names in mappings to end in .json5 Allow file names in mappings to end in .json5 Oct 3, 2023
@tomakehurst
Copy link
Member

Please can you do a ./gradlew spotlessApply and push?

@samueldcs
Copy link
Author

Please can you do a ./gradlew spotlessApply and push?

Uhhh nothing appears to have changed.. might be related to #2333?

@oleg-nenashev
Copy link
Member

@samueldcs Maybe :( I am not a huge fan of spotless, but fixing it until it passes seems to be the only way. Or one could add a github action that applies Spotless to an arbitrary pull request (with a risk of royal mess if it goes wrong)

@@ -320,7 +320,7 @@ void reportsErrorFromSubMatcher() {
.match("<something>{ bad json</something>");
checkJsonError(
matchResult,
"Unexpected character ('b' (code 98)): was expecting double-quote to start field name\n at [Source: (String)\"{ bad json\"; line: 1, column: 4]");
"Unexpected character ('j' (code 106)): was expecting a colon to separate field name and value\n at [Source: (String)\"{ bad json\"; line: 1, column: 8]");
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 we shouldn't change the way we parse user-supplied JSON in requests/responses, just stub mappings. I think maintaining a separate parser configuration and switching into it in the mappings loader (and possibly the API) might be the way forward here.

@tomakehurst tomakehurst self-assigned this Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants