Skip to content

Commit 24158d2

Browse files
authored
feat: add valid forward spec version detection (#3360)
Refs swagger-api/apidom#1741
1 parent dfd2fb4 commit 24158d2

File tree

3 files changed

+69
-67
lines changed

3 files changed

+69
-67
lines changed

package-lock.json

Lines changed: 59 additions & 59 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@
6464
"@mui/material": "^5.9.3",
6565
"@primer/octicons-react": "^17.4.0",
6666
"@swagger-api/apidom-core": "^0.40.0",
67-
"@swagger-api/apidom-ls": "^0.40.1",
67+
"@swagger-api/apidom-ls": "^0.40.3",
6868
"@swagger-api/apidom-ns-api-design-systems": "^0.40.0",
6969
"@swagger-api/apidom-parser-adapter-api-design-systems-json": "^0.40.0",
7070
"@swagger-api/apidom-parser-adapter-api-design-systems-yaml": "^0.40.0",
71-
"@swagger-api/apidom-parser-adapter-asyncapi-json-2": "^0.40.0",
72-
"@swagger-api/apidom-parser-adapter-asyncapi-yaml-2": "^0.40.0",
73-
"@swagger-api/apidom-parser-adapter-openapi-json-3-1": "^0.40.0",
74-
"@swagger-api/apidom-parser-adapter-openapi-yaml-3-1": "^0.40.0",
71+
"@swagger-api/apidom-parser-adapter-asyncapi-json-2": "^0.40.3",
72+
"@swagger-api/apidom-parser-adapter-asyncapi-yaml-2": "^0.40.3",
73+
"@swagger-api/apidom-parser-adapter-openapi-json-3-1": "^0.40.3",
74+
"@swagger-api/apidom-parser-adapter-openapi-yaml-3-1": "^0.40.3",
7575
"axios": "^0.27.2",
7676
"classnames": "^2.3.1",
7777
"deepmerge": "^4.2.2",

src/plugins/editor-content-type/actions.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,17 @@ export const detectContentType = (content) => {
8686
}
8787

8888
const openApi2YAMLMatch = content.match(
89-
/(?<YAML>^(["']?)swagger\2\s*:\s*(["']?)(?<version_yaml>2\.0)\3)|(?<JSON>"asyncapi"\s*:\s*"(?<version_json>2\.0)")/m
89+
/(?<YAML>^(["']?)swagger\2\s*:\s*(["']?)(?<version_yaml>2\.0)\3(?:\s+|$))|(?<JSON>"asyncapi"\s*:\s*"(?<version_json>2\.0)")/m
9090
);
9191
if (openApi2YAMLMatch !== null && fn.isValidYAMLObject(content)) {
9292
const contentType = 'application/vnd.oai.openapi+yaml;version=2.0';
9393

9494
return editorActions.detectContentTypeSuccess({ contentType, content, requestId });
9595
}
9696

97-
const openApi30xJSONMatch = content.match(/"openapi"\s*:\s*"(?<version_json>3\.0\.\d+)"/);
97+
const openApi30xJSONMatch = content.match(
98+
/"openapi"\s*:\s*"(?<version_json>3\.0\.(?:[1-9]\d*|0))"/
99+
);
98100
if (openApi30xJSONMatch !== null && fn.isValidJSONObject(content)) {
99101
const { groups } = openApi30xJSONMatch;
100102
const version = groups?.version_json;
@@ -104,7 +106,7 @@ export const detectContentType = (content) => {
104106
}
105107

106108
const openApi30xYAMLMatch = content.match(
107-
/(?<YAML>^(["']?)openapi\2\s*:\s*(["']?)(?<version_yaml>3\.0\.\d+)\3)|(?<JSON>"openapi"\s*:\s*"(?<version_json>3\.0\.\d+)")/m
109+
/(?<YAML>^(["']?)openapi\2\s*:\s*(["']?)(?<version_yaml>3\.0\.(?:[1-9]\d*|0))\3(?:\s+|$))|(?<JSON>"openapi"\s*:\s*"(?<version_json>3\.0\.(?:[1-9]\d*|0))")/m
108110
);
109111
if (openApi30xYAMLMatch !== null && fn.isValidYAMLObject(content)) {
110112
const { groups } = openApi30xYAMLMatch;

0 commit comments

Comments
 (0)