Version an operation with multiple versions

If an operation is valid in one or more versions, you can set this in the WSVersion attribute.

In the example, the function "prices_v1v2" is versioned for two versions, "v1" and "v2".

Multiple versions

IMPORT com

PUBLIC DEFINE userError RECORD ATTRIBUTES(WSError = "User error")
  message STRING
END RECORD

PUBLIC FUNCTION prices_v1v2(nb INTEGER ATTRIBUTES(WSParam))
  ATTRIBUTES (WSGet,WSPath = "/prices/{nb}",
               WSDescription = "Returns the price of an item for API v1 and v2",
               WSThrows = "404:item not found", 
               WSVersion = "v1,v2") 
  RETURNS (INTEGER)
   DEFINE price DECIMAL(10,2)
    TRY
      SELECT unit_price INTO price FROM unit_pricing
        WHERE unit_id = nb
      IF sqlca.sqlcode = 100 THEN
        CALL com.WebServiceEngine.SetRestError(404,NULL)
      END IF
    CATCH
      LET userError.message = SFMT(" - SQL error:%1 [%2]",
                                   sqlca.sqlcode, SQLERRMESSAGE)
      CALL com.WebServiceEngine.SetRestError(505,userError)
    END TRY
    RETURN price
END FUNCTION
The GWS will select this operation when you generate the OpenAPI documentation for either version "v1" or "v2":
  • http://myhost:6394/gas/ws/r/myGroup/myXcf/myService?openapi.json&version=v1
  • http://myhost:6394/gas/ws/r/myGroup/myXcf/myService?openapi.json&version=v2