LiveRamp / reslang

A language for describing resource-oriented APIs & turning them into Swagger or resource diagrams. Oriented around the concepts we want to expose in the APIs.
Apache License 2.0
23 stars 7 forks source link

Make "actions" routes unopinionated about response keys #145

Closed cjea closed 3 years ago

cjea commented 4 years ago

Source (@ellensartorelli FYI)

Description

Response bodies from "actions" routes should be customizable, as opposed to being locked in to the last part of the URL path (details in document linked above)

Value provided

More control for teams in determining the shape of their response body, ability to override the default if necessary

njaczko commented 4 years ago

@ellensartorelli @cjea

You can actually specify the response body for actions.

Here's an example from the Asset Permissioning Spec we're working on:

This Reslang generates an endpoint with the path /v1/policies/actions/check:

sync bulk action Policy::Check {
    orgID: string
    asset: Asset
    operation: OperationType

    /operations
      POST
        "Result of the policy check, including allowed or denied." 200 PolicyCheckResponse
}

structure PolicyCheckResponse {
    allowed: boolean
    metadata: stringmap<string>
    denyReasons: string[]
}

The generated response body looks like this (copied this from the Response Samples in the Swagger UI):

{
  "allowed": true,
  "metadata": {
    "property1": "string",
    "property2": "string"
  },
  "denyReasons": [
    "string"
  ]
}