Update OpenAPI spec, use fixed example timestamp.
This commit is contained in:
parent
80dae3b9f4
commit
f6c1fbf79c
|
@ -128,9 +128,6 @@ class AppFactory
|
|||
|
||||
self::applyPhpSettings($environment);
|
||||
|
||||
// Helper constants for annotations.
|
||||
define('SAMPLE_TIMESTAMP', random_int(time() - 86400, time() + 86400));
|
||||
|
||||
// Override DI definitions for settings.
|
||||
$diDefinitions[Environment::class] = $environment;
|
||||
|
||||
|
|
|
@ -4,27 +4,49 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Console\Command;
|
||||
|
||||
use App\Console\Application;
|
||||
use App\Environment;
|
||||
use App\Version;
|
||||
use OpenApi\Annotations\OpenApi;
|
||||
use OpenApi\Generator;
|
||||
use OpenApi\Util;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
class GenerateApiDocsCommand extends CommandAbstract
|
||||
{
|
||||
public function __invoke(
|
||||
SymfonyStyle $io,
|
||||
Environment $environment
|
||||
): int {
|
||||
public function __construct(
|
||||
Application $application,
|
||||
protected Environment $environment,
|
||||
protected Version $version
|
||||
) {
|
||||
parent::__construct($application);
|
||||
}
|
||||
|
||||
public function __invoke(SymfonyStyle $io): int
|
||||
{
|
||||
$yaml = $this->generate()->toYaml();
|
||||
$yaml_path = $this->environment->getBaseDirectory() . '/web/static/api/openapi.yml';
|
||||
|
||||
file_put_contents($yaml_path, $yaml);
|
||||
|
||||
$io->writeln('API documentation updated!');
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function generate(bool $useCurrentVersion = false): OpenApi
|
||||
{
|
||||
define('AZURACAST_API_URL', 'https://demo.azuracast.com/api');
|
||||
define('AZURACAST_API_NAME', 'AzuraCast Public Demo Server');
|
||||
define('AZURACAST_VERSION', Version::FALLBACK_VERSION);
|
||||
define(
|
||||
'AZURACAST_VERSION',
|
||||
$useCurrentVersion ? $this->version->getVersion() : Version::FALLBACK_VERSION
|
||||
);
|
||||
|
||||
$finder = Util::finder(
|
||||
[
|
||||
$environment->getBaseDirectory() . '/util/openapi.php',
|
||||
$environment->getBaseDirectory() . '/src/Entity',
|
||||
$environment->getBaseDirectory() . '/src/Controller/Api',
|
||||
$this->environment->getBaseDirectory() . '/util/openapi.php',
|
||||
$this->environment->getBaseDirectory() . '/src/Entity',
|
||||
$this->environment->getBaseDirectory() . '/src/Controller/Api',
|
||||
],
|
||||
[
|
||||
'bootstrap',
|
||||
|
@ -33,12 +55,6 @@ class GenerateApiDocsCommand extends CommandAbstract
|
|||
]
|
||||
);
|
||||
|
||||
$yaml_path = $environment->getBaseDirectory() . '/web/static/api/openapi.yml';
|
||||
$yaml = (Generator::scan($finder))->toYaml();
|
||||
|
||||
file_put_contents($yaml_path, $yaml);
|
||||
|
||||
$io->writeln('API documentation updated!');
|
||||
return 0;
|
||||
return Generator::scan($finder);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,45 +4,19 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Controller\Api;
|
||||
|
||||
use App\Environment;
|
||||
use App\Console\Command\GenerateApiDocsCommand;
|
||||
use App\Http\Response;
|
||||
use App\Http\ServerRequest;
|
||||
use App\Version;
|
||||
use OpenApi\Generator;
|
||||
use OpenApi\Util;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
class OpenApiController
|
||||
{
|
||||
public function __construct(
|
||||
protected Environment $environment,
|
||||
protected Version $version
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(ServerRequest $request, Response $response): ResponseInterface
|
||||
{
|
||||
$api_base_url = (string)$request->getRouter()->fromHere(absolute: true);
|
||||
$api_base_url = str_replace('/openapi.yml', '', $api_base_url);
|
||||
|
||||
define('AZURACAST_API_URL', $api_base_url);
|
||||
define('AZURACAST_API_NAME', 'This AzuraCast Installation');
|
||||
define('AZURACAST_VERSION', $this->version->getVersion());
|
||||
|
||||
$finder = Util::finder(
|
||||
[
|
||||
$this->environment->getBaseDirectory() . '/util/openapi.php',
|
||||
$this->environment->getBaseDirectory() . '/src/Entity',
|
||||
$this->environment->getBaseDirectory() . '/src/Controller/Api',
|
||||
],
|
||||
[
|
||||
'bootstrap',
|
||||
'locale',
|
||||
'templates',
|
||||
]
|
||||
);
|
||||
|
||||
$yaml = (Generator::scan($finder))->toYaml();
|
||||
public function __invoke(
|
||||
ServerRequest $request,
|
||||
Response $response,
|
||||
GenerateApiDocsCommand $apiDocsCommand
|
||||
): ResponseInterface {
|
||||
$yaml = $apiDocsCommand->generate(true)->toYaml();
|
||||
|
||||
$response->getBody()->write($yaml);
|
||||
return $response->withHeader('Content-Type', 'text/x-yaml');
|
||||
|
|
|
@ -138,7 +138,7 @@ class RequestsController
|
|||
* in="path",
|
||||
* required=true,
|
||||
* @OA\Schema(
|
||||
* type="integer", format="int64"
|
||||
* type="string"
|
||||
* )
|
||||
* ),
|
||||
* @OA\Response(response=200, description="Success"),
|
||||
|
@ -148,11 +148,11 @@ class RequestsController
|
|||
*
|
||||
* @param ServerRequest $request
|
||||
* @param Response $response
|
||||
* @param mixed $media_id
|
||||
* @param string $media_id
|
||||
*
|
||||
* @throws Exception\InvalidRequestAttribute
|
||||
*/
|
||||
public function submitAction(ServerRequest $request, Response $response, mixed $media_id): ResponseInterface
|
||||
public function submitAction(ServerRequest $request, Response $response, string $media_id): ResponseInterface
|
||||
{
|
||||
$station = $request->getStation();
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ class Listener
|
|||
/**
|
||||
* UNIX timestamp that the user first connected.
|
||||
*
|
||||
* @OA\Property(example=SAMPLE_TIMESTAMP)
|
||||
* @OA\Property(example=1609480800)
|
||||
* @var int
|
||||
*/
|
||||
public int $connected_on;
|
||||
|
@ -72,7 +72,7 @@ class Listener
|
|||
/**
|
||||
* UNIX timestamp that the user disconnected (or the latest timestamp if they are still connected).
|
||||
*
|
||||
* @OA\Property(example=SAMPLE_TIMESTAMP)
|
||||
* @OA\Property(example=1609480800)
|
||||
* @var int
|
||||
*/
|
||||
public int $connected_until;
|
||||
|
|
|
@ -25,7 +25,7 @@ class SongHistory implements ResolvableUrlInterface
|
|||
/**
|
||||
* UNIX timestamp when playback started.
|
||||
*
|
||||
* @OA\Property(example=SAMPLE_TIMESTAMP)
|
||||
* @OA\Property(example=1609480800)
|
||||
* @var int
|
||||
*/
|
||||
public int $played_at = 0;
|
||||
|
|
|
@ -17,7 +17,7 @@ class StationQueue implements ResolvableUrlInterface
|
|||
/**
|
||||
* UNIX timestamp when playback is expected to start.
|
||||
*
|
||||
* @OA\Property(example=SAMPLE_TIMESTAMP)
|
||||
* @OA\Property(example=1609480800)
|
||||
* @var int
|
||||
*/
|
||||
public int $cued_at = 0;
|
||||
|
|
|
@ -37,7 +37,7 @@ class StationSchedule
|
|||
|
||||
/**
|
||||
* The start time of the schedule entry, in UNIX format.
|
||||
* @OA\Property(example=SAMPLE_TIMESTAMP)
|
||||
* @OA\Property(example=1609480800)
|
||||
* @var int
|
||||
*/
|
||||
public int $start_timestamp;
|
||||
|
@ -51,7 +51,7 @@ class StationSchedule
|
|||
|
||||
/**
|
||||
* The end time of the schedule entry, in UNIX format.
|
||||
* @OA\Property(example=SAMPLE_TIMESTAMP)
|
||||
* @OA\Property(example=1609480800)
|
||||
* @var int
|
||||
*/
|
||||
public int $end_timestamp;
|
||||
|
|
|
@ -22,7 +22,7 @@ class SystemStatus
|
|||
/**
|
||||
* The current UNIX timestamp
|
||||
*
|
||||
* @OA\Property(example=SAMPLE_TIMESTAMP)
|
||||
* @OA\Property(example=1609480800)
|
||||
* @var int
|
||||
*/
|
||||
public $timestamp;
|
||||
|
|
|
@ -36,11 +36,11 @@ class Relay implements IdentifiableEntityInterface
|
|||
#[ORM\Column(type: 'array', nullable: true)]
|
||||
protected mixed $nowplaying;
|
||||
|
||||
/** @OA\Property(example=SAMPLE_TIMESTAMP) */
|
||||
/** @OA\Property(example=1609480800) */
|
||||
#[ORM\Column]
|
||||
protected int $created_at;
|
||||
|
||||
/** @OA\Property(example=SAMPLE_TIMESTAMP) */
|
||||
/** @OA\Property(example=1609480800) */
|
||||
#[ORM\Column]
|
||||
protected int $updated_at;
|
||||
|
||||
|
|
|
@ -271,7 +271,7 @@ class Settings implements Stringable
|
|||
/**
|
||||
* @OA\Property(
|
||||
* description="The UNIX timestamp when updates were last checked.",
|
||||
* example=SAMPLE_TIMESTAMP
|
||||
* example=1609480800
|
||||
* )
|
||||
*/
|
||||
#[ORM\Column]
|
||||
|
@ -604,7 +604,7 @@ class Settings implements Stringable
|
|||
/**
|
||||
* @OA\Property(
|
||||
* description="The UNIX timestamp when automated backup was last run.",
|
||||
* example=SAMPLE_TIMESTAMP
|
||||
* example=1609480800
|
||||
* )
|
||||
*/
|
||||
#[ORM\Column]
|
||||
|
@ -649,7 +649,7 @@ class Settings implements Stringable
|
|||
/**
|
||||
* @OA\Property(
|
||||
* description="The UNIX timestamp when setup was last completed.",
|
||||
* example=SAMPLE_TIMESTAMP
|
||||
* example=1609480800
|
||||
* )
|
||||
*/
|
||||
#[ORM\Column]
|
||||
|
@ -702,7 +702,7 @@ class Settings implements Stringable
|
|||
/**
|
||||
* @OA\Property(
|
||||
* description="The UNIX timestamp when the now playing sync task was last run.",
|
||||
* example=SAMPLE_TIMESTAMP
|
||||
* example=1609480800
|
||||
* )
|
||||
*/
|
||||
#[ORM\Column]
|
||||
|
@ -722,7 +722,7 @@ class Settings implements Stringable
|
|||
/**
|
||||
* @OA\Property(
|
||||
* description="The UNIX timestamp when the 60-second 'short' sync task was last run.",
|
||||
* example=SAMPLE_TIMESTAMP
|
||||
* example=1609480800
|
||||
* )
|
||||
*/
|
||||
#[ORM\Column]
|
||||
|
@ -742,7 +742,7 @@ class Settings implements Stringable
|
|||
/**
|
||||
* @OA\Property(
|
||||
* description="The UNIX timestamp when the 5-minute 'medium' sync task was last run.",
|
||||
* example=SAMPLE_TIMESTAMP
|
||||
* example=1609480800
|
||||
* )
|
||||
*/
|
||||
#[ORM\Column]
|
||||
|
@ -762,7 +762,7 @@ class Settings implements Stringable
|
|||
/**
|
||||
* @OA\Property(
|
||||
* description="The UNIX timestamp when the 1-hour 'long' sync task was last run.",
|
||||
* example=SAMPLE_TIMESTAMP
|
||||
* example=1609480800
|
||||
* )
|
||||
*/
|
||||
#[ORM\Column]
|
||||
|
@ -856,7 +856,7 @@ class Settings implements Stringable
|
|||
/**
|
||||
* @OA\Property(
|
||||
* description="The UNIX timestamp when the Maxmind Geolite was last downloaded.",
|
||||
* example=SAMPLE_TIMESTAMP
|
||||
* example=1609480800
|
||||
* )
|
||||
*/
|
||||
#[ORM\Column]
|
||||
|
|
|
@ -120,7 +120,7 @@ class StationMedia implements SongInterface, ProcessableMediaInterface, PathAwar
|
|||
/**
|
||||
* @OA\Property(
|
||||
* description="The UNIX timestamp when the database was last modified.",
|
||||
* example=SAMPLE_TIMESTAMP
|
||||
* example=1609480800
|
||||
* )
|
||||
*/
|
||||
#[ORM\Column(nullable: true)]
|
||||
|
@ -183,7 +183,7 @@ class StationMedia implements SongInterface, ProcessableMediaInterface, PathAwar
|
|||
/**
|
||||
* @OA\Property(
|
||||
* description="The latest time (UNIX timestamp) when album art was updated.",
|
||||
* example=SAMPLE_TIMESTAMP
|
||||
* example=1609480800
|
||||
* )
|
||||
*/
|
||||
#[ORM\Column]
|
||||
|
|
|
@ -71,7 +71,7 @@ class StationStreamer implements
|
|||
#[ORM\Column]
|
||||
protected bool $enforce_schedule = false;
|
||||
|
||||
/** @OA\Property(example=SAMPLE_TIMESTAMP) */
|
||||
/** @OA\Property(example=1609480800) */
|
||||
#[ORM\Column(nullable: true)]
|
||||
#[Attributes\AuditIgnore]
|
||||
protected ?int $reactivate_at = null;
|
||||
|
|
|
@ -65,12 +65,12 @@ class User implements Stringable, IdentifiableEntityInterface
|
|||
#[Attributes\AuditIgnore]
|
||||
protected ?string $two_factor_secret = null;
|
||||
|
||||
/** @OA\Property(example=SAMPLE_TIMESTAMP) */
|
||||
/** @OA\Property(example=1609480800) */
|
||||
#[ORM\Column]
|
||||
#[Attributes\AuditIgnore]
|
||||
protected int $created_at;
|
||||
|
||||
/** @OA\Property(example=SAMPLE_TIMESTAMP) */
|
||||
/** @OA\Property(example=1609480800) */
|
||||
#[ORM\Column]
|
||||
#[Attributes\AuditIgnore]
|
||||
protected int $updated_at;
|
||||
|
|
|
@ -31,7 +31,7 @@ use OpenApi\Annotations as OA;
|
|||
* in="path",
|
||||
* required=true,
|
||||
* @OA\Schema(
|
||||
* type="integer", format="int64"
|
||||
* anyOf={@OA\Schema(type="integer", format="int64"), @OA\Schema(type="string", format="string")}
|
||||
* )
|
||||
* )
|
||||
*
|
||||
|
|
|
@ -1835,8 +1835,7 @@ paths:
|
|||
description: 'The requestable song ID'
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
description: Success
|
||||
|
@ -2421,11 +2420,11 @@ components:
|
|||
connected_on:
|
||||
description: 'UNIX timestamp that the user first connected.'
|
||||
type: integer
|
||||
example: 1629689299
|
||||
example: 1609480800
|
||||
connected_until:
|
||||
description: 'UNIX timestamp that the user disconnected (or the latest timestamp if they are still connected).'
|
||||
type: integer
|
||||
example: 1629689299
|
||||
example: 1609480800
|
||||
connected_time:
|
||||
description: 'Number of seconds that the user has been connected.'
|
||||
type: integer
|
||||
|
@ -2538,7 +2537,7 @@ components:
|
|||
played_at:
|
||||
description: 'UNIX timestamp when playback started.'
|
||||
type: integer
|
||||
example: 1629689299
|
||||
example: 1609480800
|
||||
duration:
|
||||
description: 'Duration of the song in seconds'
|
||||
type: integer
|
||||
|
@ -2635,7 +2634,7 @@ components:
|
|||
cued_at:
|
||||
description: 'UNIX timestamp when playback is expected to start.'
|
||||
type: integer
|
||||
example: 1629689299
|
||||
example: 1609480800
|
||||
duration:
|
||||
description: 'Duration of the song in seconds'
|
||||
type: integer
|
||||
|
@ -2974,7 +2973,7 @@ components:
|
|||
start_timestamp:
|
||||
description: 'The start time of the schedule entry, in UNIX format.'
|
||||
type: integer
|
||||
example: 1629689299
|
||||
example: 1609480800
|
||||
start:
|
||||
description: 'The start time of the schedule entry, in ISO 8601 format.'
|
||||
type: string
|
||||
|
@ -2982,7 +2981,7 @@ components:
|
|||
end_timestamp:
|
||||
description: 'The end time of the schedule entry, in UNIX format.'
|
||||
type: integer
|
||||
example: 1629689299
|
||||
example: 1609480800
|
||||
end:
|
||||
description: 'The start time of the schedule entry, in ISO 8601 format.'
|
||||
type: string
|
||||
|
@ -3022,7 +3021,7 @@ components:
|
|||
timestamp:
|
||||
description: 'The current UNIX timestamp'
|
||||
type: integer
|
||||
example: 1629689299
|
||||
example: 1609480800
|
||||
type: object
|
||||
Api_Time:
|
||||
properties:
|
||||
|
@ -3095,10 +3094,10 @@ components:
|
|||
example: true
|
||||
created_at:
|
||||
type: integer
|
||||
example: 1629689299
|
||||
example: 1609480800
|
||||
updated_at:
|
||||
type: integer
|
||||
example: 1629689299
|
||||
example: 1609480800
|
||||
Role:
|
||||
type: object
|
||||
allOf:
|
||||
|
@ -3164,7 +3163,7 @@ components:
|
|||
update_last_run:
|
||||
description: 'The UNIX timestamp when updates were last checked.'
|
||||
type: integer
|
||||
example: 1629689299
|
||||
example: 1609480800
|
||||
public_theme:
|
||||
nullable: true
|
||||
description: 'Base Theme for Public Pages'
|
||||
|
@ -3241,12 +3240,7 @@ components:
|
|||
backup_last_run:
|
||||
description: 'The UNIX timestamp when automated backup was last run.'
|
||||
type: integer
|
||||
example: 1629689299
|
||||
backup_last_result:
|
||||
nullable: true
|
||||
description: 'The result of the latest automated backup task.'
|
||||
type: string
|
||||
example: ''
|
||||
example: 1609480800
|
||||
backup_last_output:
|
||||
nullable: true
|
||||
description: 'The output of the latest automated backup task.'
|
||||
|
@ -3255,26 +3249,26 @@ components:
|
|||
setup_complete_time:
|
||||
description: 'The UNIX timestamp when setup was last completed.'
|
||||
type: integer
|
||||
example: 1629689299
|
||||
example: 1609480800
|
||||
nowplaying:
|
||||
description: 'The current cached now playing data.'
|
||||
example: ''
|
||||
sync_nowplaying_last_run:
|
||||
description: 'The UNIX timestamp when the now playing sync task was last run.'
|
||||
type: integer
|
||||
example: 1629689299
|
||||
example: 1609480800
|
||||
sync_short_last_run:
|
||||
description: 'The UNIX timestamp when the 60-second ''short'' sync task was last run.'
|
||||
type: integer
|
||||
example: 1629689299
|
||||
example: 1609480800
|
||||
sync_medium_last_run:
|
||||
description: 'The UNIX timestamp when the 5-minute ''medium'' sync task was last run.'
|
||||
type: integer
|
||||
example: 1629689299
|
||||
example: 1609480800
|
||||
sync_long_last_run:
|
||||
description: 'The UNIX timestamp when the 1-hour ''long'' sync task was last run.'
|
||||
type: integer
|
||||
example: 1629689299
|
||||
example: 1609480800
|
||||
external_ip:
|
||||
nullable: true
|
||||
description: 'This installation''s external IP.'
|
||||
|
@ -3288,7 +3282,7 @@ components:
|
|||
geolite_last_run:
|
||||
description: 'The UNIX timestamp when the Maxmind Geolite was last downloaded.'
|
||||
type: integer
|
||||
example: 1629689299
|
||||
example: 1609480800
|
||||
enable_advanced_features:
|
||||
description: 'Whether to enable ''advanced'' functionality in the system that is intended for power users.'
|
||||
type: boolean
|
||||
|
@ -3500,7 +3494,7 @@ components:
|
|||
nullable: true
|
||||
description: 'The UNIX timestamp when the database was last modified.'
|
||||
type: integer
|
||||
example: 1629689299
|
||||
example: 1609480800
|
||||
amplify:
|
||||
nullable: true
|
||||
description: 'The amount of amplification (in dB) to be applied to the radio source (liq_amplify)'
|
||||
|
@ -3540,7 +3534,7 @@ components:
|
|||
art_updated_at:
|
||||
description: 'The latest time (UNIX timestamp) when album art was updated.'
|
||||
type: integer
|
||||
example: 1629689299
|
||||
example: 1609480800
|
||||
playlists:
|
||||
type: array
|
||||
items: { }
|
||||
|
@ -3730,7 +3724,7 @@ components:
|
|||
reactivate_at:
|
||||
nullable: true
|
||||
type: integer
|
||||
example: 1629689299
|
||||
example: 1609480800
|
||||
schedule_items:
|
||||
type: array
|
||||
items: { }
|
||||
|
@ -3829,10 +3823,10 @@ components:
|
|||
example: A1B2C3D4
|
||||
created_at:
|
||||
type: integer
|
||||
example: 1629689299
|
||||
example: 1609480800
|
||||
updated_at:
|
||||
type: integer
|
||||
example: 1629689299
|
||||
example: 1609480800
|
||||
roles:
|
||||
type: array
|
||||
items: { }
|
||||
|
@ -3846,8 +3840,13 @@ components:
|
|||
description: 'The station ID'
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
anyOf:
|
||||
-
|
||||
type: integer
|
||||
format: int64
|
||||
-
|
||||
type: string
|
||||
format: string
|
||||
example: 1
|
||||
securitySchemes:
|
||||
api_key:
|
||||
|
|
Loading…
Reference in New Issue