How is your experience with the OutSystems Community?
21
Views
1
Comments
Solved by AI
How to create example in Swagger?
Application Type
Reactive

Hi there, I am wondering how to create example value for parameter input in a swagger?

regards and thanks

2023-12-26 10-35-28
OutSystems Neo
Staff
Solution by AI
AI Generated

You can’t directly edit that “Example Value” box in OutSystems; it’s generated from your method’s input structure and the sample values you set for its attributes.

To influence what appears there, you need to change the default/sample values of the structure that is used as the body parameter of the REST method.

Here’s how to do it in O11:

  1. Find the structure used in the body

    • In Service Studio, open your REST API (Expose or Consume).
    • Select the method you’re documenting (for example, POST /contacts).
    • In the Input Parameters list, locate the parameter of Type = Contact (or whatever structure you’re sending in the body) with Receive In = Body.
    • Right‑click that type → Go to Definition to open the Structure.
  2. Set sample/default values on the attributes

    • In the Data tab, open that Structure (e.g., Contact).
    • Select each attribute (Title, Name, Gender, etc.).
    • In the properties, set:
      • Default value (for strongly typed fields, e.g. Birthday) and/or
      • Sample value (if available in your version of Service Studio).
    • For example:
      • Title: "Mr."
      • Name: "John Doe"
      • Gender: "Male"
      • Birthday: #2014-12-31#
      • Email: "john.doe@example.com"

    OutSystems uses these values when generating the Example Value and Model in the documentation for JSON bodies. [[REST API Structures<https://success.outsystems.com/documentation/11/developing_an_application/integration/consuming_rest_apis/rest_api_structures]]

  3. Publish and re-check the documentation

    • Publish the module.
    • Open Built-in API Documentation (Under the module in the browser).
    • Navigate to the REST method again and check the Example Value for the body parameter. It will reflect the attribute sample/default values you’ve set.

A couple of extra notes:

  • The shape of the JSON (which fields appear, names, types) is controlled by the structure definition itself (attributes and types). [[REST API Structures<https://success.outsystems.com/documentation/11/developing_an_application/integration/consuming_rest_apis/rest_api_structures]]
  • If you change the structure (add/remove attributes), the Example and Model sections in the Swagger/UI update accordingly.
  • For exposed REST APIs, you can only “enrich” the Swagger up to what OutSystems supports (example values per field, descriptions, etc.); you can’t programmatically inject arbitrary example payloads beyond what’s inferred from the structures. [[REST Expose - Additional information in Swagger<https://www.outsystems.com/forums/discussion/76623/rest-expose-additional-information-in-swagger]]

So in summary: define and maintain your example values at the structure attribute level in Service Studio; OutSystems uses those to generate the example JSON you see in Swagger/UI.

This answer was AI-generated. Please read it carefully and use the forums for clarifications
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.