Skip to content

Commit 4437b15

Browse files
authored
Merge pull request #114 from RonasIT/102-add-ability-to-mark-routes-as-deprecated
feat: add ability to mark routes as deprecated.
2 parents a440f4f + 5b59bb6 commit 4437b15

20 files changed

+54
-18
lines changed

readme.md

+3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ passing PHPUnit tests.
6969
/**
7070
* @summary Update user
7171
*
72+
* @deprecated
73+
*
7274
* @description
7375
* This request should be used for updating the user data
7476
*
@@ -166,6 +168,7 @@ You can use the following annotations in your request classes to customize docum
166168
- **@description** - implementation notes
167169
- **@_204** - custom description of response code. You can specify any code as you want.
168170
- **@some_field** - description of the field from the rules method
171+
- **@deprecated** - mark route as deprecated
169172
170173
> ***Note***
171174
>

src/Services/SwaggerService.php

+14
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ class SwaggerService
5757
'int' => 'integer'
5858
];
5959

60+
protected $booleanAnnotations = [
61+
'deprecated'
62+
];
63+
6064
public function __construct(Container $container)
6165
{
6266
$this->openAPIValidator = app(SwaggerSpecValidator::class);
@@ -267,10 +271,16 @@ protected function parseRequest()
267271

268272
$annotations = $this->getClassAnnotations($concreteRequest);
269273

274+
$this->markAsDeprecated($annotations);
270275
$this->saveParameters($concreteRequest, $annotations);
271276
$this->saveDescription($concreteRequest, $annotations);
272277
}
273278

279+
protected function markAsDeprecated(array $annotations)
280+
{
281+
$this->item['deprecated'] = Arr::get($annotations, 'deprecated', false);
282+
}
283+
274284
protected function parseResponse($response)
275285
{
276286
$produceList = $this->data['paths'][$this->uri][$this->method]['produces'];
@@ -782,6 +792,10 @@ protected function getClassAnnotations($class): array
782792
$paramName = str_replace('@', '', array_shift($exploded));
783793
$paramValue = implode(' ', $exploded);
784794

795+
if (in_array($paramName, $this->booleanAnnotations)) {
796+
$paramValue = true;
797+
}
798+
785799
$result[$paramName] = $paramValue;
786800
}
787801
}

tests/fixtures/AutoDocMiddlewareTest/tmp_data_search_roles_request.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
},
7272
"security": [],
7373
"description": "",
74-
"summary": "test"
74+
"summary": "test",
75+
"deprecated": false
7576
}
7677
}
7778
},

tests/fixtures/SwaggerServiceTest/tmp_data_create_user_request.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
},
4040
"security": [],
4141
"description": "",
42-
"summary": "test"
42+
"summary": "test",
43+
"deprecated": false
4344
}
4445
}
4546
},

tests/fixtures/SwaggerServiceTest/tmp_data_get_user_request.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@
6666
},
6767
"security": [],
6868
"description": "",
69-
"summary": "test"
69+
"summary": "test",
70+
"deprecated": false
7071
}
7172
}
7273
},

tests/fixtures/SwaggerServiceTest/tmp_data_post_user_request.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
}
6666
],
6767
"description": "",
68-
"summary": "test"
68+
"summary": "test",
69+
"deprecated": false
6970
}
7071
}
7172
},

tests/fixtures/SwaggerServiceTest/tmp_data_post_user_request_with_object_params.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@
6363
}
6464
],
6565
"description": "",
66-
"summary": "test"
66+
"summary": "test",
67+
"deprecated": false
6768
}
6869
}
6970
},

tests/fixtures/SwaggerServiceTest/tmp_data_put_user_request.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@
7070
}
7171
],
7272
"description": "",
73-
"summary": "test"
73+
"summary": "test",
74+
"deprecated": false
7475
}
7576
}
7677
},

tests/fixtures/SwaggerServiceTest/tmp_data_put_user_request_with_early_generated_doc.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@
7070
}
7171
],
7272
"description": "",
73-
"summary": "test"
73+
"summary": "test",
74+
"deprecated": false
7475
},
7576
"patch": {
7677
"tags": [
@@ -112,7 +113,8 @@
112113
}
113114
],
114115
"description": "",
115-
"summary": "test"
116+
"summary": "test",
117+
"deprecated": false
116118
}
117119
}
118120
},

tests/fixtures/SwaggerServiceTest/tmp_data_search_roles_request.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
},
7272
"security": [],
7373
"description": "",
74-
"summary": "test"
74+
"summary": "test",
75+
"deprecated": false
7576
}
7677
}
7778
},

tests/fixtures/SwaggerServiceTest/tmp_data_search_roles_request_invalid_content_type.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
},
4242
"security": [],
4343
"description": "",
44-
"summary": "test"
44+
"summary": "test",
45+
"deprecated": false
4546
}
4647
}
4748
},

tests/fixtures/SwaggerServiceTest/tmp_data_search_roles_request_jwt_security.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
},
7272
"security": [],
7373
"description": "",
74-
"summary": "test"
74+
"summary": "test",
75+
"deprecated": false
7576
}
7677
}
7778
},

tests/fixtures/SwaggerServiceTest/tmp_data_search_roles_request_laravel_security.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
},
7272
"security": [],
7373
"description": "",
74-
"summary": "test"
74+
"summary": "test",
75+
"deprecated": false
7576
}
7677
}
7778
},

tests/fixtures/SwaggerServiceTest/tmp_data_search_roles_request_pdf.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
},
4747
"security": [],
4848
"description": "",
49-
"summary": "test"
49+
"summary": "test",
50+
"deprecated": false
5051
}
5152
}
5253
},

tests/fixtures/SwaggerServiceTest/tmp_data_search_roles_request_plain_text.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
},
4747
"security": [],
4848
"description": "",
49-
"summary": "test"
49+
"summary": "test",
50+
"deprecated": false
5051
}
5152
}
5253
},

tests/fixtures/SwaggerServiceTest/tmp_data_search_roles_request_with_annotations.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
},
6060
"security": [],
6161
"description": "Description of the request class",
62-
"summary": "Request class to validate input data"
62+
"summary": "Request class to validate input data",
63+
"deprecated": true
6364
}
6465
}
6566
},

tests/fixtures/SwaggerServiceTest/tmp_data_search_roles_request_without_info.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
},
7272
"security": [],
7373
"description": "",
74-
"summary": "test"
74+
"summary": "test",
75+
"deprecated": false
7576
}
7677
}
7778
},

tests/fixtures/SwaggerServiceTest/tmp_data_search_roles_request_without_rule_type.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
},
6060
"security": [],
6161
"description": "",
62-
"summary": "test without rule type"
62+
"summary": "test without rule type",
63+
"deprecated": false
6364
}
6465
}
6566
},

tests/fixtures/SwaggerServiceTest/tmp_data_search_users_request.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@
9696
"security": [],
9797
"description": "",
9898
"summary": "test",
99-
"consumes": []
99+
"consumes": [],
100+
"deprecated": false
100101
}
101102
}
102103
},

tests/support/Mock/TestRequestWithAnnotations.php

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Foundation\Http\FormRequest;
66

77
/**
8+
* @deprecated
89
* @summary Request class to validate input data
910
* @description Description of the request class
1011
* @_200 The operation was completed successfully

0 commit comments

Comments
 (0)