Skip to content

Commit 38cecc9

Browse files
CLOUDP-329067: Fix atlascli examples
1 parent 269b92c commit 38cecc9

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

tools/cli/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ toolchain go1.24.0
66

77
require (
88
github.com/getkin/kin-openapi v0.132.0
9+
github.com/iancoleman/strcase v0.3.0
910
github.com/oasdiff/oasdiff v1.11.4
1011
github.com/spf13/afero v1.14.0
1112
github.com/spf13/cobra v1.9.1

tools/cli/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
1515
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
1616
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
1717
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
18+
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
19+
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
1820
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
1921
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
2022
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=

tools/cli/internal/openapi/filter/code_sample.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"time"
2525

2626
"github.com/getkin/kin-openapi/openapi3"
27+
"github.com/iancoleman/strcase"
2728
"github.com/mongodb/openapi/tools/cli/internal/apiversion"
2829
"golang.org/x/text/cases"
2930
"golang.org/x/text/language"
@@ -147,10 +148,12 @@ func apiVersion(version *apiversion.APIVersion) string {
147148
}
148149

149150
func newAtlasCliCodeSamplesForOperation(op *openapi3.Operation) codeSample {
151+
tag := strcase.ToLowerCamel(op.Tags[0])
152+
operationID := strcase.ToLowerCamel(op.OperationID)
150153
return codeSample{
151154
Lang: "cURL",
152155
Label: "Atlas CLI",
153-
Source: "atlas api " + op.OperationID + " --help",
156+
Source: "atlas api " + tag + " " + operationID + " --help",
154157
}
155158
}
156159

tools/cli/internal/openapi/filter/code_sample_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func TestCodeSampleFilter(t *testing.T) {
8181
{
8282
Lang: "cURL",
8383
Label: "Atlas CLI",
84-
Source: "atlas api testOperationID --help",
84+
Source: "atlas api testTag testOperationId --help",
8585
},
8686
{
8787
Lang: "go",
@@ -127,6 +127,7 @@ func TestCodeSampleFilter(t *testing.T) {
127127
Get: &openapi3.Operation{
128128
OperationID: "testOperationID",
129129
Summary: "testSummary",
130+
Tags: []string{"TestTag"},
130131
Responses: openapi3.NewResponses(openapi3.WithName("200", &openapi3.Response{
131132
Content: openapi3.Content{
132133
"application/vnd.atlas.preview+json": {
@@ -150,6 +151,7 @@ func TestCodeSampleFilter(t *testing.T) {
150151
Get: &openapi3.Operation{
151152
OperationID: "testOperationID",
152153
Summary: "testSummary",
154+
Tags: []string{"TestTag"},
153155
Responses: openapi3.NewResponses(openapi3.WithName("200", &openapi3.Response{
154156
Content: openapi3.Content{
155157
"application/vnd.atlas.preview+json": {
@@ -168,7 +170,7 @@ func TestCodeSampleFilter(t *testing.T) {
168170
{
169171
Lang: "cURL",
170172
Label: "Atlas CLI",
171-
Source: "atlas api testOperationID --help",
173+
Source: "atlas api testTag testOperationId --help",
172174
},
173175
{
174176
Lang: "cURL",
@@ -196,6 +198,7 @@ func TestCodeSampleFilter(t *testing.T) {
196198
Get: &openapi3.Operation{
197199
OperationID: "testOperationID",
198200
Summary: "testSummary",
201+
Tags: []string{"TestTag"},
199202
Responses: openapi3.NewResponses(openapi3.WithName("200", &openapi3.Response{
200203
Content: openapi3.Content{
201204
"application/vnd.atlas.2025-01-01.upcoming+json": {
@@ -219,6 +222,7 @@ func TestCodeSampleFilter(t *testing.T) {
219222
Get: &openapi3.Operation{
220223
OperationID: "testOperationID",
221224
Summary: "testSummary",
225+
Tags: []string{"TestTag"},
222226
Responses: openapi3.NewResponses(openapi3.WithName("200", &openapi3.Response{
223227
Content: openapi3.Content{
224228
"application/vnd.atlas.2025-01-01.upcoming+json": {
@@ -237,7 +241,7 @@ func TestCodeSampleFilter(t *testing.T) {
237241
{
238242
Lang: "cURL",
239243
Label: "Atlas CLI",
240-
Source: "atlas api testOperationID --help",
244+
Source: "atlas api testTag testOperationId --help",
241245
},
242246
{
243247
Lang: "cURL",
@@ -308,7 +312,7 @@ func TestCodeSampleFilter(t *testing.T) {
308312
{
309313
Lang: "cURL",
310314
Label: "Atlas CLI",
311-
Source: "atlas api testOperationID --help",
315+
Source: "atlas api testTag testOperationId --help",
312316
},
313317
{
314318
Lang: "go",

0 commit comments

Comments
 (0)