Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 3 additions & 3 deletions tools/cli/internal/apiversion/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ type APIVersion struct {
}

const (
dateFormat = "2006-01-02"
dateFormat = "2006-01-02"
previewDate = "3000-01-01"
)

var contentPattern = regexp.MustCompile(`application/vnd\.atlas\.((\d{4})-(\d{2})-(\d{2})|preview)\+(.+)`)
Expand All @@ -57,7 +58,6 @@ func (v *APIVersion) newVersion(version string, date time.Time) {
v.versionDate = date

if IsPreviewStabilityLevel(version) {
v.versionDate = time.Now().AddDate(10, 0, 0) // set preview date to the future
v.stabilityVersion = PreviewStabilityLevel
}
}
Expand Down Expand Up @@ -119,7 +119,7 @@ func WithFullContent(contentType string, contentValue *openapi3.MediaType) Optio

func DateFromVersion(version string) (time.Time, error) {
if IsPreviewStabilityLevel(version) {
return time.Now(), nil
return time.Parse(dateFormat, previewDate)
}
return time.Parse(dateFormat, version)
}
Expand Down
12 changes: 12 additions & 0 deletions tools/cli/internal/apiversion/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,18 @@ func TestApiVersion_GreaterThan(t *testing.T) {
version2: "2023-01-02",
expected: false,
},
{
name: "not greater",
version1: "preview",
version2: "preview",
expected: false,
},
{
name: "not greater",
version1: "private-preview-charts-dashboards",
version2: "private-preview-charts-dashboards",
expected: false,
},
}

for _, tt := range testCases {
Expand Down
2 changes: 1 addition & 1 deletion tools/cli/internal/openapi/filter/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/getkin/kin-openapi/openapi3"
)

// Filter: OperationsFilter is a filter that removes the x-xgen-owner-team extension from operations
// OperationsFilter is a filter that removes the x-xgen-owner-team extension from operations
// and moves the x-sunset extension to the operation level.
type OperationsFilter struct {
oas *openapi3.T
Expand Down
3 changes: 2 additions & 1 deletion tools/cli/internal/openapi/filter/versioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package filter

import (
Expand All @@ -21,7 +22,7 @@ import (
"github.com/mongodb/openapi/tools/cli/internal/apiversion"
)

// Filter: VersioningFilter is a filter that modifies the OpenAPI spec by removing operations and responses
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Filter: notation is used so that we can auto gen all the filters

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I was getting a warning in my IDE that this is not golang standard. I will revert the changes

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted my changes. thanks!

// VersioningFilter is a filter that modifies the OpenAPI spec by removing operations and responses
// that are not supported by the target version.
type VersioningFilter struct {
oas *openapi3.T
Expand Down
Loading