Skip to content

Commit

Permalink
feat: allow inplace upgrades from beta to ga
Browse files Browse the repository at this point in the history
- these upgrades are allowed after the pivot date
  • Loading branch information
tinygrasshopper committed Feb 4, 2025
1 parent 112a79a commit 7336100
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 3 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion end-end-tests/api-standards/test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ OPTIC_DIFF_CONTEXT=$CONTEXT ${COMPARE} \
--check
assert_ok

### Can move from beta to ga in place
OPTIC_DIFF_CONTEXT=$CONTEXT ${COMPARE} \
$HERE/resources/thing/2021-11-10/000-baseline.yaml \
$HERE/resources/thing/2021-11-10/001-stability-change.yaml \
--check
assert_ok


# These should fail

### Invalid naming convention
Expand Down Expand Up @@ -134,7 +142,6 @@ OPTIC_DIFF_CONTEXT=$CONTEXT_BETA ${COMPARE} \
assert_err

FAILING_CHANGES="\
$HERE/resources/thing/2021-11-10/001-fail-stability-change.yaml \
$HERE/resources/thing/2021-11-10/002-fail-singleton-no-pagination.yaml \
$HERE/resources/thing/2021-11-10/002-fail-singleton.yaml \
$HERE/resources/thing/2021-11-10/002-fail-paginated-post.yaml \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,84 @@ exports[`lifecycle rules stability an invalid stability is provided 1`] = `
]
`;

exports[`lifecycle rules stability beta can be promoted to ga in place 1`] = `
[
{
"change": {
"location": {
"conceptualLocation": {},
"conceptualPath": [],
"jsonPath": "",
"kind": "specification",
},
"value": {
"info": {
"title": "Empty",
"version": "0.0.0",
},
"openapi": "3.1.0",
"x-snyk-api-stability": "ga",
},
},
"condition": undefined,
"docsLink": "https://github.com/snyk/sweater-comb/blob/main/docs/principles/version.md#stability-levels",
"error": undefined,
"exempted": false,
"expected": undefined,
"isMust": true,
"isShould": false,
"name": "resource stability",
"passed": true,
"received": undefined,
"severity": 2,
"type": "requirement",
"where": "specification",
},
{
"change": {
"changeType": "changed",
"changed": {
"after": {
"info": {
"title": "Empty",
"version": "0.0.0",
},
"openapi": "3.1.0",
"x-snyk-api-stability": "ga",
},
"before": {
"info": {
"title": "Empty",
"version": "0.0.0",
},
"openapi": "3.1.0",
"x-snyk-api-stability": "beta",
},
},
"location": {
"conceptualLocation": {},
"conceptualPath": [],
"jsonPath": "",
"kind": "specification",
},
},
"condition": undefined,
"docsLink": "https://github.com/snyk/sweater-comb/blob/main/docs/principles/version.md#promoting-stability-of-a-resource-over-time",
"error": undefined,
"exempted": false,
"expected": undefined,
"isMust": true,
"isShould": false,
"name": "resource stability transitions",
"passed": true,
"received": undefined,
"severity": 2,
"type": "changed",
"where": "specification",
},
]
`;

exports[`lifecycle rules stability can not change from any stability but wip 1`] = `
[
{
Expand Down
22 changes: 22 additions & 0 deletions src/rulesets/rest/2022-05-25/__tests__/lifecycle-rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@ describe("lifecycle rules", () => {
expect(results).toMatchSnapshot();
});

test("beta can be promoted to ga in place", async () => {
const ruleRunner = new RuleRunner([lifecycleRuleset]);
const ruleInputs = {
...TestHelpers.createRuleInputs(
{
...baseJson,
[stabilityKey]: "beta",
} as OpenAPIV3.Document,
{
...baseJson,
[stabilityKey]: "ga",
} as OpenAPIV3.Document,
),
context,
};
const results = await ruleRunner.runRulesWithFacts(ruleInputs);

expect(results.length).toBeGreaterThan(0);
expect(results.every((result) => result.passed)).toBe(true);
expect(results).toMatchSnapshot();
});

test("can not change from any stability but wip", async () => {
const ruleRunner = new RuleRunner([lifecycleRuleset]);
const ruleInputs = {
Expand Down
3 changes: 3 additions & 0 deletions src/rulesets/rest/2022-05-25/lifecycle-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ const stabilityTransitions = new SpecificationRule({
// A resource can go from wip to anything, so no need to check.
if (beforeStability === "wip") return;

// in place upgrades from beta to ga are allowed
if (beforeStability === "beta" && afterStability === "ga") return;

if (beforeStability !== afterStability) {
throw new RuleError({
message: `stability transition from '${before}' to '${after}' not allowed`,
Expand Down

0 comments on commit 7336100

Please sign in to comment.