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

Mocking an openapi definition with application/xml body never matches valid input #1825

Open
glitch8eda opened this issue Dec 18, 2023 · 0 comments

Comments

@glitch8eda
Copy link

Describe the issue
Importing an openapi definition for requests using application/xml body type with schema will result in expectations that never seem to be matching the body.

What you are trying to do
I would like to import an OpenAPI definition and then verify that my service is sending requests in the right format.

MockServer version
5.15.0

To Reproduce
Steps to reproduce the issue:

  1. I used the MockServerJavaClient to import open api definition
  2. Tried running a request against it and logs show everything matches except for body.

I noticed that the expectation seems weird:
"method" : "POST",
2023-12-18 11:03:30 "path" : "/request",
2023-12-18 11:03:30 "headers" : {
2023-12-18 11:03:30 "content-type" : [ "application\/xml.*" ]
2023-12-18 11:03:30 },
2023-12-18 11:03:30 "body" : {
2023-12-18 11:03:30 "type" : "JSON_SCHEMA",
2023-12-18 11:03:30 "jsonSchema" : {

notice how the content-type description seems broken. Why the \/ ??
Also the body type is JSON_SCHEMA, but that could be OK because OpenAPI uses the same schemas for both XML and JSON, however, is Mock Server going to read the xml tags in the schema?

Expected behaviour
Simple request should have been accepted. If there is indeed some valid reason to reject the body, I would appreciate that the reason is explained in the logs. So far the only explanation we get is "body doesn't match". Why doesn't it match? Is is the content-type? Is it the xml doesn't match the schema? A mandatory field is missing?

MockServer Log

2023-12-18 11:03:30 2023-12-18 16:03:30 5.15.0 INFO 1080 request:
2023-12-18 11:03:30 
2023-12-18 11:03:30   {
2023-12-18 11:03:30     "method" : "POST",
2023-12-18 11:03:30     "path" : "/request",
2023-12-18 11:03:30     "headers" : {
2023-12-18 11:03:30       "user-agent" : [ "ReactorNetty/1.1.13" ],
2023-12-18 11:03:30       "host" : [ "localhost:15000" ],
2023-12-18 11:03:30       "content-length" : [ "548" ],
2023-12-18 11:03:30       "accept-encoding" : [ "gzip" ],
2023-12-18 11:03:30       "accept" : [ "*/*" ],
2023-12-18 11:03:30       "Content-Type" : [ "application/xml;charset=UTF-8" ]
2023-12-18 11:03:30     },
2023-12-18 11:03:30     "keepAlive" : true,
2023-12-18 11:03:30     "secure" : false,
2023-12-18 11:03:30     "protocol" : "HTTP_1_1",
2023-12-18 11:03:30     "localAddress" : "172.18.0.4:1080",
2023-12-18 11:03:30     "remoteAddress" : "172.18.0.1:54502",
2023-12-18 11:03:30     "body" : "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n...REDACTED FOR GITHUB POST...\n"
2023-12-18 11:03:30   }
2023-12-18 11:03:30 
2023-12-18 11:03:30  didn't match open api operation "redactedForGithub" content-type "application/xml" request matcher:
2023-12-18 11:03:30 
2023-12-18 11:03:30   {
2023-12-18 11:03:30     "method" : "POST",
2023-12-18 11:03:30     "path" : "/request",
2023-12-18 11:03:30     "headers" : {
2023-12-18 11:03:30       "content-type" : [ "application\\/xml.*" ]
2023-12-18 11:03:30     },
2023-12-18 11:03:30     "body" : {
2023-12-18 11:03:30       "type" : "JSON_SCHEMA",
2023-12-18 11:03:30       "jsonSchema" : {
2023-12-18 11:03:30         "properties" : {
                                  REDACTED
2023-12-18 11:03:30         },
2023-12-18 11:03:30         "required" : [ REDACTED ],
2023-12-18 11:03:30         "type" : "object",
2023-12-18 11:03:30         "xml" : {
2023-12-18 11:03:30           "name" : "redacted"
2023-12-18 11:03:30         }
2023-12-18 11:03:30       }
2023-12-18 11:03:30     }
2023-12-18 11:03:30   }
2023-12-18 11:03:30 
2023-12-18 11:03:30  because:
2023-12-18 11:03:30 
2023-12-18 11:03:30   method matched
2023-12-18 11:03:30   path matched
2023-12-18 11:03:30   body didn't match
2023-12-18 11:03:30  
2023-12-18 11:03:30 2023-12-18 16:03:30 5.15.0 INFO 1080 no expectation for:
2023-12-18 11:03:30 
2023-12-18 11:03:30   {
2023-12-18 11:03:30     "method" : "POST",
2023-12-18 11:03:30     "path" : "/request",
2023-12-18 11:03:30     "headers" : {
2023-12-18 11:03:30       "user-agent" : [ "ReactorNetty/1.1.13" ],
2023-12-18 11:03:30       "host" : [ "localhost:15000" ],
2023-12-18 11:03:30       "content-length" : [ "548" ],
2023-12-18 11:03:30       "accept-encoding" : [ "gzip" ],
2023-12-18 11:03:30       "accept" : [ "*/*" ],
2023-12-18 11:03:30       "Content-Type" : [ "application/xml;charset=UTF-8" ]
2023-12-18 11:03:30     },
2023-12-18 11:03:30     "keepAlive" : true,
2023-12-18 11:03:30     "secure" : false,
2023-12-18 11:03:30     "protocol" : "HTTP_1_1",
2023-12-18 11:03:30     "localAddress" : "172.18.0.4:1080",
2023-12-18 11:03:30     "remoteAddress" : "172.18.0.1:54502",
2023-12-18 11:03:30     "body" : "REDACTED"
2023-12-18 11:03:30   }
2023-12-18 11:03:30 
2023-12-18 11:03:30  returning response:
2023-12-18 11:03:30 
2023-12-18 11:03:30   {
2023-12-18 11:03:30     "statusCode" : 404,
2023-12-18 11:03:30     "reasonPhrase" : "Not Found"
2023-12-18 11:03:30   }
2023-12-18 11:03:30
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