Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #237 from vimeo/add-info-description
Browse files Browse the repository at this point in the history
Adding support for OpenAPI API info descriptions
  • Loading branch information
erunion authored May 16, 2019
2 parents b6e1270 + f5caeb2 commit bed1eff
Show file tree
Hide file tree
Showing 26 changed files with 55 additions and 4 deletions.
2 changes: 2 additions & 0 deletions config.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<xs:element name="info" minOccurs="1" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="description" minOccurs="1" maxOccurs="unbounded" />

<xs:element name="terms" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="url" type="xs:string" use="required" />
Expand Down
1 change: 1 addition & 0 deletions resources/examples/Showtimes/compiled/1.0/openapi/api.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
openapi: 3.0.2
info:
title: 'Mill unit test API, Showtimes'
description: 'This is an example API for the purposes of showing how Mill works.'
version: '1.0'
contact:
name: 'Get help!'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
openapi: 3.0.2
info:
title: 'Mill unit test API, Showtimes'
description: 'This is an example API for the purposes of showing how Mill works.'
version: '1.0'
contact:
name: 'Get help!'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
openapi: 3.0.2
info:
title: 'Mill unit test API, Showtimes'
description: 'This is an example API for the purposes of showing how Mill works.'
version: '1.0'
contact:
name: 'Get help!'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
openapi: 3.0.2
info:
title: 'Mill unit test API, Showtimes'
description: 'This is an example API for the purposes of showing how Mill works.'
version: 1.1.1
contact:
name: 'Get help!'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
openapi: 3.0.2
info:
title: 'Mill unit test API, Showtimes'
description: 'This is an example API for the purposes of showing how Mill works.'
version: 1.1.1
contact:
name: 'Get help!'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
openapi: 3.0.2
info:
title: 'Mill unit test API, Showtimes'
description: 'This is an example API for the purposes of showing how Mill works.'
version: 1.1.1
contact:
name: 'Get help!'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
openapi: 3.0.2
info:
title: 'Mill unit test API, Showtimes'
description: 'This is an example API for the purposes of showing how Mill works.'
version: 1.1.2
contact:
name: 'Get help!'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
openapi: 3.0.2
info:
title: 'Mill unit test API, Showtimes'
description: 'This is an example API for the purposes of showing how Mill works.'
version: 1.1.2
contact:
name: 'Get help!'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
openapi: 3.0.2
info:
title: 'Mill unit test API, Showtimes'
description: 'This is an example API for the purposes of showing how Mill works.'
version: 1.1.2
contact:
name: 'Get help!'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
openapi: 3.0.2
info:
title: 'Mill unit test API, Showtimes'
description: 'This is an example API for the purposes of showing how Mill works.'
version: 1.1.3
contact:
name: 'Get help!'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
openapi: 3.0.2
info:
title: 'Mill unit test API, Showtimes'
description: 'This is an example API for the purposes of showing how Mill works.'
version: 1.1.3
contact:
name: 'Get help!'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
openapi: 3.0.2
info:
title: 'Mill unit test API, Showtimes'
description: 'This is an example API for the purposes of showing how Mill works.'
version: 1.1.3
contact:
name: 'Get help!'
Expand Down
1 change: 1 addition & 0 deletions resources/examples/Showtimes/compiled/1.1/openapi/api.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
openapi: 3.0.2
info:
title: 'Mill unit test API, Showtimes'
description: 'This is an example API for the purposes of showing how Mill works.'
version: '1.1'
contact:
name: 'Get help!'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
openapi: 3.0.2
info:
title: 'Mill unit test API, Showtimes'
description: 'This is an example API for the purposes of showing how Mill works.'
version: '1.1'
contact:
name: 'Get help!'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
openapi: 3.0.2
info:
title: 'Mill unit test API, Showtimes'
description: 'This is an example API for the purposes of showing how Mill works.'
version: '1.1'
contact:
name: 'Get help!'
Expand Down
1 change: 1 addition & 0 deletions resources/examples/Showtimes/compiled/public/1.0/api.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
openapi: 3.0.2
info:
title: 'Mill unit test API, Showtimes'
description: 'This is an example API for the purposes of showing how Mill works.'
version: '1.0'
contact:
name: 'Get help!'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
openapi: 3.0.2
info:
title: 'Mill unit test API, Showtimes'
description: 'This is an example API for the purposes of showing how Mill works.'
version: 1.1.1
contact:
name: 'Get help!'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
openapi: 3.0.2
info:
title: 'Mill unit test API, Showtimes'
description: 'This is an example API for the purposes of showing how Mill works.'
version: 1.1.2
contact:
name: 'Get help!'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
openapi: 3.0.2
info:
title: 'Mill unit test API, Showtimes'
description: 'This is an example API for the purposes of showing how Mill works.'
version: 1.1.3
contact:
name: 'Get help!'
Expand Down
1 change: 1 addition & 0 deletions resources/examples/Showtimes/compiled/public/1.1/api.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
openapi: 3.0.2
info:
title: 'Mill unit test API, Showtimes'
description: 'This is an example API for the purposes of showing how Mill works.'
version: '1.1'
contact:
name: 'Get help!'
Expand Down
2 changes: 2 additions & 0 deletions resources/examples/mill.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
bootstrap="../../vendor/autoload.php"
>
<info>
<description>This is an example API for the purposes of showing how Mill works.</description>

