Skip to content

Commit

Permalink
Merge pull request #114 from RonasIT/102-add-ability-to-mark-routes-a…
Browse files Browse the repository at this point in the history
…s-deprecated

feat: add ability to mark routes as deprecated.
  • Loading branch information
DenTray committed Nov 14, 2023
2 parents a440f4f + 5b59bb6 commit 4437b15
Show file tree
Hide file tree
Showing 20 changed files with 54 additions and 18 deletions.
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ passing PHPUnit tests.
/**
* @summary Update user
*
* @deprecated
*
* @description
* This request should be used for updating the user data
*
Expand Down Expand Up @@ -166,6 +168,7 @@ You can use the following annotations in your request classes to customize docum
- **@description** - implementation notes
- **@_204** - custom description of response code. You can specify any code as you want.
- **@some_field** - description of the field from the rules method
- **@deprecated** - mark route as deprecated

> ***Note***
>
Expand Down
14 changes: 14 additions & 0 deletions src/Services/SwaggerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class SwaggerService
'int' => 'integer'
];

protected $booleanAnnotations = [
'deprecated'
];

public function __construct(Container $container)
{
$this->openAPIValidator = app(SwaggerSpecValidator::class);
Expand Down Expand Up @@ -267,10 +271,16 @@ protected function parseRequest()

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

$this->markAsDeprecated($annotations);
$this->saveParameters($concreteRequest, $annotations);
$this->saveDescription($concreteRequest, $annotations);
}

protected function markAsDeprecated(array $annotations)
{
$this->item['deprecated'] = Arr::get($annotations, 'deprecated', false);
}

protected function parseResponse($response)
{
$produceList = $this->data['paths'][$this->uri][$this->method]['produces'];
Expand Down Expand Up @@ -782,6 +792,10 @@ protected function getClassAnnotations($class): array
$paramName = str_replace('@', '', array_shift($exploded));
$paramValue = implode(' ', $exploded);

if (in_array($paramName, $this->booleanAnnotations)) {
$paramValue = true;
}

$result[$paramName] = $paramValue;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
},
"security": [],
"description": "",
"summary": "test"
"summary": "test",
"deprecated": false
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
},
"security": [],
"description": "",
"summary": "test"
"summary": "test",
"deprecated": false
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
},
"security": [],
"description": "",
"summary": "test"
"summary": "test",
"deprecated": false
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
}
],
"description": "",
"summary": "test"
"summary": "test",
"deprecated": false
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
}
],
"description": "",
"summary": "test"
"summary": "test",
"deprecated": false
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
}
],
"description": "",
"summary": "test"
"summary": "test",
"deprecated": false
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
}
],
"description": "",
"summary": "test"
"summary": "test",
"deprecated": false
},
"patch": {
"tags": [
Expand Down Expand Up @@ -112,7 +113,8 @@
}
],
"description": "",
"summary": "test"
"summary": "test",
"deprecated": false
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
},
"security": [],
"description": "",
"summary": "test"
"summary": "test",
"deprecated": false
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
},
"security": [],
"description": "",
"summary": "test"
"summary": "test",
"deprecated": false
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
},
"security": [],
"description": "",
"summary": "test"
"summary": "test",
"deprecated": false
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
},
"security": [],
"description": "",
"summary": "test"
"summary": "test",
"deprecated": false
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
},
"security": [],
"description": "",
"summary": "test"
"summary": "test",
"deprecated": false
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
},
"security": [],
"description": "",
"summary": "test"
"summary": "test",
"deprecated": false
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
},
"security": [],
"description": "Description of the request class",
"summary": "Request class to validate input data"
"summary": "Request class to validate input data",
"deprecated": true
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
},
"security": [],
"description": "",
"summary": "test"
"summary": "test",
"deprecated": false
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
},
"security": [],
"description": "",
"summary": "test without rule type"
"summary": "test without rule type",
"deprecated": false
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@
"security": [],
"description": "",
"summary": "test",
"consumes": []
"consumes": [],
"deprecated": false
}
}
},
Expand Down
1 change: 1 addition & 0 deletions tests/support/Mock/TestRequestWithAnnotations.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Foundation\Http\FormRequest;

/**
* @deprecated
* @summary Request class to validate input data
* @description Description of the request class
* @_200 The operation was completed successfully
Expand Down

0 comments on commit 4437b15

Please sign in to comment.