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

using creating an expectation using an OpenAPI/Swagger spec uses the wrong JSON schema dialect #1896

Open
fvanderwielen opened this issue Aug 13, 2024 · 0 comments

Comments

@fvanderwielen
Copy link

Describe the issue
When creating an expectation using an OpenAPI/Swagger spec, MockServer uses the wrong JSON schema dialect to create the actual expectation out of it.

What you are trying to do
create an expectation using an openAPI swagger spec. MockServer (MS) running as a docker container, calling the create expectation endpoint, with inline swagger spec in the request body.

MockServer version
The version you are using: 5.15.0

To Reproduce
Steps to reproduce the issue:

  1. running MockServer as docker container
  2. create the expectation from swagger API via curl, for a specific operationID. The operation has a schema for the body, that uses excludeminimum: true. This is correct per OpenAPI schema dialect: https://swagger.io/docs/specification/data-models/keywords/
  3. perform the request to mockserver
  4. Code you used to create expectations: curl. I cannot share the openAPI spec itself, sadly, but as mentioned it has in the schema excludeminimum: true.
  5. What error you saw: In the log in the control plane UI/dashboard, an error is reported:
    `ERROR

exception validating JSON

exception:
com.networknt.schema.JsonSchemaException: exclusiveMinimum value is not a number at com.networknt.schema.ExclusiveMinimumValidator.(ExclusiveMinimumValidator.java:41) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480) at com.networknt.schema.ValidatorTypeCode.newValidator(ValidatorTypeCode.java:158) at com.networknt.schema.JsonMetaSchema.newValidator(JsonMetaSchema.java:286) at com.networknt.schema.ValidationContext.newValidator(ValidationContext.java:57) at com.networknt.schema.JsonSchema.read(JsonSchema.java:236) at com.networknt.schema.JsonSchema.getValidators(JsonSchema.java:524) at com.networknt.schema.JsonSchema.validate(JsonSchema.java:315) at com.networknt.schema.PropertiesValidator.validate(PropertiesValidator.java:69) at com.networknt.schema.JsonSchema.validate(JsonSchema.java:316) at com.networknt.schema.JsonSchema.validate(JsonSchema.java:299) at org.mockserver.validator.jsonschema.JsonSchemaValidator.isValid(JsonSchemaValidator.java:167) at org.mockserver.matchers.JsonSchemaMatcher.matches(JsonSchemaMatcher.java:46) at org.mockserver.matchers.JsonSchemaMatcher.matches(JsonSchemaMatcher.java:16) at org.mockserver.matchers.HttpRequestPropertiesMatcher.matches(HttpRequestPropertiesMatcher.java:498) at org.mockserver.matchers.HttpRequestPropertiesMatcher.bodyMatches(HttpRequestPropertiesMatcher.java:476) at org.mockserver.matchers.HttpRequestPropertiesMatcher.bodyMatches(HttpRequestPropertiesMatcher.java:444) at org.mockserver.matchers.HttpRequestPropertiesMatcher.matches(HttpRequestPropertiesMatcher.java:290) at org.mockserver.matchers.HttpRequestPropertiesMatcher.matches(HttpRequestPropertiesMatcher.java:208) at org.mockserver.matchers.HttpRequestsPropertiesMatcher.matches(HttpRequestsPropertiesMatcher.java:512) at org.mockserver.mock.RequestMatchers.lambda$firstMatchingExpectation$9(RequestMatchers.java:227) at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
...`

Expected behaviour
the request does not generate an error and is matched.

MockServer Log
please see above for the logged error.

Further info
in search of a proper fix I dived into the code of mockserver. In the end the problem is that the default JSON schema dialect used is incompatible with the JSON schema dialect of OpenAPI:

building an expectation without OpenAPI spec but with JSONschema directly does allow for setting the schema dialect explicitly, as mentioned in the MS docs on this. But using an OpenAPI spec uses its parser, and $schema is unsupported or otherwise stripped out of when parsing/serializing it, it seems. Because I did try to add $schema to V4 when PUTing the expectation, but see it gone in the expectation shown on the dashboard.

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

1 participant