Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
bvandewe opened this issue Sep 19, 2022 · 2 comments
Assignees
Labels
app: server Concerns the server priority: high Indicates a high priority issue type: bug Something isn't working weight: 1 An issue that has a very low development impact
Projects

Comments

@bvandewe
Copy link

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

@cdavernas cdavernas self-assigned this Sep 20, 2022
@cdavernas cdavernas added type: bug Something isn't working priority: high Indicates a high priority issue app: server Concerns the server weight: 1 An issue that has a very low development impact labels Sep 20, 2022
@cdavernas cdavernas added this to To do in Server via automation Sep 20, 2022
@cdavernas cdavernas added this to the 0.2.0 milestone Sep 20, 2022
@bvandewe
Copy link
Author

bvandewe commented Sep 21, 2022

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 }"
            }

@cdavernas cdavernas modified the milestones: v0.2.0, v0.3.0 Sep 26, 2022
@cdavernas cdavernas removed this from the v0.3.0 milestone Nov 4, 2022
@cdavernas
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app: server Concerns the server priority: high Indicates a high priority issue type: bug Something isn't working weight: 1 An issue that has a very low development impact
Projects
No open projects
Server
To do
Development

No branches or pull requests

2 participants