Skip to content

Commit

Permalink
Merge pull request #14 from ConductionNL/dev-robert
Browse files Browse the repository at this point in the history
SwaggerDecorator update
  • Loading branch information
rubenvdlinde authored Jan 13, 2020
2 parents 3ce1222 + 4d6f8dc commit e2e3c9b
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 25 deletions.
2 changes: 1 addition & 1 deletion api/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ settings:
version: V.0.1
description: ''Naast deze JSON rest API is er ook een [graphql](/graphql) interface beschikbaar.''
repro: 'https://github.com/ConductionNL/locatiecatalogus'
subdomain: lc
subdomain: pc
domains:
- conduction.nl
- zaakonline.nl
Expand Down
48 changes: 36 additions & 12 deletions api/public/schema/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1175,12 +1175,10 @@ components:
schemas:
Accommodation-read:
type: object
description: ''
description: 'A room or other accommodation that can facilitate people.'
properties:
id:
readOnly: true
externalDocs:
url: 'http://schema.org/identifier'
type: string
name:
description: 'The name of this accommodation is displayed as a title to end users'
Expand Down Expand Up @@ -1218,6 +1216,7 @@ components:
items:
type: string
place:
description: 'The location this accommodation belongs to'
$ref: '#/components/schemas/Place-read'
required:
- name
Expand All @@ -1232,7 +1231,7 @@ components:
- resources
Accommodation-write:
type: object
description: ''
description: 'A room or other accommodation that can facilitate people.'
required:
- name
- accommodationCategory
Expand Down Expand Up @@ -1281,10 +1280,11 @@ components:
items:
type: string
place:
description: 'The location this accommodation belongs to'
$ref: '#/components/schemas/Place-write'
'Accommodation:jsonld-read':
type: object
description: ''
description: 'A room or other accommodation that can facilitate people.'
properties:
'@context':
readOnly: true
Expand Down Expand Up @@ -1334,6 +1334,7 @@ components:
items:
type: string
place:
description: 'The location this accommodation belongs to'
$ref: '#/components/schemas/Place:jsonld-read'
required:
- name
Expand All @@ -1348,7 +1349,7 @@ components:
- resources
'Accommodation:jsonld-write':
type: object
description: ''
description: 'A room or other accommodation that can facilitate people.'
required:
- name
- accommodationCategory
Expand Down Expand Up @@ -1406,10 +1407,11 @@ components:
items:
type: string
place:
description: 'The location this accommodation belongs to'
$ref: '#/components/schemas/Place:jsonld-write'
Place-read:
type: object
description: ''
description: 'A building or terrain with an address that can host accommodations.'
properties:
id:
readOnly: true
Expand Down Expand Up @@ -1456,6 +1458,11 @@ components:
url: 'http://schema.org/DateTime'
type: string
format: date-time
accommodations:
description: 'The accommodations in this location'
type: array
items:
$ref: '#/components/schemas/Accommodation-read'
required:
- name
- publicAccess
Expand All @@ -1464,7 +1471,7 @@ components:
- closingTime
Place-write:
type: object
description: ''
description: 'A building or terrain with an address that can host accommodations.'
required:
- name
- publicAccess
Expand Down Expand Up @@ -1514,9 +1521,14 @@ components:
url: 'http://schema.org/DateTime'
type: string
format: date-time
accommodations:
description: 'The accommodations in this location'
type: array
items:
$ref: '#/components/schemas/Accommodation-write'
'Place:jsonld-read':
type: object
description: ''
description: 'A building or terrain with an address that can host accommodations.'
properties:
'@context':
readOnly: true
Expand Down Expand Up @@ -1572,6 +1584,11 @@ components:
url: 'http://schema.org/DateTime'
type: string
format: date-time
accommodations:
description: 'The accommodations in this location'
type: array
items:
$ref: '#/components/schemas/Accommodation:jsonld-read'
required:
- name
- publicAccess
Expand All @@ -1580,7 +1597,7 @@ components:
- closingTime
'Place:jsonld-write':
type: object
description: ''
description: 'A building or terrain with an address that can host accommodations.'
required:
- name
- publicAccess
Expand Down Expand Up @@ -1639,6 +1656,11 @@ components:
url: 'http://schema.org/DateTime'
type: string
format: date-time
accommodations:
description: 'The accommodations in this location'
type: array
items:
$ref: '#/components/schemas/Accommodation:jsonld-write'
definitions:
Accommodation-read:
properties:
Expand Down Expand Up @@ -1758,6 +1780,7 @@ definitions:
example: '08:00'
closingTime:
example: '18:00'
accommodations: []
required:
- name
- publicAccess
Expand Down Expand Up @@ -1798,6 +1821,7 @@ definitions:
example: '08:00'
closingTime:
example: '18:00'
accommodations: []
required:
- name
- publicAccess
Expand All @@ -1808,13 +1832,13 @@ tags:
-
name: Accommodation
description: |
A room or other accommodation that can facilitate people.
-
name: Place
description: |
A building or terrain with an address that can host accommodations.
securityDefinitions:
Expand Down
4 changes: 2 additions & 2 deletions api/public/schema/publiccode.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ url: "https://github.com/ConductionNL/locatiecatalogus"
landingURL: "lc.zaakonline.nl"
isBasedOn: "https://github.com/ConductionNL/Proto-component-commonground.git"
softwareVersion: "V.0.1"
releaseDate: "2020-09-01"
logo:
releaseDate: "2020-13-01"
logo: lc.zaakonline.nl
monochromeLogo: img/logo-mono.svg

inputTypes:
Expand Down
2 changes: 2 additions & 0 deletions api/src/Entity/Accommodation.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ class Accommodation
private $resources = [];

/**
* @var Place The location this accommodation belongs to
*
* @Groups({"read","write"})
* @ORM\ManyToOne(targetEntity="App\Entity\Place", inversedBy="accommodations")
* @ORM\JoinColumn(nullable=false)
Expand Down
2 changes: 2 additions & 0 deletions api/src/Entity/Place.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ class Place
private $closingTime;

/**
* @var Accommodation[]|ArrayCollection The accommodations in this location
* @Groups({"read", "write"})
* @ORM\OneToMany(targetEntity="App\Entity\Accommodation", mappedBy="place", orphanRemoval=true)
*/
private $accommodations;
Expand Down
53 changes: 43 additions & 10 deletions api/src/Swagger/SwaggerDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ final class SwaggerDecorator implements NormalizerInterface
private $camelCaseToSnakeCaseNameConverter;

public function __construct(
NormalizerInterface $decorated,
ParameterBagInterface $params,
CacheInterface $cache,
EntityManagerInterface $em,
AnnotationReader $annotationReader,
CamelCaseToSnakeCaseNameConverter $camelCaseToSnakeCaseNameConverter
) {
NormalizerInterface $decorated,
ParameterBagInterface $params,
CacheInterface $cache,
EntityManagerInterface $em,
AnnotationReader $annotationReader,
CamelCaseToSnakeCaseNameConverter $camelCaseToSnakeCaseNameConverter
) {
$this->decorated = $decorated;
$this->params = $params;
$this->cash = $cache;
Expand Down 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 e2e3c9b

Please sign in to comment.