How to read API Proxy resources into a Flow Variable

Today I found out about a very cool new feature in Apigee X. It's now possible to dynamically read the contents of a resource such as an OpenAPI spec, or even a JavaScript file within the resources folder in your API Proxy.

So, here is how you do it. First you read the contents of the resource into a flow variable using AssignMessage/AssignVariable as show below:

<AssignMessage name='AM-From-ResourceURL'>
  <AssignVariable>
    <Name>new-flow-variable</Name>
    <ResourceURL>oas://my-spec.yaml</ResourceURL>
  </AssignVariable>
</AssignMessage>

Then, you can use the new-flow-variable wherever you want in the API Proxy.

This is useful for example if you want to expose the contents of an OpenAPI Spec as REST Resource (e.g. /myproxy/spec) in your API Proxy without having to duplicate the contents in multiple policies. See example below:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage continueOnError="false" enabled="true" name="AM-GetOAS">
    <DisplayName>AM-GetOAS</DisplayName>
    <Properties/>
    <AssignVariable>
        <Name>oas-content</Name>
        <ResourceURL>oas://openapi3_0.yaml</ResourceURL>
    </AssignVariable>
    <Set>
        <StatusCode>200</StatusCode>
        <Payload>{oas-content}</Payload>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="response"/>
</AssignMessage>

Hope this helps, and thanks to @dchiesa1 for making this feature happen!

 

4 3 249
3 REPLIES 3

Indeed very nice feature! Any plans on making this available in Apigee Edge (both Private Cloud & SAAS)? 

Thanks!

KR
Piet

There is no plan to make this feature available in Apigee Edge, as far as I know. 

Hello! Is there any option to extract an specific attribute from oas and asssign it into a variable?