Skip to content

Commit 6d8024e

Browse files
jianyexijianye xi
andauthored
add rules for xms enum (#243)
* add xms-enum rules * change log Co-authored-by: jianye xi <[email protected]>
1 parent 0e49127 commit 6d8024e

File tree

15 files changed

+422
-19
lines changed

15 files changed

+422
-19
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Changelog
2+
## 0.10.0 Released on 2022-09-15
3+
4+
- Added rules: AddedXmsEnum,RemovedXmsEnum,XmsEnumChanged.
25

36
## 0.9.7 Released on 2022-08-15
47

docs/rules/1047.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
### 1047 - XmsEnumChanged
2+
3+
**Description**: Checks whether the x-ms-enum 'name' or 'modelAsString' is changed.
4+
5+
**Cause**: This is considered a breaking change.
6+
7+
**Example**:
8+
1. x-ms-enum modelAsString is changed from 'false' to 'true'.
9+
10+
Old specification
11+
```json5
12+
{
13+
"type": "string",
14+
"description": "Required. Indicates the type of account.",
15+
"enum": [
16+
"Storage",
17+
"BlobStorage"
18+
],
19+
"x-ms-enum": {
20+
"name": "Kind",
21+
"modelAsString": false
22+
}
23+
}
24+
```
25+
26+
New specification
27+
```json5
28+
{
29+
"type": "string",
30+
"description": "Required. Indicates the type of account.",
31+
"enum": [
32+
"Storage",
33+
"BlobStorage"
34+
],
35+
"x-ms-enum": {
36+
"name": "Kind",
37+
"modelAsString": true
38+
}
39+
}
40+
```

docs/rules/1048.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
### 1048 - AddedXmsEnum
2+
3+
**Description**: Checks whether the x-ms-enum is added.
4+
5+
**Cause**: This is considered a breaking change.
6+
7+
**Example**:
8+
1. x-ms-enum is added in the new specification.
9+
10+
Old specification
11+
```json5
12+
{
13+
"type": "string",
14+
"description": "Required. Indicates the type of account.",
15+
"enum": [
16+
"Storage",
17+
"BlobStorage"
18+
],
19+
}
20+
```
21+
22+
New specification
23+
```json5
24+
{
25+
"type": "string",
26+
"description": "Required. Indicates the type of account.",
27+
"enum": [
28+
"Storage",
29+
"BlobStorage"
30+
],
31+
"x-ms-enum": {
32+
"name": "Kind",
33+
"modelAsString": true
34+
}
35+
}
36+
```

docs/rules/1049.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
### 1049 - RemovedXmsEnum
2+
3+
**Description**: Checks whether the x-ms-enum is removed.
4+
5+
**Cause**: This is considered a breaking change.
6+
7+
**Example**:
8+
1. x-ms-enum is removed in the new specification.
9+
10+
Old specification
11+
```json5
12+
{
13+
"type": "string",
14+
"description": "Required. Indicates the type of account.",
15+
"enum": [
16+
"Storage",
17+
"BlobStorage"
18+
],
19+
"x-ms-enum": {
20+
"name": "Kind",
21+
"modelAsString": true
22+
}
23+
}
24+
```
25+
26+
New specification
27+
```json5
28+
{
29+
"type": "string",
30+
"description": "Required. Indicates the type of account.",
31+
"enum": [
32+
"Storage",
33+
"BlobStorage"
34+
],
35+
}
36+
```

openapi-diff/src/modeler/AutoRest.Swagger.Tests/Resource/Swagger/new/operation_check_02.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"swagger": 2.0,
2+
"swagger": "2.0",
33
"info": {
44
"title": "operation_check_01",
55
"version": "1.0"
@@ -9,7 +9,7 @@
99
"paths": {
1010
"/api/Parameters": {
1111
"put": {
12-
"tag": [ "Parameters" ],
12+
"tags": [ "Parameters" ],
1313
"operationId": "Parameters_Put",
1414
"produces": [
1515
"text/plain"
@@ -19,13 +19,13 @@
1919
"name": "database",
2020
"in": "body",
2121
"required": true,
22-
"type": "object",
2322
"schema": { "$ref": "#/definitions/DatabaseRenamed" }
2423
}
25-
]
24+
],
25+
"responses": {}
2626
},
2727
"post": {
28-
"tag": [ "Parameters" ],
28+
"tags": [ "Parameters" ],
2929
"operationId": "Parameters_Post",
3030
"produces": [
3131
"text/plain"
@@ -35,15 +35,15 @@
3535
"name": "registry",
3636
"in": "body",
3737
"required": true,
38-
"type": "object",
3938
"schema": { "$ref": "#/definitions/Register" }
4039
}
41-
]
40+
],
41+
"responses": {}
4242
}
4343
},
4444
"/api/Responses": {
4545
"get": {
46-
"tag": [ "Responses" ],
46+
"tags": [ "Responses" ],
4747
"operationId": "Responses_Get",
4848
"produces": [
4949
"text/plain"
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"swagger": 2.0,
3+
"info": {
4+
"title": "type_changed",
5+
"version": "1.0"
6+
},
7+
"host": "localhost:8000",
8+
"schemes": [ "http", "https" ],
9+
"consumes": [ "text/plain", "text/json" ],
10+
"produces": [ "text/plain" ],
11+
"paths": {
12+
"/api/Parameters": {
13+
"put": {
14+
"tag": [ "Parameters" ],
15+
"operationId": "Parameters_Put",
16+
"produces": [
17+
"text/plain"
18+
],
19+
"parameters": [
20+
{
21+
"name": "database",
22+
"in": "body",
23+
"required": true,
24+
"type": "object",
25+
"schema": { "$ref": "#/definitions/Database" }
26+
}
27+
]
28+
}
29+
}
30+
},
31+
"definitions": {
32+
"Database": {
33+
"properties": {
34+
"a": {
35+
"type": "string",
36+
"readOnly": true,
37+
"description": "This is a system generated property.\nThe _rid value is empty for this operation.",
38+
"x-ms-enum": {
39+
"name": "ResourceIdentityType",
40+
"modelAsString": true
41+
}
42+
},
43+
"b": {
44+
"type": "string",
45+
"enum": [
46+
"A",
47+
"B",
48+
"C"
49+
],
50+
"description": "This property shows the number of databases returned."
51+
}
52+
}
53+
}
54+
}
55+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"swagger": 2.0,
3+
"info": {
4+
"title": "type_changed",
5+
"version": "1.0"
6+
},
7+
"host": "localhost:8000",
8+
"schemes": [ "http", "https" ],
9+
"consumes": [ "text/plain", "text/json" ],
10+
"produces": [ "text/plain" ],
11+
"paths": {
12+
"/api/Parameters": {
13+
"put": {
14+
"tag": [ "Parameters" ],
15+
"operationId": "Parameters_Put",
16+
"produces": [
17+
"text/plain"
18+
],
19+
"parameters": [
20+
{
21+
"name": "database",
22+
"in": "body",
23+
"required": true,
24+
"type": "object",
25+
"schema": { "$ref": "#/definitions/Database" }
26+
}
27+
]
28+
}
29+
}
30+
},
31+
"definitions": {
32+
"Database": {
33+
"properties": {
34+
"a": {
35+
"type": "string",
36+
"readOnly": true,
37+
"description": "This is a system generated property.\nThe _rid value is empty for this operation."
38+
},
39+
"b": {
40+
"type": "string",
41+
"enum": [
42+
"A",
43+
"B",
44+
"C"
45+
],
46+
"x-ms-enum": {
47+
"name": "ResourceIdentityTypeNew",
48+
"modelAsString": false
49+
},
50+
"description": "This property shows the number of databases returned."
51+
}
52+
}
53+
}
54+
}
55+
}

openapi-diff/src/modeler/AutoRest.Swagger.Tests/Resource/Swagger/old/operation_check_02.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"swagger": 2.0,
2+
"swagger": "2.0",
33
"info": {
44
"title": "operation_check_01",
55
"version": "1.0"
@@ -9,7 +9,7 @@
99
"paths": {
1010
"/api/Parameters": {
1111
"put": {
12-
"tag": [ "Parameters" ],
12+
"tags": [ "Parameters" ],
1313
"operationId": "Parameters_Put",
1414
"produces": [
1515
"text/plain"
@@ -19,13 +19,12 @@
1919
"name": "database",
2020
"in": "body",
2121
"required": true,
22-
"type": "object",
2322
"schema": { "$ref": "#/definitions/Database" }
2423
}
25-
]
24+
],"responses": {}
2625
},
2726
"post": {
28-
"tag": [ "Parameters" ],
27+
"tags": [ "Parameters" ],
2928
"operationId": "Parameters_Post",
3029
"produces": [
3130
"text/plain"
@@ -35,15 +34,15 @@
3534
"name": "registry",
3635
"in": "body",
3736
"required": true,
38-
"type": "object",
3937
"schema": { "$ref": "#/definitions/Registry" }
4038
}
41-
]
39+
],
40+
"responses": {}
4241
}
4342
},
4443
"/api/Responses": {
4544
"get": {
46-
"tag": [ "Responses" ],
45+
"tags": [ "Responses" ],
4746
"operationId": "Responses_Get",
4847
"produces": [
4948
"text/plain"
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"swagger": 2.0,
3+
"info": {
4+
"title": "type_changed",
5+
"version": "1.0"
6+
},
7+
"host": "localhost:8000",
8+
"schemes": [ "http", "https" ],
9+
"consumes": [ "text/plain", "text/json" ],
10+
"produces": [ "text/plain" ],
11+
"paths": {
12+
"/api/Parameters": {
13+
"put": {
14+
"tag": [ "Parameters" ],
15+
"operationId": "Parameters_Put",
16+
"produces": [
17+
"text/plain"
18+
],
19+
"parameters": [
20+
{
21+
"name": "database",
22+
"in": "body",
23+
"required": true,
24+
"type": "object",
25+
"schema": { "$ref": "#/definitions/Database" }
26+
}
27+
]
28+
}
29+
}
30+
},
31+
"definitions": {
32+
"Database": {
33+
"properties": {
34+
"a": {
35+
"type": "string",
36+
"readOnly": true,
37+
"description": "This is a system generated property.\nThe _rid value is empty for this operation.",
38+
"enum": [
39+
"A",
40+
"B",
41+
"C"
42+
]
43+
},
44+
"b": {
45+
"type": "string",
46+
"enum": [
47+
"A",
48+
"B",
49+
"C"
50+
],
51+
"x-ms-enum": {
52+
"name": "ResourceIdentityType",
53+
"modelAsString": true
54+
},
55+
"description": "This property shows the number of databases returned."
56+
}
57+
}
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)