Skip to content

Commit 715e761

Browse files
Change
1 parent 48148ed commit 715e761

34 files changed

+92
-2365
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"symfony/dependency-injection": "5.*",
2828
"symfony/filesystem": "5.*",
2929
"symfony/config": "5.*",
30-
"negreanucalin/sparkle-dto": "~1.1",
30+
"negreanucalin/sparkle-dto": "~0.1",
3131
"ext-json": "*"
3232
}
3333
}

composer.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readme.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,25 @@ Just manual-functional testing for now provided in folder `demo_files` by runni
1010

1111
* Define mandatory and optional parameters by adding demo files
1212
* Validate route params
13-
1. If FILE and JSON or named POST variables present throw error (only 1 of them)
14-
2. Parameter type validation (from list:uri,post, get)
15-
3. GET cannot have JSON and FILE
16-
4. Route validation:
17-
I. If parameter present in route check if it exists in list
18-
II. If parameter present check if uri
13+
1. If FILE and JSON or named POST variables present throw error (only 1 of them)
14+
2. Parameter type validation (from list:uri,post, get)
15+
3. GET cannot have JSON and FILE
16+
4. Route validation:
17+
I. If parameter present in route check if it exists in list
18+
II. If parameter present check if uri
1919
* Parses `*.yaml` files and generates a flat document containing the application's documentation
20-
* Notes
21-
* No filename convention required
22-
* You can organize however you want
23-
* A sugestion would be to have multiple files:
24-
* `_project.yaml` - Project description
25-
* `_categories.yaml` - Menu items and sub-items
26-
* `user_route.yaml` - Route example
27-
* `another_route.yaml` - Route example
20+
*
21+
### Notes
22+
* No filename convention required
23+
* You can organize however you want
24+
* A sugestion would be to have multiple files:
25+
* `_project.yaml` - Project description
26+
* `_categories.yaml` - Menu items and sub-items
27+
* `user_route.yaml` - Route example
28+
* `another_route.yaml` - Route example
2829
2930
* Project
30-
* File name `_my_awesome_project.yaml`
31+
* File name `_my_awesome_project.yaml`
3132
```
3233
project:
3334
name: My Awesome project
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace MultidocParser\Exceptions;
4+
5+
class NoCategoryRouteException extends \Exception
6+
{
7+
const MESSAGE = 'Missing category for route:';
8+
9+
public function __construct($name)
10+
{
11+
parent::__construct(self::MESSAGE.' '. $name);
12+
}
13+
}

src/Normalizers/DataNormalizer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace MultidocParser\Normalizers;
44

5+
use MultidocParser\Exceptions\NoCategoryRouteException;
56
use MultidocParser\Exceptions\UndefinedTemplateException;
67
use MultidocParser\Services\FileContentParserService;
78
use Symfony\Component\Finder\SplFileInfo;
@@ -27,6 +28,7 @@ public function hydrateFilesToRouteDefinitionList(SplFileInfo $file, $routeDefin
2728
/**
2829
* @param array[] $routeDefinitionList
2930
* @return array[]
31+
* @throws NoCategoryRouteException
3032
*/
3133
public function formatTagsAndStatusAndHeaders($routeDefinitionList)
3234
{
@@ -55,6 +57,9 @@ public function formatTagsAndStatusAndHeaders($routeDefinitionList)
5557
}
5658
unset($routeDefinitionList[$routeIndex][FileContentParserService::STATUS_PLURAL_LIST]);
5759
}
60+
if (!isset($routeDefinitionList[$routeIndex]['category'])) {
61+
throw new NoCategoryRouteException($routeDefinitionList[$routeIndex]['name']);
62+
}
5863
$routeDefinitionList[$routeIndex]['categoryId'] = $routeDefinitionList[$routeIndex]['category'];
5964
unset($routeDefinitionList[$routeIndex]['category']);
6065
}

src/Services/OutputFileService.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace MultidocParser\Services;
34

45
use MultidocParser\DTO\CategoryDto;
@@ -22,15 +23,15 @@ class OutputFileService
2223
*/
2324
private $categoryRenderer;
2425

25-
private $outputDirectory = __DIR__.'\..\\';
26+
private $outputDirectory = __DIR__ . '\..\\';
2627

2728
private $projectFileName = 'project.json';
2829

2930
private $categoryListFileName = 'categories.json';
3031

3132

3233
public function __construct(
33-
Filesystem $fileService,
34+
Filesystem $fileService,
3435
CategoryRenderer $categoryRenderer
3536
)
3637
{
@@ -40,7 +41,7 @@ public function __construct(
4041

4142
public function prepareOutputFolder($outputPath)
4243
{
43-
if(empty($outputPath)) {
44+
if (empty($outputPath)) {
4445
$outputPath = self::DEFAULT_OUTPUT_PATH;
4546
}
4647
$this->outputDirectory = $outputPath;
@@ -56,12 +57,12 @@ public function exportProjectEntityToOutputFolder(ProjectDto $project)
5657
{
5758
$this->removeCurrentFilesInOutput();
5859
$this->fileService->dumpFile(
59-
$this->outputDirectory.DIRECTORY_SEPARATOR.$this->projectFileName,
60+
$this->outputDirectory . DIRECTORY_SEPARATOR . $this->projectFileName,
6061
json_encode($project, JSON_PRETTY_PRINT)
6162
);
6263

6364
$this->fileService->dumpFile(
64-
$this->outputDirectory.DIRECTORY_SEPARATOR.$this->categoryListFileName,
65+
$this->outputDirectory . DIRECTORY_SEPARATOR . $this->categoryListFileName,
6566
json_encode(
6667
$this->categoryRenderer->renderList($project->categories), JSON_PRETTY_PRINT)
6768
);
@@ -70,17 +71,17 @@ public function exportProjectEntityToOutputFolder(ProjectDto $project)
7071
private function removeCurrentFilesInOutput()
7172
{
7273
$this->fileService->remove(array(
73-
$this->outputDirectory.DIRECTORY_SEPARATOR,
74-
$this->outputDirectory.DIRECTORY_SEPARATOR
74+
$this->outputDirectory . DIRECTORY_SEPARATOR,
75+
$this->outputDirectory . DIRECTORY_SEPARATOR
7576
));
7677
}
7778

7879
public function exportLogo(ProjectDto $project, $outputFolder)
7980
{
8081
if ($project->logo) {
8182
$this->fileService->copy(
82-
$project->definitionFile.DIRECTORY_SEPARATOR.$project->logo,
83-
$outputFolder.DIRECTORY_SEPARATOR.$project->logo,
83+
$project->definitionFile . DIRECTORY_SEPARATOR . $project->logo,
84+
$outputFolder . DIRECTORY_SEPARATOR . $project->logo,
8485
true
8586
);
8687
}
@@ -92,7 +93,7 @@ public function exportLogo(ProjectDto $project, $outputFolder)
9293
*/
9394
public function exportExampleFiles($categoryList, $outputFolder)
9495
{
95-
foreach($categoryList as $category) {
96+
foreach ($categoryList as $category) {
9697
if ($category->routeList) {
9798
foreach ($category->routeList as $route) {
9899
$this->moveExampleFilesFromRoute($route, $outputFolder);
@@ -110,7 +111,7 @@ public function exportExampleFiles($categoryList, $outputFolder)
110111
*/
111112
private function moveExampleFilesFromRoute(RouteDto $route, $outputFolder)
112113
{
113-
if($route->request->method == FileContentParserService::ROUTE_METHOD_POST){
114+
if ($route->request->method == FileContentParserService::ROUTE_METHOD_POST) {
114115
/**
115116
* @var $paramList ParameterDto[]
116117
*/
@@ -119,11 +120,11 @@ private function moveExampleFilesFromRoute(RouteDto $route, $outputFolder)
119120
if (empty($paramList)) {
120121
return;
121122
}
122-
foreach($paramList as $parameter) {
123-
if($parameter->data_type == FileContentParserService::PARAMETER_TYPE_FILE){
123+
foreach ($paramList as $parameter) {
124+
if ($parameter->data_type == FileContentParserService::PARAMETER_TYPE_FILE) {
124125
$this->fileService->copy(
125-
$route->inputPath.DIRECTORY_SEPARATOR.$parameter->example,
126-
$outputFolder.DIRECTORY_SEPARATOR.$parameter->example,
126+
$route->inputPath . DIRECTORY_SEPARATOR . $parameter->example,
127+
$outputFolder . DIRECTORY_SEPARATOR . $parameter->example,
127128
true
128129
);
129130
}

0 commit comments

Comments
 (0)