Issue with go-gen templating

@miguelmendoza @ssvaidyanathan - I am exploring this tool and watched your latest demo in mad_in_apis. Using the version 1.0.0

When trying to render a proxy based on the template, i am running into below issues,

  1. VirtualHost - I am not able to set this element in apiproxy.yml - as its complaining with error
$ apigee-go-gen render apiproxy --template ./proxy-template/apiproxy.yml --output ./pxy_auto

Error: unknown node "VirtualHost" found at "Root.ProxyEndpoints.0.ProxyEndpoint(name: default).HTTPProxyConnection"
  1. policies - When we add policies in UI, there is a folder which gets created with all the policies and only the names will be represented in the test.xml, but using this tool the policy itself is getting substituted. Do I have to make the template structure different to achieve this ?

Command

apigee-go-gen render apiproxy --template ./proxy-template/apiproxy.yml --output ./pxy_auto --set PXY_NAME=test --set PXY_PATH=/test

apiproxy.yml

APIProxy:
  .revision: 1
  .name: {{ $.Values.PXY_NAME }}
  Basepaths: {{ $.Values.PXY_PATH }}
  Description: 'Proxy bundle for "{{ $.Values.PXY_NAME }}"'
  DisplayName: {{ $.Values.PXY_NAME }}
  Policies: {{ include "./policies.yml" . | nindent 2 }}
  ProxyEndpoints:
    ProxyEndpoint: default
  Resources: {}
  Spec: {}
  TargetEndpoints:
    TargetEndpoint: default
ProxyEndpoints:
  - ProxyEndpoint:
      .name: default
      Description: {}
      FaultRules: {}
      PreFlow:
        .name: PreFlow
        Request: {}
        Response: {}
      PostFlow:
        .name: PostFlow
        Request: {}
        Response: {}
      Flows: {}
      HTTPProxyConnection:
        BasePath: {{ $.Values.PXY_PATH }}
        Properties: {}
      RouteRule:
        .name: default
        TargetEndpoint: default
TargetEndpoints:
  - TargetEndpoint:
      .name: default
      Description: {}
      FaultRules: {}
      PreFlow:
        .name: PreFlow
        Request:
          Step:
            Name: AM-RemoveHeaders
        Response: {}
      PostFlow:
        .name: PostFlow
        Request: {}
        Response: {}
      Flows: {}
      HTTPTargetConnection:
        Properties: {}
        URL: {{ $.Values.PXY_URL  }}
Resources: []

policies.yml

- AssignMessage:
    .async: false
    .continueOnError: false
    .enabled: true
    .name: AM-RemoveHeaders
    DisplayName: AM-RemoveHeaders
    Remove:
      Headers:
        - Header:
            .name: Authorization
    IgnoreUnresolvedVariables: true
    AssignTo:
      .createNew: false
      .transport: http
      .type: request

Output

File Structure

pxy_auto
  apiproxy
    proxies
      default.xml
    targets
      default.xml
    test.xml

<?xml version="1.0" encoding="UTF-8"?>
<APIProxy revision="1" name="test">
  <DisplayName>test</DisplayName>
  <Description>Proxy bundle for "test"</Description>
  <Spec/>
  <Basepaths>/test</Basepaths>
  <Policies>
    <AssignMessage async="false" continueOnError="false" enabled="true" name="AM-RemoveHeaders">
      <DisplayName>AM-RemoveHeaders</DisplayName>
      <Remove>
        <Headers>
          <Header name="Authorization"/>
        </Headers>
      </Remove>
      <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
      <AssignTo createNew="false" transport="http" type="request"/>
    </AssignMessage>
  </Policies>
  <Resources/>
  <ProxyEndpoints>
    <ProxyEndpoint>default</ProxyEndpoint>
  </ProxyEndpoints>
  <TargetEndpoints>
    <TargetEndpoint>default</TargetEndpoint>
  </TargetEndpoints>
</APIProxy>

I tried the below in the APIProxy section of yml by indenting the Policies to root of YML and its creating the policies folder, but the output of test.xml is missing the policies added to it, unless I explicity mention them.

Can you give a valid apiproxy.yml file ?

apiproxy.yml

APIProxy:
  .revision: 1
  .name: {{ $.Values.PXY_NAME }}
  Basepaths: {{ $.Values.PXY_PATH }}
  Description: 'Proxy bundle for "{{ $.Values.PXY_NAME }}"'
  DisplayName: {{ $.Values.PXY_NAME }}
Policies: {{ include "./policies.yml" . | nindent 2 }}

test.xml

<APIProxy revision="1" name="test">
  <DisplayName>test</DisplayName>
  <Basepaths>/test</Basepaths>
</APIProxy>

@johnwilliams- Try out with the example in the repo –> apigee-go-gen/examples/templates/oas3 at main · apigee/apigee-go-gen · GitHub to learn more about how the template uses the policies and how they are defined in the yaml structure.

This tools currently supports the Apigee X/hybrid proxy bundles only, so VirtualHost is not compatible with this tool. @miguelmendoza - can you clarify if we plan to add that?

@johnwilliams you can run the command in debug mode to see the intermediate YAML that’s rendered using the –-debug=true. Check if the contents of the policies.yaml is embedded correctly into the main the template.

adding VirtualHost would be of great help for the OPDK users as I could see the flexibility this tool can bring when running in a pipeline for creating a base proxy for further development.