Skip to content

Rendering template fails when providing resources in relative path #32

@SeboRei

Description

@SeboRei

Observed Behavior

Platforms: Windows 11 x64, Ubuntu 24.04

➜  apigee-go-gen render apiproxy --template apiproxy.yaml --output ./out
Error: open ./jsc/addAccessTokenCookie.js: no such file or directory

Resources are given relative to template file:

Resources:
  - Resource:
      Type: jsc
      Path: ./jsc/addAccessTokenCookie.js

Template file was generated by loading a ZIP via the CLI.
Same behavior is observed for OAS.

Steps to reproduce:

  1. Load API Proxy zip bundle:
apigee-go-gen transform apiproxy-to-yaml \
--input ./bundle.zip \
--output ./apiproxy.yaml
  1. Execute template render
apigee-go-gen render apiproxy --template apiproxy.yaml --output ./out
  1. Observe error.

Suspected cause

Render model.go

Function "GenerateBundle" copies the rendered YAML into a temporary directory which does not contain any of the resources:

func GenerateBundle(createModelFunc func(string) (v1.Model, error), cFlags *CommonFlags, validate bool, dryRun string, debug bool) error {
	var err error

	bundleOutputFile := cFlags.OutputFile

	//create a temporary location for rendering into
	tmpDir, err := os.MkdirTemp("", "render-*")
	if err != nil {
		return errors.New(err)
	}

	// render the template to a temporary location
        // THIS PRODUCES WRONG OUTCOME
	cFlags.OutputFile = flags.String(filepath.Join(tmpDir, "model.yaml"))
	err = RenderGenericTemplate(cFlags, false)
	if err != nil {
		return errors.New(err)
	}

Debug state in Line 60:

Image

Note the discrepancy between TemplateFile and OutputFile

Suggested solution

Render the model.yaml into the current base directory and remove it after the bundle is generated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions