Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tools/cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ toolchain go1.24.0

require (
github.com/getkin/kin-openapi v0.132.0
github.com/iancoleman/strcase v0.3.0
github.com/oasdiff/oasdiff v1.11.4
github.com/spf13/afero v1.14.0
github.com/spf13/cobra v1.9.1
Expand Down
2 changes: 2 additions & 0 deletions tools/cli/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
Expand Down
5 changes: 4 additions & 1 deletion tools/cli/internal/openapi/filter/code_sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"time"

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

func newAtlasCliCodeSamplesForOperation(op *openapi3.Operation) codeSample {
tag := strcase.ToLowerCamel(op.Tags[0])
operationID := strcase.ToLowerCamel(op.OperationID)
return codeSample{
Lang: "cURL",
Label: "Atlas CLI",
Source: "atlas api " + op.OperationID + " --help",
Source: "atlas api " + tag + " " + operationID + " --help",
}
}

Expand Down
12 changes: 8 additions & 4 deletions tools/cli/internal/openapi/filter/code_sample_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestCodeSampleFilter(t *testing.T) {
{
Lang: "cURL",
Label: "Atlas CLI",
Source: "atlas api testOperationID --help",
Source: "atlas api testTag testOperationId --help",
},
{
Lang: "go",
Expand Down Expand Up @@ -127,6 +127,7 @@ func TestCodeSampleFilter(t *testing.T) {
Get: &openapi3.Operation{
OperationID: "testOperationID",
Summary: "testSummary",
Tags: []string{"TestTag"},
Responses: openapi3.NewResponses(openapi3.WithName("200", &openapi3.Response{
Content: openapi3.Content{
"application/vnd.atlas.preview+json": {
Expand All @@ -150,6 +151,7 @@ func TestCodeSampleFilter(t *testing.T) {
Get: &openapi3.Operation{
OperationID: "testOperationID",
Summary: "testSummary",
Tags: []string{"TestTag"},
Responses: openapi3.NewResponses(openapi3.WithName("200", &openapi3.Response{
Content: openapi3.Content{
"application/vnd.atlas.preview+json": {
Expand All @@ -168,7 +170,7 @@ func TestCodeSampleFilter(t *testing.T) {
{
Lang: "cURL",
Label: "Atlas CLI",
Source: "atlas api testOperationID --help",
Source: "atlas api testTag testOperationId --help",
},
{
Lang: "cURL",
Expand Down Expand Up @@ -196,6 +198,7 @@ func TestCodeSampleFilter(t *testing.T) {
Get: &openapi3.Operation{
OperationID: "testOperationID",
Summary: "testSummary",
Tags: []string{"TestTag"},
Responses: openapi3.NewResponses(openapi3.WithName("200", &openapi3.Response{
Content: openapi3.Content{
"application/vnd.atlas.2025-01-01.upcoming+json": {
Expand All @@ -219,6 +222,7 @@ func TestCodeSampleFilter(t *testing.T) {
Get: &openapi3.Operation{
OperationID: "testOperationID",
Summary: "testSummary",
Tags: []string{"TestTag"},
Responses: openapi3.NewResponses(openapi3.WithName("200", &openapi3.Response{
Content: openapi3.Content{
"application/vnd.atlas.2025-01-01.upcoming+json": {
Expand All @@ -237,7 +241,7 @@ func TestCodeSampleFilter(t *testing.T) {
{
Lang: "cURL",
Label: "Atlas CLI",
Source: "atlas api testOperationID --help",
Source: "atlas api testTag testOperationId --help",
},
{
Lang: "cURL",
Expand Down Expand Up @@ -308,7 +312,7 @@ func TestCodeSampleFilter(t *testing.T) {
{
Lang: "cURL",
Label: "Atlas CLI",
Source: "atlas api testOperationID --help",
Source: "atlas api testTag testOperationId --help",
},
{
Lang: "go",
Expand Down
Loading
Loading