You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
running MockServer as docker container
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/
perform the request to mockserver
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.
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.
The text was updated successfully, but these errors were encountered:
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:
excludeminimum: true
. This is correct per OpenAPI schema dialect: https://swagger.io/docs/specification/data-models/keywords/excludeminimum: true
.`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:
mockserver/mockserver-core/src/main/java/org/mockserver/validator/jsonschema/JsonSchemaValidator.java
Line 39 in b607ad6
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.
The text was updated successfully, but these errors were encountered: