synapse icon indicating copy to clipboard operation
synapse copied to clipboard

Failed to determine the required body parameter for a function defined in OAS 2.0

Open bvandewe opened this issue 3 years ago • 1 comments
trafficstars

What happened:

The worker throws the below error when trying to read the OpenAPI/Swagger spec for a POST function, defined in v2.0:

[14:12:14] info: Synapse.Worker.Services.Processors.OpenApiFunctionProcessor[0]
      Initializing activity '73c0fdcb-2a02-448f-9bf6-bf79d8d719d9' (type: 'Action')...
[14:12:14] info: System.Net.Http.HttpClient.Default.LogicalHandler[100]
      Start processing HTTP request GET https://private-server/v2/api-docs?group=mosaic-server
[14:12:14] info: System.Net.Http.HttpClient.Default.ClientHandler[100]
      Sending HTTP request GET https://private-server/v2/api-docs?group=mosaic-server
[14:12:15] info: System.Net.Http.HttpClient.Default.ClientHandler[101]
      Received HTTP response headers after 1456.6153ms - 200
[14:12:15] info: System.Net.Http.HttpClient.Default.LogicalHandler[101]
      End processing HTTP request after 1456.8661ms - 200
[14:12:16] warn: Synapse.Worker.Services.Processors.OpenApiFunctionProcessor[0]
      An error occured while executing the activity '73c0fdcb-2a02-448f-9bf6-bf79d8d719d9' (type: 'Action')/r/nDetails:/r/nSystem.NullReferenceException: Failed to determine the required body parameter for the function with name 'create-user-account'
         at Synapse.Worker.Services.Processors.OpenApiFunctionProcessor.InitializeAsync(CancellationToken cancellationToken) in /src/src/apps/Synapse.Worker/Services/Processors/OpenApiFunctionProcessor.cs:line 244
[14:12:16] warn: Synapse.Worker.Services.Processors.OperationStateProcessor[0]
      An error occured while executing the activity '7a04117d-6e9e-473d-a608-2cfd34431013' (type: 'State')/r/nDetails:/r/nSystem.NullReferenceException: Failed to determine the required body parameter for the function with name 'create-user-account'
         at Synapse.Worker.Services.Processors.OpenApiFunctionProcessor.InitializeAsync(CancellationToken cancellationToken) in /src/src/apps/Synapse.Worker/Services/Processors/OpenApiFunctionProcessor.cs:line 244
[14:12:16] warn: Synapse.Worker.Services.WorkflowRuntime[0]
      An error occured while executing the workflow instance: System.NullReferenceException: Failed to determine the required body parameter for the function with name 'create-user-account'
         at Synapse.Worker.Services.Processors.OpenApiFunctionProcessor.InitializeAsync(CancellationToken cancellationToken) in /src/src/apps/Synapse.Worker/Services/Processors/OpenApiFunctionProcessor.cs:line 244
[14:12:16] info: Microsoft.Hosting.Lifetime[0]
      Application is shutting down...

SW Function def

"functions": [
    {
      "name": "create-user-account",
      "operation": "https://private-server/v2/api-docs?group=mosaic-server#signUpUsingPOST",
      "type": "rest",
      "authRef": "mosaic-tmp-oauth2"
    },

snip

"states":

snip

    {
      "name": "Create User Account",
      "type": "operation",
      "actions": [
        {
          "name": "Create User Account",
          "actionDataFilter": {
            "toStateData": "${ .userAccount }"
          },
          "functionRef": {
            "refName": "create-user-account",
            "arguments": {
              "body": {
                "user": "${ .newUser }"
              }
            }
          }
        }
      ]
      "end": true
    }

Tried multiple variations of the body, of which:

    "functionRef": {
            "refName": "create-user-account",
            "arguments": {
              "body": "${ .newUser }"
            }

OAS Function def

{
  "swagger": "2.0",

  snip

  "paths": {
    "/api/user/signup": {
      "post": {
        "tags": [
          "user-controller"
        ],
        "summary": "Sign up for user account in Mosaic.",
        "description": "Allowed for Admins and EPMs",
        "operationId": "signUpUsingPOST",
        "consumes": [
          "application/json"
        ],
        "produces": [
          "*/*"
        ],
        "parameters": [
          {
            "in": "body",
            "name": "user",
            "description": "user",
            "required": true,
            "schema": {
              "$ref": "#/definitions/MosaicUserInputDTO"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "schema": {
              "type": "object"
            }
          },
          "201": {
            "description": "Returns the new  mosaic user info after creation"
          },
          "400": {
            "description": "Missing details in the request"
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Not Found"
          },
          "501": {
            "description": "Error encountered when adding user account to Mosaic"
          }
        }
      }
    },

What you expected to happen:

Would expect Synapse to be able to parse a POST function described in OAS spec v2.x, as it does for GET functions.

How to reproduce it:

POST data to an endpoint described in OAS v2.0.

Anything else we need to know?:

Environment:

Synapse 0.1.25, K8s/Istio, Keycloak

bvandewe avatar Sep 19 '22 14:09 bvandewe

Acceptable workaround: do not define "body" explicitly in the arguments and let Synapse figure it out on its own...

i.e.: change

    "functionRef": {
            "refName": "create-user-account",
            "arguments": {
              "body": {
                "user": "${ .newUser }"
              }
            }

to

    "functionRef": {
            "refName": "create-user-account",
            "arguments": {
              "user": "${ .newUser }"
            }

bvandewe avatar Sep 21 '22 10:09 bvandewe

This is as designed when using OpenAPI, I don't know why I overlooked it and did not close it before. Sorry about that.

let Synapse figure it out on its own

That's the expected behavior: Synapse handles named arguments and ensures they are correctly placed and encoded according to the OpenAPI document's specifications. Users don't need to worry about query parameters, paths, headers, cookies, or body content. In OpenAPI, these details are abstracted away by the defining document.

cdavernas avatar May 26 '24 12:05 cdavernas