diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ac6ca0764..3e57d4ba4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -59,7 +59,12 @@ jobs: GOPRIVATE: github.com/phrase/phrase-go run: | npm install + npm run generate.go npm run generate.cli + # Verify the generated CLI compiles before publishing it. Build against + # the freshly generated go client so this does not depend on a released + # phrase-go version that may lag behind the spec. + (cd ./clients/cli && go mod edit -replace github.com/phrase/phrase-go/v4=../go && go build . && go mod edit -dropreplace github.com/phrase/phrase-go/v4) git clone https://$API_TOKEN_GITHUB@github.com/phrase/phrase-cli.git clones/cli &> /dev/null rsync -avI --delete --exclude='.git/' clients/cli/ clones/cli cd clones/cli diff --git a/.github/workflows/test-cli.yml b/.github/workflows/test-cli.yml index 44422f927..88ef6f393 100644 --- a/.github/workflows/test-cli.yml +++ b/.github/workflows/test-cli.yml @@ -2,11 +2,20 @@ # Once we add tests, we should add a step here to run them name: Run CLI Tests on: - push: + pull_request: paths: - - .github/workflows/test-cli.yml + - 'paths/**' + - 'paths.yaml' + - 'schemas/**' + - 'schemas.yaml' + - 'parameters.yaml' + - 'responses.yaml' + - 'headers.yaml' + - 'main.yaml' + - 'openapi-generator/templates/cli/**' - openapi-generator/cli_lang.yaml - 'clients/cli/**' + - .github/workflows/test-cli.yml jobs: test: runs-on: ubuntu-latest diff --git a/openapi-generator/templates/cli/api.handlebars b/openapi-generator/templates/cli/api.handlebars index 18e1c3c0c..4865de418 100644 --- a/openapi-generator/templates/cli/api.handlebars +++ b/openapi-generator/templates/cli/api.handlebars @@ -54,14 +54,14 @@ func init{{{nickname}}}() { {{#allParams~}} {{#required~}} {{#isPrimitiveType~}} - {{#if (eq paramName "file")~}} - {{paramName}}, err := os.Open(params.GetString(helpers.ToSnakeCase("{{paramName}}"))) + {{#isFile~}} + {{paramName}}, err := os.Open(params.GetString(helpers.ToSnakeCase("{{{vendorExtensions.x-export-param-name}}}"))) if err != nil { HandleError(err) } {{else~}} {{paramName}} := params.Get{{{capitalizeFirst dataType}}}(helpers.ToSnakeCase("{{{vendorExtensions.x-export-param-name}}}")) - {{/if}} + {{/isFile}} {{else~}} var {{paramName}} api.{{{dataType}}} if err := json.Unmarshal([]byte(params.GetString("data")), &{{paramName}}); err != nil { @@ -72,9 +72,9 @@ func init{{{nickname}}}() { } {{/isPrimitiveType~}} {{else~}} - {{#if (or (eq paramName "file") (eq paramName "filename"))~}} - if params.IsSet(helpers.ToSnakeCase("{{paramName}}")) { - file, err := os.Open(params.GetString(helpers.ToSnakeCase("{{paramName}}"))) + {{#isFile~}} + if params.IsSet(helpers.ToSnakeCase("{{{vendorExtensions.x-export-param-name}}}")) { + file, err := os.Open(params.GetString(helpers.ToSnakeCase("{{{vendorExtensions.x-export-param-name}}}"))) localVarOptionals.{{{vendorExtensions.x-export-param-name}}} = optional.NewInterface(file) if err != nil { HandleError(err) @@ -111,7 +111,7 @@ func init{{{nickname}}}() { localVarOptionals.{{{vendorExtensions.x-export-param-name}}} = {{#if (eq dataType "[]string")}}{{paramName}}{{else}}optional.NewInterface({{paramName}}){{/if}} } {{/isModel}}{{/isPrimitiveType}} - {{/if}} + {{/isFile}} {{/required~}} {{/allParams~}}