After extensive experimentation, I have discovered a solution to a persistent issue that had previously confounded me for over a year. I have documented this solution to ensure that it is not forgotten.

Despite various attempts, I was unable to create a custom connector that would accept multiple data types. The connector consistently failed when I attempted to use it. Although I had developed multiple responses with string and int32 types, the issue persisted. This was particularly problematic because saving multiple custom connectors in a single solution with the same base path was impossible.

However, I recalled that OpenAPI 3 support was scheduled to be added to Power Automate in September 2022. I decided to leverage this by creating an OpenAPI file, as OpenAPI 3 supports “oneOff” to address my issue.

To begin, I copied the Swagger from the custom connector and imported it into Swagger Hub. Then, I converted it to OpenAPI 3 and added the configuration for “oneOff,” which is demonstrated in the code below:

statistics:
  type: array
  items:
    type: object
    properties:
      type:
        type: string
        description: type
      value:
        "oneOf": [
                  {
                  "type": "integer",
                  "format": "int32"
                  },
                  {
                  "type": "string"
                  }
              ]
        nullable: true
        description: value
  description: statistics

After exporting the OpenAPI 3 definition file, I created a new custom connector in Power Automate using the exported OpenAPI 3 file. Power Automate now accepts OpenAPI 3 definition files and compiles them back to Swagger 2.

This approach essentially modified the default response by including the “allOf” command, which was the specific feature I needed. The converted Swagger 2 is demonstrated below:

## default response 

statistics:
    description: statistics
    type: array
    items:
    type: object
    properties:
        type:
        description: type
        type: string
        value:
        description: value
        allOf:
            - format: int32
            type: integer

## '100' response

statistics:
    description: statistics
    type: array
    items:
    type: object
    properties:
        type:
        description: type
        type: string
        value:
        description: value
        type: string

This modification allowed the connector to function without fail, as it was now capable of accepting string, int32, or null in the value property. The only caveat is that in Power Apps, the value is untyped, although it is easily converted.

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *