Skip to content

Commit

Permalink
fix: only-major-api-versions allows versions larger than v9
Browse files Browse the repository at this point in the history
Previously http://localhost:3000/v51 would have failed.

fixes #2
  • Loading branch information
philsturgeon committed Dec 30, 2022
1 parent 19f05ac commit 1e23c22
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 124 deletions.
135 changes: 76 additions & 59 deletions __tests__/one-api-version-per-document.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,73 @@ import { DiagnosticSeverity } from "@stoplight/types";
import testRule from "./__helpers__/helper";

testRule("one-api-version-per-document", [
{
name: "valid case: different environments same version",
document: {
openapi: "3.1.0",
info: { version: "1.0" },
servers: [
{
name: "valid case: different environments same version",
document: {
openapi: "3.1.0",
info: { version: "1.0" },
servers: [
{
url: 'https://dev.example.org/v1'
url: "https://dev.example.org/v1",
},
{
url: 'https://prod.example.org/v1'
url: "https://prod.example.org/v1",
},
],
},
errors: [],
},
},
errors: [],
},

{
name: "valid case: weird versions but they're the same",
document: {
openapi: "3.1.0",
info: { version: "1.0" },
servers: [
{
name: "valid case: large versions are ok",
document: {
openapi: "3.1.0",
info: { version: "1.0" },
servers: [
{
url: 'https://dev.example.org/version123.56'
url: "https://dev.example.org/v51",
},
{
url: 'https://prod.example.org/version123.56'
url: "https://prod.example.org/v51",
},
],
},
errors: [],
},
},
errors: [],
},

{
name: "valid case: port numbers are ok",
document: {
openapi: "3.1.0",
info: { version: "1.0" },
servers: [
{
name: "valid case: weird versions but they're the same",
document: {
openapi: "3.1.0",
info: { version: "1.0" },
servers: [
{
url: 'https://dev.example.org:3000/version123'
url: "https://dev.example.org/version123.56",
},
{
url: 'https://prod.example.org/version123'
url: "https://prod.example.org/version123.56",
},
],
},
errors: [],
},
},
errors: [],
},

{
name: "valid case: port numbers are ok",
document: {
openapi: "3.1.0",
info: { version: "1.0" },
servers: [
{
url: "https://dev.example.org:3000/version123",
},
{
url: "https://prod.example.org/version123",
},
],
},
errors: [],
},

{
name: "valid case: no versions",
Expand All @@ -78,7 +95,7 @@ testRule("one-api-version-per-document", [
},
errors: [],
},

{
name: "valid case: empty servers defined",
document: {
Expand All @@ -88,7 +105,7 @@ testRule("one-api-version-per-document", [
},
errors: [],
},

{
name: "valid case: weird servers defined",
document: {
Expand All @@ -99,27 +116,27 @@ testRule("one-api-version-per-document", [
errors: [],
},

{
name: "invalid: multiple versions in directory",
document: {
openapi: "3.1.0",
info: { version: "1.0" },
servers: [
{
name: "invalid: multiple versions in directory",
document: {
openapi: "3.1.0",
info: { version: "1.0" },
servers: [
{
url: 'https://example.org/v1',
url: "https://example.org/v1",
},
{
url: 'https://example.org/v2',
url: "https://example.org/v2",
},
],
},
errors: [
{
message: "Multiple API versions detected in Server URLs.",
path: ["servers"],
severity: DiagnosticSeverity.Error,
},
],
errors: [
{
message: "Multiple API versions detected in Server URLs.",
path: ["servers"],
severity: DiagnosticSeverity.Error,
},
],
},

{
Expand All @@ -129,10 +146,10 @@ testRule("one-api-version-per-document", [
info: { version: "1.0" },
servers: [
{
url: 'https://v1.example.org/',
url: "https://v1.example.org/",
},
{
url: 'https://v2.example.org/',
url: "https://v2.example.org/",
},
],
},
Expand All @@ -143,7 +160,7 @@ testRule("one-api-version-per-document", [
severity: DiagnosticSeverity.Error,
},
],
},
},

{
name: "invalid: multiple versions in middle subdir",
Expand All @@ -152,10 +169,10 @@ testRule("one-api-version-per-document", [
info: { version: "1.0" },
servers: [
{
url: 'https://api.v1.example.org/',
url: "https://api.v1.example.org/",
},
{
url: 'https://api.v2.example.org/',
url: "https://api.v2.example.org/",
},
],
},
Expand All @@ -166,7 +183,7 @@ testRule("one-api-version-per-document", [
severity: DiagnosticSeverity.Error,
},
],
},
},

{
name: "invalid: multiple weird versions",
Expand All @@ -175,10 +192,10 @@ testRule("one-api-version-per-document", [
info: { version: "1.0" },
servers: [
{
url: 'https://12345.example.org/',
url: "https://12345.example.org/",
},
{
url: 'https://example.org/v23456',
url: "https://example.org/v23456",
},
],
},
Expand All @@ -189,5 +206,5 @@ testRule("one-api-version-per-document", [
severity: DiagnosticSeverity.Error,
},
],
},
},
]);
101 changes: 52 additions & 49 deletions __tests__/only-major-api-versions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,68 @@ import { DiagnosticSeverity } from "@stoplight/types";
import testRule from "./__helpers__/helper";

testRule("only-major-api-versions", [
{
name: "valid case: major is ok",
document: {
openapi: "3.1.0",
info: { version: "1.0" },
servers: [
{
name: "valid case: major is ok",
document: {
openapi: "3.1.0",
info: { version: "1.0" },
servers: [
{
url: 'https://api.example.org/v1'
url: "https://api.example.org/v1",
},
],
},
errors: [],
},
},
errors: [],
},

{
name: "valid case: port numbers are ok",
document: {
openapi: "3.1.0",
info: { version: "1.0" },
servers: [
name: "valid case: large versions are ok",
document: {
openapi: "3.1.0",
info: { version: "1.0" },
servers: [
{
url: 'http://localhost:3000'
url: "http://localhost/v51",
},
],
},
errors: [],
},

// {
// name: "valid case: large versions are ok",
// document: {
// openapi: "3.1.0",
// info: { version: "1.0" },
// servers: [
// {
// url: 'http://localhost/v51'
// },
// ],
// },
// errors: [],
// },
},
errors: [],
},

{
name: "invalid case: minor is unnecessary",
document: {
openapi: "3.1.0",
info: { version: "1.0" },
servers: [
{
name: "valid case: port numbers are ok",
document: {
openapi: "3.1.0",
info: { version: "1.0" },
servers: [
{
url: 'https://api.example.org/v1.2'
url: "http://localhost:3000",
},
],
},
},
errors: [],
},

{
name: "invalid case: minor is unnecessary",
document: {
openapi: "3.1.0",
info: { version: "1.0" },
servers: [
{
url: "https://api.example.org/v1.2",
},
],
},
errors: [
{
message: "Version numbers SHOULD contain major only, no minor or patch.",
message:
"Version numbers SHOULD contain major only, no minor or patch.",
path: ["servers", "0", "url"],
severity: DiagnosticSeverity.Warning,
},
],
},
},

{
name: "invalid case: patch is massively wasteful",
Expand All @@ -71,18 +72,19 @@ testRule("only-major-api-versions", [
info: { version: "1.0" },
servers: [
{
url: 'https://api.example.org/v1.2.3'
url: "https://api.example.org/v1.2.3",
},
],
},
errors: [
{
message: "Version numbers SHOULD contain major only, no minor or patch.",
message:
"Version numbers SHOULD contain major only, no minor or patch.",
path: ["servers", "0", "url"],
severity: DiagnosticSeverity.Warning,
},
],
},
},

{
name: "invalid case: subdomain versions too",
Expand All @@ -91,16 +93,17 @@ testRule("only-major-api-versions", [
info: { version: "1.0" },
servers: [
{
url: 'https://v1.2.3.example.org/'
url: "https://v1.2.3.example.org/",
},
],
},
errors: [
{
message: "Version numbers SHOULD contain major only, no minor or patch.",
message:
"Version numbers SHOULD contain major only, no minor or patch.",
path: ["servers", "0", "url"],
severity: DiagnosticSeverity.Warning,
},
],
},
},
]);
Loading

0 comments on commit 1e23c22

Please sign in to comment.