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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 14 additions & 0 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 2 additions & 1 deletion
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
},

0 commit comments

Comments
 (0)