<terms url="https://example.com/terms" />

<contact
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/Specification/OpenApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function compile(): void
'openapi' => '3.0.2',
'info' => [
'title' => $this->config->getName(),
'description' => $this->config->getDescription(),
'version' => $version,
'contact' => $this->processContact()
],
Expand Down
25 changes: 21 additions & 4 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ class Config
/** @var string The base directory for this configuration file. */
protected $base_dir;

/** @var null|string The name of your API. */
protected $name = null;
/** @var string The name of your API. */
protected $name;

/** @var string The description of your API. */
protected $description;

/** @var null|string The terms of service URL for your API. */
protected $terms = null;
Expand Down Expand Up @@ -306,6 +309,10 @@ protected function loadCompilerSettings(SimpleXMLElement $xml): void
*/
protected function loadInfo(SimpleXMLElement $xml): void
{
if (isset($xml->info->description)) {
$this->description = (string) $xml->info->description;
}

if (isset($xml->info->terms)) {
$this->terms = (string) $xml->info->terms['url'];
}
Expand Down Expand Up @@ -543,13 +550,23 @@ protected function loadErrorRepresentations(SimpleXMLElement $xml): void
/**
* Get the name of your API.
*
* @return null|string
* @return string
*/
public function getName(): ?string
public function getName(): string
{
return $this->name;
}

/**
* Get the description of your API.
*
* @return string
*/
public function getDescription(): string
{
return $this->description;
}

/**
* Get the terms of service URL for your API.
*
Expand Down
7 changes: 7 additions & 0 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ public function testLoadFromXML(): void
$config = $this->getConfig();

$this->assertSame('Mill unit test API, Showtimes', $config->getName());
$this->assertSame(
'This is an example API for the purposes of showing how Mill works.',
$config->getDescription()
);

$this->assertSame('https://example.com/terms', $config->getTerms());

$this->assertSame([
Expand Down Expand Up @@ -230,6 +235,8 @@ public function testLoadFromXMLFailuresOnVariousBadXMLFiles(array $exception_det
if (strpos($provider, 'info.') === false) {
$info = <<<XML
<info>
<description>This is an example API for the purposes of showing how Mill works.</description>
<terms url="https://example.com/terms" />
<contact
Expand Down
2 changes: 2 additions & 0 deletions tests/_fixtures/mill.test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
bootstrap="vendor/autoload.php"
>
<info>
<description>This is an example API for the purposes of showing how Mill works.</description>

<terms url="https://example.com/terms" />

<contact
Expand Down

0 comments on commit bed1eff

Please sign in to comment.