Published REST Swagger Example Value remains empty {} despite having Import/Export Mappings configured
0
Question Body: Hi everyone, I'm struggling with a persistent issue in my Published REST Service documentation. I have a POST operation where the Request Body and Response example values only show empty braces {} in the Swagger UI. Here is what I have already configured: JSON Structure: I created a structure using a valid JSON snippet with sample data (e.g., "Batman", "Nolan"). Mappings: I have both Import and Export mappings correctly linked to the JSON structure and the Domain Model entity. Operation Settings: In the REST operation, I selected the correct Mapping for the Request and Response, and the parameter is set to "Body". Microflow: The Microflow parameters match the entity used in the mappings. Even with all this, the "Example Value" box in Swagger does not populate with the fields from my JSON structure. I've tried cleaning the deployment directory and restarting, but it didn't help. The attributes in the JSON Structure are marked as 0..1 (optional). Could this be the reason why Mendix is omitting them from the Swagger example? If so, how can I force them to appear as a placeholder? Studio Pro Version: 10.24.6. Any help would be appreciated!
asked
William Medeiros
2 answers
1
If your Published REST operation is based on a JSON structure + Import/Export mappings, Swagger UI may still show the Example Value as {} even when the mappings are correct. A practical workaround is to switch to Message Definitions for request/response and rebuild your mappings on top of those.
What to try:
Create a Request Message Definition and a Response Message Definition (with the exact fields you want exposed).
Recreate (or adjust) your Import/Export mappings to use these Message Definitions instead of the JSON structure.
In the Published REST operation, select the new request/response mappings.
Re-publish and check Swagger again.
Note
Even after this, Swagger may not always auto-generate a populated “Example Value” in the UI. If you want a guaranteed example payload shown to consumers, add a sample JSON in the endpoint Documentation (as a JSON code block) so users have a clear request/response example regardless of Swagger’s auto-example generation.
answered
Ahmet Kudu
1
I would suggest to use Message definition for import/export using this this json becuase they enforce strict contract.
Create a Message Definition for the request + response (instead of relying on JSON Structure).
Rebuild your import/export mappings based on that Message Definition.
Re-select those mappings in the operation, redeploy.