PowerAutomate - Custom Connector - dynamic value - rquest header Error - api

I'm trying to read a database with dynamic values and dynamic schema so I don't have to hard code everything.
The instructions for this are fine and there are some examples on the forum.
The request for GetTables works without problems.
But when I want to include it in the next request, so that I get a DropDown field with all tables, the following error appears at the DropDown:
ERROR
Could not retrieve values. The dynamic invocation request failed with error: Unexpected error occurred when calling the ApiHubsRuntime API:
'System.InvalidOperationException: Misused header name. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects.
at System.Net.Http.Headers.HttpHeaders.CheckHeaderName(String name)
at System.Net.Http.Headers.HttpHeaders.Add(String name, String value)
at Microsoft.Azure.ProcessSimple.Data.DataProviders.AzureResourceManagerDataProvider.<>c__DisplayClass52_0`2.<<CallAzureResourceManager>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.WindowsAzure.ResourceStack.Common.Algorithms.AsyncRetry.<Retry>d__3`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Microsoft.Azure.ProcessSimple.Data.DataProviders.AzureResourceManagerDataProvider.<CallAzureResourceManager>d__52`2.MoveNext()'.
Both requests need the access data in the header. I first suspected that this was the problem and created a policy that overwrites the header of each request. No success.
I realize that the error relates to the part of the response header with the api-hub.
RESPONSE HEADER EXAMPLE
begin-tick: 2157897875,
cache-control: no-cache,
content-length: 62841,
content-security-policy: default-src 'self' https: *;script-src 'self' 'unsafe-inline' 'unsafe-eval' https: *;style-src 'self' 'unsafe-inline';img-src 'self' ... [just some URLs there]
content-type: application/json; charset=utf-8,
date: Wed, 10 Aug 2022 21:43:01 GMT,
expires: -1,
pragma: no-cache,
x-ms-apihub-cached-response: true,
x-ms-apihub-obo: true,
x-powered-by: ASP.NET
Accept: application/json
REQUEST HEADER
{
"Authorization": "Bearer eyJ0eXAiOiJKV1QiLB7xtcY",
"ApiIntegrationCode": "123",
"UserName": "456",
"Secret": "789",
"Content-Type": "application/json"
}
I cut the Swagger YAML but here it is
schemes:
- https
consumes: []
produces: []
paths:
/entityinformation:
get:
responses:
default:
description: default
schema:
type: object
properties:
entityDescriptions:
type: array
items:
type: object
properties:
info:
type: object
properties:
name:
type: string
description: name
canCreate:
type: boolean
description: canCreate
canDelete:
type: boolean
description: canDelete
canQuery:
type: boolean
description: canQuery
canUpdate:
type: boolean
description: canUpdate
description: info
description: entityDescriptions
headers:
begin-tick:
description: begin-tick
type: string
cache-control:
description: cache-control
type: string
content-length:
description: content-length
type: string
content-security-policy:
description: content-security-policy
type: string
content-type:
description: content-type
type: string
date:
description: date
type: string
expires:
description: expires
type: string
pragma:
description: pragma
type: string
x-ms-apihub-cached-response:
description: x-ms-apihub-cached-response
type: string
x-ms-apihub-obo:
description: x-ms-apihub-obo
type: string
x-powered-by:
description: x-powered-by
type: string
Accept:
description: Accept
type: string
summary: Get Tables
description: All Database Tables
operationId: GetTables
produces:
- application/json
parameters:
- name: ApiIntegrationCode
in: header
required: true
type: string
default: HardCoded
description: AskDev
x-ms-summary: ApiIntegrationCode
x-ms-visibility: internal
- name: UserName
in: header
required: true
type: string
default: HardCoded
description: AskDev
x-ms-summary: UserName
x-ms-visibility: internal
- name: Secret
in: header
required: true
type: string
default: HardCoded
description: AskDev
x-ms-summary: Secret
x-ms-visibility: internal
- name: Content-Type
in: header
required: true
type: string
default: application/json
x-ms-visibility: internal
/Services/query:
get:
responses:
default:
description: default
schema:
type: object
properties:
items:
type: array
items:
type: object
properties:
id:
type: integer
format: int32
description: id
billingCodeID:
type: integer
format: int32
description: billingCodeID
createDate:
type: string
description: createDate
description: items
pageDetails:
type: object
properties:
count:
type: integer
format: int32
description: count
requestCount:
type: integer
format: int32
description: requestCount
prevPageUrl:
type: string
description: prevPageUrl
nextPageUrl:
type: string
description: nextPageUrl
description: pageDetails
headers:
begin-tick:
description: begin-tick
type: string
cache-control:
description: cache-control
type: string
content-length:
description: content-length
type: string
content-security-policy:
description: content-security-policy
type: string
content-type:
description: content-type
type: string
date:
description: date
type: string
expires:
description: expires
type: string
pragma:
description: pragma
type: string
x-ms-apihub-cached-response:
description: x-ms-apihub-cached-response
type: string
x-ms-apihub-obo:
description: x-ms-apihub-obo
type: string
x-powered-by:
description: x-powered-by
type: string
Accept:
description: Accept
type: string
summary: Services
description: Services
operationId: Services
parameters:
- name: search
in: query
required: false
type: string
x-ms-dynamic-values:
operationId: GetTables
value-path: info/name
value-collection: entityDescriptions
value-title: info/name
parameters:
ApiIntegrationCode:
parameter: ApiIntegrationCode
UserName:
parameter: UserName
Secret:
parameter: Secret
Content-Type: application/json
- name: ApiIntegrationCode
in: header
required: true
type: string
default: HardCoded
description: AskDev
x-ms-summary: ApiIntegrationCode
x-ms-visibility: internal
- name: UserName
in: header
required: true
type: string
default: HardCoded
description: AskDev
x-ms-summary: UserName
x-ms-visibility: internal
- name: Secret
in: header
required: true
type: string
default: HardCoded
description: AskDev
x-ms-summary: Secret
x-ms-visibility: internal
- name: Content-Type
in: header
required: true
type: string
default: application/json
x-ms-visibility: internal
definitions: {}
parameters: {}
responses: {}
securityDefinitions: {}
security: []
tags: []
Thanks for help :)

Related

RAML specification Traits issue

I get this syntax error, while I'm using the traits two times in the resource(one in the header part and another one is in the response part),I'm trying to fix it, but unable to do it.
error is :
is:
-Responsemessage
Hence below is the RAML specification.
#%RAML 1.0
title: RAML_Project
traits:
Responsemessage:
responses:
200:
body:
application/json:
example: {"Statuscode": 1,"message" :"Success done by traits "}
client-id-required:
headers:
client_id:
type: string
required: true
secret_key:
required: true
type: string
/QueryActivity:
get:
is:
- client-id-required
queryParameters:
Fistname:
type: string
required: true
is:
-Responsemessage
/QuerybyEmpid:
get:
body:
application/json:
type: !include dataType.raml
is:
- Responsemessage
-Responsemessage is missing the space between the - and the R. Also you seem to have 2 is: facets in the same resource. Thie - is the YAML array notation. I recommend to instead use the simpler array notation with [] instead:
/QueryActivity:
get:
is: [client-id-required, Responsemessage]
queryParameters:
Fistname:
type: string
required: true

Google API gateway Cors Headers Use options request

After implementing an api gateway in front of my app engine instances I got a problem stating that the request was blocked because of the CORS header. After searching online I found out that API gateway doesn't provide a way to set the CORS policy, however it also "overwrite" the header sent by my single back-end application. Does I need to implement a load balancer to set an additional Header or there is a way to avoid the overwrite?
Example of API:
paths:
"/login":
post:
description: "Login into the service"
operationId: "login"
x-google-backend:
address: https://project-id.oa.r.appspot.com/api/v1/login
produces:
- "application/json"
responses:
200:
description: "Projects retrieved successfully"
schema:
$ref: "#/definitions/access_token"
401:
description: "Wrong password"
schema:
type: "string"
404:
description: "User not exists"
schema:
type: "string"
parameters:
- in: body
name: user
description: The user to create.
schema:
type: object
required:
- userName
properties:
userName:
type: string
firstName:
type: string
lastName:
type: string
After a lot of trials, I found a simpler solution than implementing a load balancer in front of the gateway:
To use the CORS headers provided by the back-end application it is enough to add a OPTIONS request to the API to avoid headers being overwritten. So, given the login API I just need to add the request like this:
paths:
"/login":
post:
description: "Login into the service"
operationId: "login"
x-google-backend:
address: https://project-id.oa.r.appspot.com/api/v1/login
produces:
- "application/json"
responses:
200:
description: "Projects retrieved successfully"
schema:
$ref: "#/definitions/access_token"
401:
description: "Wrong password"
schema:
type: "string"
404:
description: "User not exists"
schema:
type: "string"
parameters:
- in: body
name: user
description: The user to create.
schema:
type: object
required:
- userName
properties:
userName:
type: string
firstName:
type: string
lastName:
type: string
options:
description: "Cors associated request to login"
operationId: "login cors"
x-google-backend:
address: https://project-id.oa.r.appspot.com/api/v1/login
responses:
200:
description: "Allow"
401:
description: "Cors not allowed"

Does a POST method create a new entity, and return the id of that entity, in openapi 3.0.2?

I understand that a POST method in openapi 3.0.2 is supposed to create a new entity, and return the id of that entity. When I add an additional route to GET or DELETE that entity by ID, I get a 404 error. I don't quite know why that might be.
Here are my post and get methods:
/api/globalorderdays:
post:
tags:
- Setup Global Order Days
summary: Allows user to add order days and holidays to multiple
sessions.
requestBody:
required: true
description: put text here
content:
application/json:
schema:
$ref: '#/components/schemas/GlobalOrderSetupInfo'
responses:
201:
description: Created
400:
description: Bad request
401:
description: Unauthorized
/api/globalorderdays/{Id}:
get:
tags:
- Setup Global Order Days
summary: put text here
parameters:
- in: path
name: Id
required: true
description: put text here
schema:
type: integer
example:
responses:
200:
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/GlobalOrderSetupInfo'
400:
description: Bad request
401:
description: Unauthorized
/api/globalorderdays/{Id}:
delete:
tags:
- Setup Global Order Days
summary: Allows user to delete added order days
parameters:
- in: path
name: Id
required: true
description: put text here
schema:
type: integer
example:
responses:
204:
description: Deleted
400:
description: Bad request
401:
description: Unauthorized
Here are the components:
GlobalOrderSetupInfo:
description: 'Put Text Here'
type: object
properties:
Id:
type: integer
nullable: true
AvailableHolidayList:
type: string
nullable: true
SelectedOrderHolidays:
type: string
nullable: true
SelectedHolidays:
type: string
nullable: true
OrderDays:
type: string
nullable: true
NoOrderDays:
type: string
nullable: true
AllSessionList:
uniqueItems: false
type: array
items:
$ref: '#/components/schemas/SessionInfoList'
SessionIdString:
type: string
nullable: true
SessionInfoList:
description: 'Put Text Here'
type: object
properties:
Id:
type: integer
nullable: true
SessionID:
type: integer
nullable: true
Name:
type: string
nullable: true
Type:
type: string
GroupName:
type: string
IsChecked:
type: boolean
default: false
SetupID:
type: string
nullable: true
I expect to be able to retrieve/delete the entity by Id, but I return 404 errors
There are several issues with your spec.
The /api/globalorderdays/{Id} path is repeated several times. This is not valid.
# Incorrect
/api/globalorderdays/{Id}:
get:
...
/api/globalorderdays/{Id}:
delete:
...
Instead, specify the path once and list all of its HTTP methods below it, like so:
/api/globalorderdays/{Id}:
get:
...
delete:
...
Parameter examples are missing the value:
schema:
type: integer
example: # <-----
A missing value in YAML is an equivalent of null, but null is not a valid example for an integer schema. Either add a proper integer example, such as example: 1, or remove the example keyword from those schemas.
Once these issues are fixed, the mocks for GET and DELETE will work properly.

How can I declare the response array type for OpenAPI definition with JAX-RS?

I'm building a REST service with JAX-RS, Microprofile and Payara 5. My method returns an object of type Response. The response itself contains a List of MyClass. The implementation looks like this:
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType;
import org.eclipse.microprofile.openapi.annotations.media.Content;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
#GET
#Path("/{a}/{b}/{c}")
#APIResponse(content = #Content(schema = #Schema(type = SchemaType.ARRAY, implementation = MyClass.class)))
public Response getMyClass(#PathParam("a") String a,
#PathParam("b") String b,
#PathParam("c") String c) {
return Response
.ok()
.entity(new ArrayList<>())
.build();
}
The generated OpenAPI definition looks like this:
/api/translations/{a}/{b}/{c}:
get:
operationId: getMyClass
parameters:
- name: a
in: path
required: true
style: simple
schema:
type: string
- [...]
responses:
default:
description: Default Response.
content:
'*/*':
schema:
type: array
items: {}
As you can see, the definition of MyClass.class is missing in the response type. How can I add that type to the definition? Is the #ApiResponse annotation the correct way to achieve this?
I tested this today with the newest payara 5.191 and it did not worked for me too.
It seems that there is a bug in the current payara implementation, because I checked the example on this page guide-microprofile-openapi
The same implementation has 2 different openapi generations (Payara and OpenLiberty)
Payara:
openapi: 3.0.0
info:
title: Deployed Resources
version: 1.0.0
servers:
- url: https://10.0.0.72:8080/ipma
description: Default Server.
paths:
/resources/server:
get:
summary: List servers.
description: 'Returns all servers '
operationId: getServers
responses:
default:
description: Special description
content:
application/json:
schema:
type: array
/resources/server/{id}:
get:
summary: get server by id.
description: 'return one server with the specified id'
operationId: getServerById
parameters:
- name: id
in: query
style: simple
schema:
type: number
responses:
default:
description: Special description
content:
application/json:
schema:
$ref: '#/components/schemas/Server'
components:
schemas:
Server:
properties:
name:
type: string
example: test
id:
type: number
example: "0"
description: foo
OpenLiberty:
openapi: 3.0.0
info:
title: Deployed APIs
version: 1.0.0
servers:
- url: http://localhost:9080
paths:
/resources/server/{id}:
get:
summary: get server by id.
description: 'return one server with the specified id'
operationId: getServerById
parameters:
- name: id
in: query
schema:
type: integer
format: int64
responses:
default:
description: Special description
content:
application/json:
schema:
$ref: '#/components/schemas/Server'
/resources/server:
get:
summary: List servers.
description: 'Returns all servers '
operationId: getServers
responses:
default:
description: Special description
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Server'
components:
schemas:
Server:
required:
- id
- name
type: object
properties:
id:
type: integer
format: int64
example: 0
name:
type: string
example: test
description: foo

Swagger POST with non-json body

I'm defining a resource that you POST to with a non-JSON body. It's just a string like form parameters. Something like what happens with OAuth:
grant_type=&code=&redirect_uri=
How can I document that on Swagger? Do I have to use formParam format instead of body? Everything I put into body it converts to JSON examples.
TokenRequest:
properties:
grant_type:
type: string
description: OAuth Grant Type
enum:
- authorization_code
- refresh
code:
type: string
description: Authorization Code obtained from /authorize required if grant_type = au
redirect_uri:
type: string
description: Defined Redirect URI Example - https://example.com/callback
refresh_token:
type: string
description: Required if grant_type = refresh
Here is an example on how to document the form data:
post:
tags:
- pet
summary: Updates a pet in the store with form data
description: ''
operationId: updatePetWithForm
consumes:
- application/x-www-form-urlencoded
produces:
- application/xml
- application/json
parameters:
- name: petId
in: path
description: ID of pet that needs to be updated
required: true
type: integer
format: int64
- name: name
in: formData
description: Updated name of the pet
required: false
type: string
- name: status
in: formData
description: Updated status of the pet
required: false
type: string
responses:
'405':
description: Invalid input
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
But in your case, it seems you want to define OAuth setting so please refer to Swagger Spec 2.0 for more information. Here is an example for PetStore:
securityDefinitions:
petstore_auth:
type: oauth2
authorizationUrl: 'http://petstore.swagger.io/api/oauth/dialog'
flow: implicit
scopes:
'write:pets': modify pets in your account
'read:pets': read your pets
api_key:
type: apiKey
name: api_key
in: header