Skip to content

Commit 2eb5632

Browse files
committed
feat(nx-plugin): enhance OpenAPI and Swagger spec comparison utilities
- Introduce functions to standardize OpenAPI and Swagger specs, including version detection and conversion. - Implement `removeExamples` function to clean up specs before comparison, ensuring accurate diff results. - Add comprehensive tests for new functionality, covering various scenarios for OpenAPI 3.1 and Swagger 2.0 specs. - Update existing comparison logic to utilize standardized specs for improved accuracy.
1 parent f856938 commit 2eb5632

14 files changed

+1433
-2
lines changed

packages/nx-plugin/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,15 @@
5151
"@hey-api/json-schema-ref-parser": "1.0.5",
5252
"@hey-api/openapi-ts": "workspace:*",
5353
"@nx/devkit": "20.8.1",
54-
"latest-version": "9.0.0",
5554
"api-smart-diff": "^1.0.6",
55+
"latest-version": "9.0.0",
56+
"swagger2openapi": "^7.0.8",
5657
"tslib": "2.8.1",
5758
"xcurl": "2.1.2"
5859
},
5960
"devDependencies": {
6061
"@config/vite-base": "workspace:*",
62+
"@types/swagger2openapi": "^7.0.4",
6163
"typescript": "5.8.3",
6264
"vitest": "3.1.1"
6365
},
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
{
2+
"openapi": "3.1.0",
3+
"info": {
4+
"title": "Test API 3.1",
5+
"version": "1.0.0",
6+
"description": "A test API for testing OpenAPI 3.1 spec comparison"
7+
},
8+
"servers": [
9+
{
10+
"url": "https://api.example.com/v1",
11+
"description": "Production server"
12+
}
13+
],
14+
"security": [
15+
{
16+
"apiKey": []
17+
}
18+
],
19+
"paths": {
20+
"/users": {
21+
"get": {
22+
"summary": "Get all users",
23+
"parameters": [
24+
{
25+
"name": "limit",
26+
"in": "query",
27+
"description": "Number of users to return",
28+
"required": false,
29+
"schema": {
30+
"type": "integer",
31+
"default": 10
32+
}
33+
}
34+
],
35+
"responses": {
36+
"200": {
37+
"description": "Successful response",
38+
"content": {
39+
"application/json": {
40+
"schema": {
41+
"type": "array",
42+
"items": {
43+
"$ref": "#/components/schemas/User"
44+
}
45+
},
46+
"example": [
47+
{
48+
"id": 1,
49+
"name": "John Doe"
50+
}
51+
]
52+
}
53+
}
54+
}
55+
}
56+
}
57+
}
58+
},
59+
"webhooks": {
60+
"newUser": {
61+
"post": {
62+
"summary": "New user webhook",
63+
"requestBody": {
64+
"content": {
65+
"application/json": {
66+
"schema": {
67+
"$ref": "#/components/schemas/User"
68+
}
69+
}
70+
}
71+
},
72+
"responses": {
73+
"200": {
74+
"description": "Webhook processed successfully"
75+
}
76+
}
77+
}
78+
}
79+
},
80+
"components": {
81+
"schemas": {
82+
"User": {
83+
"type": "object",
84+
"properties": {
85+
"id": {
86+
"type": "integer"
87+
},
88+
"name": {
89+
"type": "string"
90+
},
91+
"tags": {
92+
"type": "array",
93+
"prefixItems": [{ "type": "string" }, { "type": "number" }],
94+
"items": { "type": "string" }
95+
}
96+
}
97+
}
98+
},
99+
"securitySchemes": {
100+
"apiKey": {
101+
"type": "apiKey",
102+
"name": "X-API-Key",
103+
"in": "header"
104+
}
105+
}
106+
}
107+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"swagger": "2.0",
3+
"info": {
4+
"title": "Test API Swagger",
5+
"version": "1.0.0",
6+
"description": "A test API for testing Swagger 2.0 spec comparison"
7+
},
8+
"host": "api.example.com",
9+
"basePath": "/v1",
10+
"schemes": ["https"],
11+
"securityDefinitions": {
12+
"apiKey": {
13+
"type": "apiKey",
14+
"name": "X-API-Key",
15+
"in": "header"
16+
}
17+
},
18+
"security": [
19+
{
20+
"apiKey": []
21+
}
22+
],
23+
"paths": {
24+
"/users": {
25+
"get": {
26+
"summary": "Get all users",
27+
"parameters": [
28+
{
29+
"name": "limit",
30+
"in": "query",
31+
"description": "Number of users to return",
32+
"required": false,
33+
"type": "integer",
34+
"default": 10
35+
}
36+
],
37+
"responses": {
38+
"200": {
39+
"description": "Successful response",
40+
"schema": {
41+
"type": "array",
42+
"items": {
43+
"$ref": "#/definitions/User"
44+
}
45+
},
46+
"examples": {
47+
"application/json": [
48+
{
49+
"id": 1,
50+
"name": "John Doe"
51+
}
52+
]
53+
}
54+
}
55+
}
56+
}
57+
}
58+
},
59+
"definitions": {
60+
"User": {
61+
"type": "object",
62+
"properties": {
63+
"id": {
64+
"type": "integer"
65+
},
66+
"name": {
67+
"type": "string"
68+
},
69+
"tags": {
70+
"type": "array",
71+
"items": {
72+
"type": "string"
73+
}
74+
}
75+
}
76+
}
77+
}
78+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"swagger": "2.0",
3+
"info": {
4+
"title": "Test API Swagger",
5+
"version": "1.0.0",
6+
"description": "A test API for testing Swagger 2.0 spec comparison"
7+
},
8+
"host": "api.example.com",
9+
"basePath": "/v1",
10+
"schemes": ["https"],
11+
"securityDefinitions": {
12+
"apiKey": {
13+
"type": "apiKey",
14+
"name": "X-API-Key",
15+
"in": "header"
16+
}
17+
},
18+
"security": [
19+
{
20+
"apiKey": []
21+
}
22+
],
23+
"paths": {
24+
"/users": {
25+
"get": {
26+
"summary": "Get all users",
27+
"parameters": [
28+
{
29+
"name": "limit",
30+
"in": "query",
31+
"description": "Number of users to return",
32+
"required": false,
33+
"type": "integer",
34+
"default": 10
35+
}
36+
],
37+
"responses": {
38+
"200": {
39+
"description": "Successful response",
40+
"schema": {
41+
"type": "array",
42+
"items": {
43+
"$ref": "#/definitions/User"
44+
}
45+
},
46+
"examples": {
47+
"application/json": [
48+
{
49+
"id": 1,
50+
"name": "John Doe"
51+
}
52+
]
53+
}
54+
}
55+
}
56+
}
57+
}
58+
},
59+
"definitions": {
60+
"User": {
61+
"type": "object",
62+
"properties": {
63+
"id": {
64+
"type": "integer",
65+
"format": "int64"
66+
},
67+
"name": {
68+
"type": "string",
69+
"minLength": 1
70+
},
71+
"tags": {
72+
"type": "array",
73+
"items": {
74+
"type": "string"
75+
},
76+
"minItems": 1
77+
}
78+
}
79+
}
80+
}
81+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
{
2+
"swagger": "2.0",
3+
"info": {
4+
"title": "Test API Swagger",
5+
"version": "1.0.0",
6+
"description": "A test API for testing Swagger 2.0 spec comparison"
7+
},
8+
"host": "api.example.com",
9+
"basePath": "/v1",
10+
"schemes": ["https"],
11+
"securityDefinitions": {
12+
"apiKey": {
13+
"type": "apiKey",
14+
"name": "X-API-Key",
15+
"in": "header"
16+
}
17+
},
18+
"security": [
19+
{
20+
"apiKey": []
21+
}
22+
],
23+
"paths": {
24+
"/users": {
25+
"get": {
26+
"summary": "Get all users",
27+
"parameters": [
28+
{
29+
"name": "limit",
30+
"in": "query",
31+
"description": "Number of users to return",
32+
"required": false,
33+
"type": "integer",
34+
"default": 10
35+
}
36+
],
37+
"responses": {
38+
"200": {
39+
"description": "Successful response",
40+
"schema": {
41+
"type": "array",
42+
"items": {
43+
"$ref": "#/definitions/User"
44+
}
45+
},
46+
"examples": {
47+
"application/json": [
48+
{
49+
"id": 1,
50+
"name": "John Doe"
51+
}
52+
]
53+
}
54+
}
55+
}
56+
},
57+
"post": {
58+
"summary": "Create a new user",
59+
"parameters": [
60+
{
61+
"name": "user",
62+
"in": "body",
63+
"description": "User object to create",
64+
"required": true,
65+
"schema": {
66+
"$ref": "#/definitions/User"
67+
}
68+
}
69+
],
70+
"responses": {
71+
"201": {
72+
"description": "User created successfully",
73+
"schema": {
74+
"$ref": "#/definitions/User"
75+
}
76+
}
77+
}
78+
}
79+
}
80+
},
81+
"definitions": {
82+
"User": {
83+
"type": "object",
84+
"properties": {
85+
"id": {
86+
"type": "integer"
87+
},
88+
"name": {
89+
"type": "string"
90+
},
91+
"tags": {
92+
"type": "array",
93+
"items": {
94+
"type": "string"
95+
}
96+
}
97+
}
98+
}
99+
}
100+
}

0 commit comments

Comments
 (0)