From 791e38b2d3dcb852ab098f43434adee38d1d334c Mon Sep 17 00:00:00 2001 From: Eddie Chayes <35413716+eddiechayes@users.noreply.github.com> Date: Fri, 5 Apr 2024 14:29:30 -0700 Subject: [PATCH] docs(changeset): fix publishing for go sdk (#679) * docs(changeset): fix publishing for go sdk * run integration tests --- generator/konfig-dash/.changeset/unlucky-games-work.md | 5 +++++ .../packages/konfig-cli/src/commands/generate.ts | 8 ++++++++ .../packages/konfig-cli/src/commands/publish.ts | 3 ++- .../java/org/openapitools/codegen/DefaultGenerator.java | 5 ++++- .../src/main/resources/go/go.mod.mustache | 4 ++-- .../konfig-integration-tests/sdks/go-carbon/go/go.mod | 2 +- .../konfig-integration-tests/sdks/go-decentro/go/go.mod | 2 +- .../sdks/go-newscatcher/README.md | 2 +- .../sdks/go-newscatcher/go/configuration.go | 2 +- .../sdks/go-newscatcher/go/go.mod | 2 +- .../sdks/go-newscatcher/konfig.yaml | 2 +- .../sdks/splitit/go-splitit/go/go.mod | 2 +- 12 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 generator/konfig-dash/.changeset/unlucky-games-work.md diff --git a/generator/konfig-dash/.changeset/unlucky-games-work.md b/generator/konfig-dash/.changeset/unlucky-games-work.md new file mode 100644 index 0000000000..ff16fe172c --- /dev/null +++ b/generator/konfig-dash/.changeset/unlucky-games-work.md @@ -0,0 +1,5 @@ +--- +'konfig-cli': patch +--- + +fix publishing for go sdk diff --git a/generator/konfig-dash/packages/konfig-cli/src/commands/generate.ts b/generator/konfig-dash/packages/konfig-cli/src/commands/generate.ts index 004af77b0a..734964d7e5 100644 --- a/generator/konfig-dash/packages/konfig-cli/src/commands/generate.ts +++ b/generator/konfig-dash/packages/konfig-cli/src/commands/generate.ts @@ -1603,6 +1603,14 @@ function constructGoGenerationRequest({ ) } + const majorVersion = restOfConfig.version.split('.')[0] + const outputParentDir = path.basename(restOfConfig.outputDirectory) + if (parseInt(majorVersion) > 1 && outputParentDir !== `v${majorVersion}`) { + CliUx.ux.error( + `Go SDK output directory must end with the directory "v${majorVersion}". See https://go.dev/blog/v2-go-modules.` + ) + } + const requestGo: GenerateRequestBodyType['generators']['go'] = { files: createTemplateFilesObject(files, 'go', configDir), ...handleReadmeSnippet({ config: restOfConfig }), diff --git a/generator/konfig-dash/packages/konfig-cli/src/commands/publish.ts b/generator/konfig-dash/packages/konfig-cli/src/commands/publish.ts index 234ce69063..870cd72f77 100644 --- a/generator/konfig-dash/packages/konfig-cli/src/commands/publish.ts +++ b/generator/konfig-dash/packages/konfig-cli/src/commands/publish.ts @@ -137,6 +137,7 @@ const publishScripts = { gitHost: string skipTag?: boolean }) => { + const majorVersion = version.split('.')[0] return [ ...(await generateGitTagCommands({ version, @@ -145,7 +146,7 @@ const publishScripts = { isSubmodule, skipTag, })), - `GOPROXY=proxy.golang.org go list -m ${gitHost}/${owner}/${repo}@v${version}`, + `GOPROXY=proxy.golang.org go list -m ${gitHost}/${owner}/${repo}/v${majorVersion}@v${version}`, ] }, npm: async ({ diff --git a/generator/konfig-generator-api/src/main/java/org/openapitools/codegen/DefaultGenerator.java b/generator/konfig-generator-api/src/main/java/org/openapitools/codegen/DefaultGenerator.java index f50c35ce0d..a67a820cf9 100644 --- a/generator/konfig-generator-api/src/main/java/org/openapitools/codegen/DefaultGenerator.java +++ b/generator/konfig-generator-api/src/main/java/org/openapitools/codegen/DefaultGenerator.java @@ -1020,8 +1020,11 @@ Map buildSupportFileBundle(List allOperations, Li if (openAPI.getInfo() != null) bundle.put("infoExtensions", openAPI.getInfo().getExtensions()); - if (bundle.get("packageVersion") != null) + if (bundle.get("packageVersion") != null) { bundle.put("packageVersionWithoutDashes", ((String) bundle.get("packageVersion")).replaceAll("-", "")); + bundle.put("packageMajorVersion", ((String) bundle.get("packageVersion")).split("\\.")[0]); + bundle.put("isMajorVersionGreaterThanOne", Integer.parseInt((String) bundle.get("packageMajorVersion")) > 1); + } if (bundle.get("npmVersion") != null) bundle.put("npmVersionWithoutDashes", ((String) bundle.get("npmVersion")).replaceAll("-", "")); if (bundle.get("podVersion") != null) diff --git a/generator/konfig-generator-api/src/main/resources/go/go.mod.mustache b/generator/konfig-generator-api/src/main/resources/go/go.mod.mustache index 0742938265..142fc93c1a 100644 --- a/generator/konfig-generator-api/src/main/resources/go/go.mod.mustache +++ b/generator/konfig-generator-api/src/main/resources/go/go.mod.mustache @@ -1,4 +1,4 @@ -module {{gitHost}}/{{gitUserId}}/{{gitRepoId}}{{#isGoSubmodule}}/{{packageName}}{{/isGoSubmodule}} +module {{gitHost}}/{{gitUserId}}/{{gitRepoId}}{{#isMajorVersionGreaterThanOne}}/v{{packageMajorVersion}}{{/isMajorVersionGreaterThanOne}} go 1.13 @@ -8,4 +8,4 @@ require ( {{#withAWSV4Signature}} github.com/aws/aws-sdk-go v1.34.14 {{/withAWSV4Signature}} -) +) \ No newline at end of file diff --git a/generator/konfig-integration-tests/sdks/go-carbon/go/go.mod b/generator/konfig-integration-tests/sdks/go-carbon/go/go.mod index 077ec4802f..56c2dea531 100644 --- a/generator/konfig-integration-tests/sdks/go-carbon/go/go.mod +++ b/generator/konfig-integration-tests/sdks/go-carbon/go/go.mod @@ -5,4 +5,4 @@ go 1.13 require ( github.com/stretchr/testify v1.4.0 golang.org/x/oauth2 v0.0.0-20210323180902-22b0adad7558 -) +) \ No newline at end of file diff --git a/generator/konfig-integration-tests/sdks/go-decentro/go/go.mod b/generator/konfig-integration-tests/sdks/go-decentro/go/go.mod index 67bca2042c..ea7feca096 100644 --- a/generator/konfig-integration-tests/sdks/go-decentro/go/go.mod +++ b/generator/konfig-integration-tests/sdks/go-decentro/go/go.mod @@ -5,4 +5,4 @@ go 1.13 require ( github.com/stretchr/testify v1.4.0 golang.org/x/oauth2 v0.0.0-20210323180902-22b0adad7558 -) +) \ No newline at end of file diff --git a/generator/konfig-integration-tests/sdks/go-newscatcher/README.md b/generator/konfig-integration-tests/sdks/go-newscatcher/README.md index 01a467e7ea..35cfee1c30 100644 --- a/generator/konfig-integration-tests/sdks/go-newscatcher/README.md +++ b/generator/konfig-integration-tests/sdks/go-newscatcher/README.md @@ -2,4 +2,4 @@ |Language|Version|Package Manager|README|Source| |-|-|-|-|-| -|Go|6.0.0|[pkg.go.dev](https://pkg.go.dev/github.com/konfig-dev/newscatcher-go-sdk/go)|[README](https://github.com/konfig-dev/newscatcher-go-sdk/tree/HEAD/go#readme)|[Source](https://github.com/konfig-dev/newscatcher-go-sdk/tree/HEAD/go)| \ No newline at end of file +|Go|1.0.0|[pkg.go.dev](https://pkg.go.dev/github.com/konfig-dev/newscatcher-go-sdk/go)|[README](https://github.com/konfig-dev/newscatcher-go-sdk/tree/HEAD/go#readme)|[Source](https://github.com/konfig-dev/newscatcher-go-sdk/tree/HEAD/go)| \ No newline at end of file diff --git a/generator/konfig-integration-tests/sdks/go-newscatcher/go/configuration.go b/generator/konfig-integration-tests/sdks/go-newscatcher/go/configuration.go index ca35c8bd82..60a9502939 100644 --- a/generator/konfig-integration-tests/sdks/go-newscatcher/go/configuration.go +++ b/generator/konfig-integration-tests/sdks/go-newscatcher/go/configuration.go @@ -105,7 +105,7 @@ type Configuration struct { func NewConfiguration() *Configuration { cfg := &Configuration{ DefaultHeader: make(map[string]string), - UserAgent: "Konfig/6.0.0/go", + UserAgent: "Konfig/1.0.0/go", TokenUrl: "", Debug: false, Context: context.Background(), diff --git a/generator/konfig-integration-tests/sdks/go-newscatcher/go/go.mod b/generator/konfig-integration-tests/sdks/go-newscatcher/go/go.mod index 8eb07f891f..ac87b659ac 100644 --- a/generator/konfig-integration-tests/sdks/go-newscatcher/go/go.mod +++ b/generator/konfig-integration-tests/sdks/go-newscatcher/go/go.mod @@ -5,4 +5,4 @@ go 1.13 require ( github.com/stretchr/testify v1.4.0 golang.org/x/oauth2 v0.0.0-20210323180902-22b0adad7558 -) +) \ No newline at end of file diff --git a/generator/konfig-integration-tests/sdks/go-newscatcher/konfig.yaml b/generator/konfig-integration-tests/sdks/go-newscatcher/konfig.yaml index a8f2c235b3..eee1c5f90f 100644 --- a/generator/konfig-integration-tests/sdks/go-newscatcher/konfig.yaml +++ b/generator/konfig-integration-tests/sdks/go-newscatcher/konfig.yaml @@ -20,7 +20,7 @@ fixConfig: href='https://newscatcherapi.com'>https://newscatcherapi.com generators: go: - version: 6.0.0 + version: 1.0.0 packageName: newscatcherapi outputDirectory: go git: diff --git a/generator/konfig-integration-tests/sdks/splitit/go-splitit/go/go.mod b/generator/konfig-integration-tests/sdks/splitit/go-splitit/go/go.mod index 52bfdf367e..c85161d103 100644 --- a/generator/konfig-integration-tests/sdks/splitit/go-splitit/go/go.mod +++ b/generator/konfig-integration-tests/sdks/splitit/go-splitit/go/go.mod @@ -5,4 +5,4 @@ go 1.13 require ( github.com/stretchr/testify v1.4.0 golang.org/x/oauth2 v0.0.0-20210323180902-22b0adad7558 -) +) \ No newline at end of file