Skip to content

Commit

Permalink
MoreApp Forms - Improve "Create task" action (#3636)
Browse files Browse the repository at this point in the history
* Improve "Create task" action

* Review comments
  • Loading branch information
beestree authored Sep 12, 2024
1 parent b051dd9 commit 9eb2c61
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
36 changes: 35 additions & 1 deletion certified-connectors/MoreApp Forms/apiDefinition.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,31 @@
],
"description": "Downloads a report."
}
},
"/api/v1.0/forms/customer/:customerId:/forms/{formId}/versions": {
"get": {
"responses": {
"200": {
"description": "default",
"schema": {
"type": "object"
}
}
},
"summary": "Get formVersion",
"operationId": "GetFormVersion",
"parameters": [
{
"name": "formId",
"in": "path",
"x-ms-summary": "formId",
"description": "formId",
"type": "string",
"required": true
}
],
"description": "Lists versions of a form"
}
}
},
"x-ms-connector-metadata": [
Expand Down Expand Up @@ -653,7 +678,16 @@
"type": "string"
},
"data": {
"type": "object"
"type": "object",
"x-ms-dynamic-schema": {
"operationId": "GetFormVersion",
"value-path": "schema",
"parameters": {
"formId": {
"parameter": "formId"
}
}
}
},
"publishInfo": {
"type": "object",
Expand Down
32 changes: 31 additions & 1 deletion certified-connectors/MoreApp Forms/script.csx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public class Script : ScriptBase
public class Script : ScriptBase
{
public override async Task<HttpResponseMessage> ExecuteAsync()
{
Expand Down Expand Up @@ -57,6 +57,36 @@
return reportResponse;
}

// Create an OpenAPI schema from a formVersion
// Runs only for GetFormVersion
if (this.Context.OperationId == "GetFormVersion")
{
JArray responseBody = JArray.Parse(await response.Content.ReadAsStringAsync().ConfigureAwait(false));
JArray fields = (JArray) responseBody[0]["fields"];
JObject properties = new JObject();

foreach (JObject field in fields)
{
JObject fieldProperties = (JObject) field["properties"];
if(fieldProperties.ContainsKey("data_name")) {
JObject widget = new JObject();
widget["oneOf"] = new JArray();
((JArray) widget["oneOf"]).Add(new JObject{["type"] = "string"});
((JArray) widget["oneOf"]).Add(new JObject{["type"] = "object"});
widget["x-ms-summary"] = fieldProperties["label_text"];
widget["description"] = fieldProperties["label_text"];
properties[(string) fieldProperties["data_name"]] = widget;
}
}

var schema = new JObject();
schema["type"] = "object";
schema["properties"] = properties;
var root = new JObject();
root["schema"] = schema;
response.Content = CreateJsonContent(root.ToString());
}

return response;
}

Expand Down

0 comments on commit 9eb2c61

Please sign in to comment.