Skip to content
This repository has been archived by the owner on Oct 17, 2023. It is now read-only.

Commit

Permalink
New SwaggerDecorator version
Browse files Browse the repository at this point in the history
  • Loading branch information
rjzondervan committed Jan 13, 2020
1 parent d1bd6a4 commit b644b64
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions api/src/Swagger/SwaggerDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function normalize($object, $format = null, array $context = [])
//$additionalEntityDocs = $this->getAdditionalEntityDocs($entity);
$entityDocs = $this->getAdditionalEntityDocs($entity);
// Only run if we have aditional docs
if (array_key_exists('properties', $entityDocs)) {
if(array_key_exists('properties',$entityDocs)){
$additionalDocs = array_merge($additionalDocs, $entityDocs['properties']);
}

Expand Down Expand Up @@ -418,13 +418,20 @@ private function getAdditionalEntityDocs($entity)
$atributes = [];
$groups = [];


foreach ($tags as $tag) {
$name = $tag->getName();
$description = $tag->getDescription();
//
//$description = (string) $description;

switch ($name) {

// Description
case 'var':
$atributes['description'] = (string) $description;
$atributes['type'] = (string) $tag->getType();

break;

// Docblocks
case 'example':
$atributes['example'] = (string) $description;
Expand All @@ -437,22 +444,48 @@ private function getAdditionalEntityDocs($entity)
break;

// Constrainds (Validation)
case "Assert\Date":
$atributes['type'] = "string";
$atributes['format'] = 'date';
$atributes['example'] = \date('Y-m-d');
break;
case "Assert\DateTime":
$atributes['type'] = "string";
$atributes['format'] = 'date-time';
$atributes['example'] = \date('Y-m-d H:i:s');
break;
case "Assert\Time":
$atributes['type'] = "string";
$atributes['format'] = 'time';
$atributes['example'] = \date('H:i:s');
break;
case "Assert\Timezone":
$atributes['type'] = "string";
$atributes['format'] = 'timezone';
$atributes['example'] = 'America/New_York';
break;
case "Assert\Uuid":
$atributes['type'] = "string";
$atributes['format'] = 'uuid';
break;
case "Assert\Email":
$atributes['type'] = "string";
$atributes['format'] = 'email';
break;
case "Assert\Url":
$atributes['type'] = "string";
$atributes['format'] = 'url';
break;
case "Assert\Regex":
$atributes['type'] = "string";
$atributes['format'] = 'regex';
break;
case "Assert\Ip":
$atributes['type'] = "string";
$atributes['format'] = 'ip';
break;
case "Assert\Json":
$atributes['type'] = "string";
$atributes['format'] = 'json';
break;
case "Assert\Choice":
Expand Down

0 comments on commit b644b64

Please sign in to comment.