How to test a Published REST Service with the swagger UI.

1
My REST service has a POST operation that accepts a single body parameter.   The generated swagger UI page should allow me to test my service quickly but whenever I enter some JSON in the body parameter, the Execute button fails to call the service. Is this generated page operating correctly? I’ve tested the same operation with the same JSON body parameter in SOAPUI and it works as expected.   Also, does this swagger UI page support passing in XML parameters? the parameter content type dropdown only ever seems to contain the option ‘application/json’.    
asked
6 answers
3

The execute button does nothing.

So, I noticed that the parameter type for SAPDataBatch is ‘file’ rather than ‘object’ as I have in other POST operations. This must be because I used a JSON structure to generate the import mapping. I created a message definition using the same schema objects and generated a new import mapping from that. Hey presto!, on the swagger page the parameter type is now object and I can execute my request….

Unfortunately, the import mapping creates an empty schema object. 

answered
1

Hi Gerrit,

My service operation:

Body parameter:

swagger UI page (note: already authenticated!):

answered
1

Just wanted to share what i’ve just learnt the hard way, in case anyone else ran into something similar:

 

In my case, we’ve opted to use JSON structure for our import/export mappings instead of Message Definitions because the latter does not currently support specialized entities (there’s an idea posted here in case this is something you’d want too: https://forum.mendix.com/link/ideas/2650)

 

However, the downside of using JSON structure for the mappings is that the Swagger documentation will be more limited compared to using Message Definitions. In their documentation (JSON Schema for Published REST Operation), they write that “Operations that have an import or export mapping defined on it will generate such a schema, but only for mappings that are based on message definitions.” and also that if the mapping is not based on a message definition, your body parameter will be depicted as a 'file' type.

So this is the current documented behavior rather than a bug, and you will not be able to click on “Execute” on Swagger, because it will not know of your actual model/schema and is expecting a ‘file’ instead of a JSON input to the body parameter.

 

I noted OP was using JSON structure for mappings too hence seeing the same issues I had. Apologies for the long mouthful, but TL;DR: the Swagger generated from Mendix will only work as expected if you’re using Message definitions for your import/export mapping, instead of JSON structure.

answered
0

Normaly Swagger UI provides you the parameters as inpput fields which you are able to use. Do you use a message definition for your REST service? Then Swagger UI should provide you more detailed information about your built service..

Maybe you can provide some more information about your implementation to propably have a better undertsanding of your issue.

answered
0

Did you perhaps miss the authentication pop-up after hitting execute? Happens to me sometimes.. :)

answered
0

Hey… 

Facing the same issue. can i know how you got this resolved ?

answered