Skip to content

Commit

Permalink
weather_status: Add OpenAPI spec
Browse files Browse the repository at this point in the history
Signed-off-by: jld3103 <[email protected]>
  • Loading branch information
provokateurin committed May 5, 2023
1 parent bc279a4 commit d3a5932
Show file tree
Hide file tree
Showing 5 changed files with 1,021 additions and 11 deletions.
2 changes: 2 additions & 0 deletions apps/weather_status/lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public function __construct() {

/**
* @inheritDoc
*
* @return array{weather_status: array{enabled: bool}}
*/
public function getCapabilities() {
return [
Expand Down
23 changes: 15 additions & 8 deletions apps/weather_status/lib/Controller/WeatherStatusController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@
*/
namespace OCA\WeatherStatus\Controller;

use OCA\WeatherStatus\ResponseDefinitions;
use OCA\WeatherStatus\Service\WeatherStatusService;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\ILogger;
use OCP\IRequest;

/**
* @psalm-import-type WeatherStatusForecast from ResponseDefinitions
*/
class WeatherStatusController extends OCSController {

/** @var string */
Expand Down Expand Up @@ -59,7 +63,7 @@ public function __construct(string $appName,
*
* Try to use the address set in user personal settings as weather location
*
* @return DataResponse with success state and address information
* @return DataResponse<array{success: bool, lat: ?float, lon: ?float, address: ?string}, Http::STATUS_OK>
*/
public function usePersonalAddress(): DataResponse {
return new DataResponse($this->service->usePersonalAddress());
Expand All @@ -73,7 +77,7 @@ public function usePersonalAddress(): DataResponse {
* - use the user defined address
*
* @param int $mode New mode
* @return DataResponse success state
* @return DataResponse<array{success: bool}, Http::STATUS_OK>
*/
public function setMode(int $mode): DataResponse {
return new DataResponse($this->service->setMode($mode));
Expand All @@ -88,7 +92,7 @@ public function setMode(int $mode): DataResponse {
* @param string|null $address Any approximative or exact address
* @param float|null $lat Latitude in decimal degree format
* @param float|null $lon Longitude in decimal degree format
* @return DataResponse with success state and address information
* @return DataResponse<array{success: bool, lat: ?float, lon: ?float, address: ?string}, Http::STATUS_OK>
*/
public function setLocation(?string $address, ?float $lat, ?float $lon): DataResponse {
$currentWeather = $this->service->setLocation($address, $lat, $lon);
Expand All @@ -100,7 +104,7 @@ public function setLocation(?string $address, ?float $lat, ?float $lon): DataRes
*
* Get stored user location
*
* @return DataResponse which contains coordinates, formatted address and current weather status mode
* @return DataResponse<array{lat: float, lon: float, address: string, mode: int}, Http::STATUS_OK>
*/
public function getLocation(): DataResponse {
$location = $this->service->getLocation();
Expand All @@ -112,7 +116,10 @@ public function getLocation(): DataResponse {
*
* Get forecast for current location
*
* @return DataResponse which contains success state and filtered forecast data
* @return DataResponse<WeatherStatusForecast[], Http::STATUS_OK>|DataResponse<array{success: bool}, Http::STATUS_NOT_FOUND>
*
* 200: Forecast returned
* 404: Forecast not found
*/
public function getForecast(): DataResponse {
$forecast = $this->service->getForecast();
Expand All @@ -128,7 +135,7 @@ public function getForecast(): DataResponse {
*
* Get favorites list
*
* @return DataResponse which contains the favorite list
* @return DataResponse<string[], Http::STATUS_OK>
*/
public function getFavorites(): DataResponse {
return new DataResponse($this->service->getFavorites());
Expand All @@ -139,8 +146,8 @@ public function getFavorites(): DataResponse {
*
* Set favorites list
*
* @param array $favorites
* @return DataResponse success state
* @param string[] $favorites Favorite addresses
* @return DataResponse<array{success: bool}, Http::STATUS_OK>
*/
public function setFavorites(array $favorites): DataResponse {
return new DataResponse($this->service->setFavorites($favorites));
Expand Down
87 changes: 87 additions & 0 deletions apps/weather_status/lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php
declare(strict_types=1);

/**
* @copyright Copyright (c) 2023 Kate Döen <[email protected]>
*
* @author Kate Döen <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\WeatherStatus;

/**
* https://api.met.no/doc/ForecastJSON
* @psalm-type WeatherStatusForecast = array{
* time: string,
* data: array{
* instant: array{
* details: array{
* air_pressure_at_sea_level: float,
* air_temperature: float,
* cloud_area_fraction: float,
* cloud_area_fraction_high: float,
* cloud_area_fraction_low: float,
* cloud_area_fraction_medium: float,
* dew_point_temperature: float,
* fog_area_fraction: float,
* relative_humidity: float,
* ultraviolet_index_clear_sky: float,
* wind_from_direction: float,
* wind_speed: float,
* wind_speed_of_gust: float,
* },
* },
* next_12_hours: array{
* summary: array{
* symbol_code: string,
* },
* details: array{
* probability_of_precipitation: float,
* },
* },
* next_1_hours: array{
* summary: array{
* symbol_code: string,
* },
* details: array{
* precipitation_amount: float,
* precipitation_amount_max: float,
* precipitation_amount_min: float,
* probability_of_precipitation: float,
* probability_of_thunder: float,
* },
* },
* next_6_hours: array{
* summary: array{
* symbol_code: string,
* },
* details: array{
* air_temperature_max: float,
* air_temperature_min: float,
* precipitation_amount: float,
* precipitation_amount_max: float,
* precipitation_amount_min: float,
* probability_of_precipitation: float,
* },
* },
* },
* }
*/
class ResponseDefinitions {
}
5 changes: 2 additions & 3 deletions apps/weather_status/lib/Service/WeatherStatusService.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ public function setMode(int $mode): array {

/**
* Get favorites list
* @param array $favorites
* @return array success state
* @return string[]
*/
public function getFavorites(): array {
$favoritesJson = $this->config->getUserValue($this->userId, Application::APP_ID, 'favorites', '');
Expand All @@ -141,7 +140,7 @@ public function getFavorites(): array {

/**
* Set favorites list
* @param array $favorites
* @param string[] $favorites
* @return array success state
*/
public function setFavorites(array $favorites): array {
Expand Down
Loading

0 comments on commit d3a5932

Please sign in to comment.