Azure custom connector dynamic schema not working - azure

Trying to use x-ms-dynamic-values (which working as expected) and x-ms-dynamic-schema (which doesn't seems to work)
I only getting the body param name dynamicActionSchema instead of the dynamic schema.
Those are my paths:
paths:
/api/v1/actions:
get:
description: Get lists
summary: Get's action list you have access to
operationId: GetActionsList
parameters:
- {in: query, name: include_attributes, default: ref, type: string, description: The
number of items to skip before starting to collect the result set}
responses:
'200':
description: OK
schema: {$ref: '#/definitions/GetLists'}
/api/v1/actions/{actionId}:
get:
description: Gets the schema of the selected action
summary: Get's the schema of the selected action
operationId: GetActionSchema
parameters:
- {name: actionId, in: path, required: true, type: string, x-ms-summary: Select
Action}
responses:
'200':
description: OK
schema: {type: object}
/api/v1/executions/{action}:
post:
description: Executing ST action - Uses Dynamic values and dynamic schema to
draw form
summary: Executing ST action
operationId: ExecuteSTAction
parameters:
- name: action
type: string
in: path
description: Select action you want to execute
required: true
x-ms-summary: Select Action
x-ms-dynamic-values: {operationId: GetActionsList, value-path: ref}
- name: dynamicActionSchema
in: body
description: Dynamic Schema of items in selected action
schema:
type: object
x-ms-dynamic-schema:
operationId: GetActionSchema
parameters:
actionId: {parameter: action}
value-path: parameters
responses:
'201': {description: Executed}
definitions:
GetLists:
type: array
items:
type: object
properties:
ref: {type: string}
required: [ref]
security:
- API Key: []
Dynamic schema operation output sample:
{
"parameters": {
"tags": {
"description": "List of tags for item.",
"required": false,
"type": "array",
"position": 12
},
"env": {
"description": "Environment variables which will be available to the script.",
"type": "object"
},
"detected": {
"description": "The datetime for detecting the item.",
"required": true,
"type": "string",
"position": 6
},
"description": {
"description": "The description of the item.",
"required": false,
"type": "string",
"position": 2
}
...
}
}
Full example:
https://github.com/microsoft/PowerPlatformConnectors/blob/070009ba5681fd57ee6cc61d2a380123712a088f/certified-connectors/Ticketing.events/apiDefinition.swagger.json
MS docs:
https://learn.microsoft.com/en-us/connectors/custom-connectors/openapi-extensions#use-dynamic-schema
Open thread in Power Apps forum:
https://powerusers.microsoft.com/t5/Building-Power-Apps/Dynamic-schema-doesn-t-seems-to-work-based-on-a-body-parameter/m-p/1373866#M357492

Found my issue, schema should be in the form of:
{
"parameters": {
"type": "object",
"properties": {
"debug": {
"default": false,
"required": false,
"description": "Enable runner debug mode.",
"type": "boolean"
},
...
}
}
}

Related

Multiple swagger opitons in one project

I have multiple API path for admin level APIs and for customer APIs, I have defined two route folders. I want to set two swaggerOptions, but Unfortunately it only read one of them but not both, how can I set both of them but different routes.
Customer Level:
const swaggeroption1: swaggerJsDoc.Options = {
definition: {
openapi: "x.x.x",
info: {
title: "Customer API",
version: "x.x.x",
description: "Customer level",
},
servers: [
{
url: "http://localhost:80",
description: "server 1",
},
{
url: "XXXXXX",
description: "server1",
},
],
},
apis: ["./routes/customer/*.ts"],
};
Admin Level:
const swaggeroption2: swaggerJsDoc.Options = {
definition: {
openapi: "x.x.x",
info: {
title: "Admin API",
version: "x.x.x",
description: "Admin level",
},
servers: [
{
url: "http://localhost:80",
description: "server 1",
},
{
url: "XXXXXX",
description: "server2",
},
],
},
apis: ["./routes/admin/*.ts"],
};
Any Idea, how to handle these, in a single file?

Replicating Mongo schema enforcement across multiple database instances

I'm running a NodeJS application that connects to a Mongo database. I've done the initial development with the MongoClient library. I'm now learning however that without using an ORM like Mongoose, it is becoming increasingly harder to ensure the shape of the data is good. I found a nice thing in the Mongo documentation that indicates I can enforce a schema; one example looking like this:
db.createCollection("students", {
validator: {
$jsonSchema: {
bsonType: "object",
required: [ "name", "year", "major", "address" ],
properties: {
name: {
bsonType: "string",
description: "must be a string and is required"
},
year: {
bsonType: "int",
minimum: 2017,
maximum: 3017,
description: "must be an integer in [ 2017, 3017 ] and is required"
},
major: {
enum: [ "Math", "English", "Computer Science", "History", null ],
description: "can only be one of the enum values and is required"
},
gpa: {
bsonType: [ "double" ],
description: "must be a double if the field exists"
},
address: {
bsonType: "object",
required: [ "city" ],
properties: {
street: {
bsonType: "string",
description: "must be a string if the field exists"
},
city: {
bsonType: "string",
description: "must be a string and is required"
}
}
}
}
}
}
})
and it solved my problems except if I were to spin up a new db instance (for instance using a Docker container). Wondering if anyone has any suggestions about how to copy validation across db instances or spin up a new one with it? I will rewrite the application at some point to use Mongoose (or other ORM) but in the mean time I'm looking for a solution to this problem using the validator on a schema.

node.js odata-server mongodb unable to post related entity

I have been working on a node.js odata server based on this example: How to set up a nodejs OData endpoint with odata-server
I have everything working... I can read, update, insert, delete. But I am trying to associate a Journal with a Tasks and I am having problems.
I have tried several different ways outlined here: Operations (OData Version 2.0)
Here is my code:
/* global $data */
require('odata-server');
$data.Class.define("Task", $data.Entity, null, {
Id: { type: "id", key: true, computed: true, nullable: false },
Title: { type: "string", required: true, maxLength: 200 },
Journals: { type: "array", elementType: "Journal"
, inverseProperty: "Task" }
});
$data.Class.define("Journal", $data.Entity, null, {
Id: { type: "id", key: true, computed: true, nullable: false },
Entry: { type: "string" },
DateInserted: { type: "string" },
Task: { type: "object", elementType: "Task" , inverseProperty: "Journals" }
});
$data.EntityContext.extend("obb", {
Tasks: { type: $data.EntitySet, elementType: Task },
Journals: { type: $data.EntitySet, elementType: Journal }
});
$data.createODataServer(obb, '/api-v0.1', 2046, 'localhost');
Question:
Is this feature even available from odata-server what would the post look like to link a Journal to a Task?
I am using fiddler2 and composing a POST I have tried these urls:
//localhost:2046/api-v0.1/Tasks('the-id-of-a-task')/Journals
//localhost:2046/api-v0.1/Tasks('the-id-of-a-task')/Journals/$link
post body's I have tried:
{"Entry":"This is a test"}
{"url":"http://localhost:2046/api-v0.1/Journals('id-of-a-journal-in-the-db')"}
I have even tried to build out and post a Task with journals together and that didn't work.
Any help would be greatly appreciated. Thanks.

Loopback REST findById doesn't work well

I'd like to use findById function through REST API.
I defined "ID" as string all constructed by number.
I try to find by ID, the system seems to recognize it number.
I can't use it when the ID is a big number over "9007199254740992" - max number of integer.
I'd like to use ID just as string.
Please tell me how to solve this problem.
Thank you,
--follow up--
My program is as follow.
Model - sample-model.json
{
"name": "SampleModel",
"base": "PersistedModel",
"idInjection": true,
"properties": {
"id": {
"type": "string",
"id": "true",
"required": true,
"doc": "MODEL ID"
},
"prop1": {
"type": "string",
"required": true
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": []
}
When I access to findById function through REST API, I always get following debug message.
strong-remoting:shared-method - findById - invoke with +11ms [ 9007199254740992, undefined, [Function: callback] ]
strong-remoting:shared-method - findById - result null +25ms
strong-remoting:rest-adapter Invoking rest.after for SampleModel.findById +6ms
express:router restRemoteMethodNotFound : /api/SampleModels/9007199254740993 +143ms
express:router restUrlNotFound : /api/SampleModels/9007199254740993 +8ms
express:router restErrorHandler : /api/SampleModels/9007199254740993 +2ms
strong-remoting:rest-adapter Error in GET /SampleModels/9007199254740993: Error: Unknown "SampleModel" id "9007199254740993".
I resolved my question by myself.
We can define arguments that the remote method accepts using "accepts" option.
Built-in findById function defines as follow at PersistedModel:
accepts: [
{ arg: 'id', type: 'any', description: 'Model id', required: true,
http: {source: 'path'}},
{ arg: 'filter', type: 'object',
description: 'Filter defining fields and include'}
],
When the type is defined any, the id changes to number by HttpContext.coerce function - if the id consists only number chars.
To solve this problem, I defines SampleModel.findByIdCustom and create another remote method as follow:
SampleModel.js
SampleModel.findByIdCustom = function(id, filter, cb) {
SampleModel.findById(id, filter, cb);
}
//Define remote method
SampleModel.remoteMethod(
'findByIdCustom',
{
description: 'Find a model instance by id from the data source.',
accessType: 'READ',
accepts: [
{ arg: 'id', type: 'string', description: 'Model id', required: true,
http: {source: 'path'}},
{ arg: 'filter', type: 'object',
description: 'Filter defining fields and include'}
],
returns: {arg: 'data', type: 'user', root: true},
http: {verb: 'get', path: '/:id'},
rest: {after: SampleModel.convertNullToNotFoundError},
isStatic: true
}
);
//disable built-in remote method
SampleMethod.disableRemoteMethod('findById', true);
Thank you,
Just set idInjection to false (so that loopback doesnt automatically add an id property to your model), then define a property with the following parameters:
{
"idInjection": false,
"properties": {
"id": {
"type": "string",
"id": true,
"generated": true
}
}
}

Body parameters parsing issue with swagger-tool middleware (on expressJS)

With swagger 2.0 spec, i'm describing an 'operation' to add new resources:
A POST request with 3 parameters:
{
name: "username",
in: "header",
description: "New user unsername",
required: true,
type: "string"
},
{
name: "password",
in: "header",
description: "New user password",
required: true,
type: "string"
},
{
name: "pensis",
in: "body",
description: "New pensis to create",
required: true,
schema: {
properties: {
content: {
type: "string",
description: "Content of this pensis stored as markdown text"
}
}
}
}
I setup the POST request with the 3 previous parameters:
username: "Bob",
password: "Yo!",
pensis: {
content: "The content"
}
I send the POST request, and when i parse it using swagger-tool metadata 0.8.6 middleware, i get a strange response :
The value of req.swagger.params.pensis.value provided by this middleware is not:
{ content: 'The content' }
but:
{ content: 'The content',
username: 'ClementVidal',
password: 'r'
}
Do you have any idea about why those 3 parameters are merged together inside the same pensis object ??
Thanks for your help
Clément Vidal

Resources