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

TCK bug? Use of equalTo PetStoreAppTest#testSchema rejects 10.0 for schema.multipleOf #412

Closed
tjquinno opened this issue Feb 24, 2020 · 2 comments · Fixed by #418
Closed

Comments

@tjquinno
Copy link

In PetStoreAppTest#testSchema, line 58 retrieves schema.multipleOf and uses Hamcrest's equalTo(10) to check the value returned from the server under test.

The Schema annotation declares multipleOf as a double, and the petId parameter on PetResource#getPetById is 10.

The Schema model interface defines 'multipleOf' as a BigDecimal. As it turns out the SnakeYAML serializer emits 10.0 in this case, using the BigDecimal type on the model interface to drive the output format.

This causes the TCK test to fail -- incorrectly I think -- because the test uses Hamcrest's equalTo(10) which does not match 10.0.

I have worked around this in the extensions we use with SnakeYAML so we can pass that TCK test, but it's a bit of a pain.

(There is a mention of the double/BigDecimal mismatch regarding multipleOf in #178 (closed) but that issue is really not directly related to this one.)

Using decimal notation to format a BigDecimal seems perfectly reasonable, so can the test be changed to accept 10 and 10.0?

I have not looked for similar constructs elsewhere in the tests that might also need attention. This was the only test failure I saw due to this problem.

@tjquinno
Copy link
Author

Related (I think), if the server replies with OpenAPI JSON that contain this as part of the schema data:

              "maximum": !!float '101',
              "minimum": !!float '9',

(with the explicit type tags) then the checks for maximum and minimum in the same PetStoreAppTest#testSchema test also fail.

Not surprisingly, if I inspect the ValidatableResponse response content using the debugger, then here is the JSON for those properties (I didn't pretty-format it -- it's copied and pasted directly from the debugger):

"maximum":101.0,"minimum":9.0

This seems to be triggering the same behavior I mentioned earlier with multipleOf.

@MikeEdgar
Copy link
Member

Possible solution would be to update numeric equality checks with org.hamcrest.Matchers#comparesEqualTo where appropriate.

Azquelt pushed a commit to Azquelt/microprofile-open-api that referenced this issue Mar 17, 2022
Allow setting version and other info elements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants