Browse Source

openapi improvements (#2381)

* generate openapi definitions as separate build task

* first defns

* install etv-client module in docker

* include python entrypoint in docker

* update changelog
pull/2369/head
Jason Dove 4 months ago committed by GitHub
parent
commit
487d99dc69
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      CHANGELOG.md
  2. 18
      ErsatzTV/ErsatzTV.csproj
  3. 7
      ErsatzTV/Startup.cs
  4. 1712
      ErsatzTV/wwwroot/openapi/scripted-schedule-tagged.json
  5. 1703
      ErsatzTV/wwwroot/openapi/scripted-schedule.json
  6. 297
      ErsatzTV/wwwroot/openapi/v1.json
  7. 12
      docker/Dockerfile
  8. 52
      scripts/scripted-schedules/entrypoint.py

4
CHANGELOG.md

@ -27,6 +27,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). @@ -27,6 +27,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- `/home/jason/schedule.sh http://localhost:8409 00000000-0000...0000 reset "party central" 23`
- This enables wrapper script re-use across multiple scripted schedules
- API reference is available at `/docs`
- Docker images contain pre-generated python api client and entrypoint script
- Entrypoint is at `/app/scripted-schedules/entrypoint.py`
- Scripts folder should be mounted to `/app/scripted-schedules/scripts`
- Playouts should be created with scripted schedule `/app/scripted-schedules/entrypoint.py script-name` (no trailing `.py`)
## [25.5.0] - 2025-09-01
### Added

18
ErsatzTV/ErsatzTV.csproj

@ -15,6 +15,20 @@ @@ -15,6 +15,20 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup>
<OpenApiDocumentsDirectory>$(MSBuildProjectDirectory)\wwwroot\openapi</OpenApiDocumentsDirectory>
<OpenApiGenerateDocumentsOnBuild>false</OpenApiGenerateDocumentsOnBuild>
</PropertyGroup>
<Target Name="RenameOpenApiFiles" AfterTargets="GenerateOpenApiDocuments">
<Move SourceFiles="$(OpenApiDocumentsDirectory)\ErsatzTV.json"
DestinationFiles="$(OpenApiDocumentsDirectory)\v1.json" />
<Move SourceFiles="$(OpenApiDocumentsDirectory)\ErsatzTV_scripted-schedule.json"
DestinationFiles="$(OpenApiDocumentsDirectory)\scripted-schedule.json" />
<Move SourceFiles="$(OpenApiDocumentsDirectory)\ErsatzTV_scripted-schedule-tagged.json"
DestinationFiles="$(OpenApiDocumentsDirectory)\scripted-schedule-tagged.json" />
</Target>
<ItemGroup>
<PackageReference Include="Blazored.FluentValidation" Version="2.2.0" />
<PackageReference Include="Bugsnag.AspNet.Core" Version="4.1.0" />
@ -34,6 +48,10 @@ @@ -34,6 +48,10 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.ApiDescription.Server" Version="9.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.14.15">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

7
ErsatzTV/Startup.cs

@ -620,7 +620,12 @@ public class Startup @@ -620,7 +620,12 @@ public class Startup
endpoints.MapControllers();
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
endpoints.MapOpenApi().CacheOutput();
if (CurrentEnvironment.IsDevelopment())
{
endpoints.MapOpenApi();
}
endpoints.MapScalarApiReference("/docs", options =>
{
options.AddDocument(

1712
ErsatzTV/wwwroot/openapi/scripted-schedule-tagged.json

File diff suppressed because it is too large Load Diff

1703
ErsatzTV/wwwroot/openapi/scripted-schedule.json

File diff suppressed because it is too large Load Diff

297
ErsatzTV/wwwroot/openapi/v1.json

@ -0,0 +1,297 @@ @@ -0,0 +1,297 @@
{
"openapi": "3.0.1",
"info": {
"title": "ErsatzTV | v1",
"version": "1.0.0"
},
"paths": {
"/api/channels/{channelNumber}/playout/reset": {
"post": {
"tags": [
"Channels"
],
"summary": "Reset channel playout",
"parameters": [
{
"name": "channelNumber",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/libraries/{id}/scan": {
"post": {
"tags": [
"Libraries"
],
"summary": "Scan library",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
}
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/libraries/{id}/scan-show": {
"post": {
"tags": [
"Libraries"
],
"summary": "Scan show",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
}
}
],
"requestBody": {
"content": {
"application/json-patch+json": {
"schema": {
"$ref": "#/components/schemas/ScanShowRequest"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/ScanShowRequest"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/ScanShowRequest"
}
},
"application/*+json": {
"schema": {
"$ref": "#/components/schemas/ScanShowRequest"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/maintenance/gc": {
"get": {
"tags": [
"Maintenance"
],
"summary": "Garbage collect",
"parameters": [
{
"name": "force",
"in": "query",
"schema": {
"type": "boolean",
"default": false
}
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/maintenance/empty_trash": {
"post": {
"tags": [
"Maintenance"
],
"summary": "Empty trash",
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/sessions": {
"get": {
"tags": [
"Sessions"
],
"summary": "Get sessions",
"responses": {
"200": {
"description": "OK",
"content": {
"text/plain": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/HlsSessionModel"
}
}
},
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/HlsSessionModel"
}
}
},
"text/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/HlsSessionModel"
}
}
}
}
}
}
}
},
"/api/session/{channelNumber}": {
"delete": {
"tags": [
"Sessions"
],
"summary": "Stop session",
"parameters": [
{
"name": "channelNumber",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/version": {
"get": {
"tags": [
"Version"
],
"summary": "Get version",
"responses": {
"200": {
"description": "OK",
"content": {
"text/plain": {
"schema": {
"type": "string"
}
},
"application/json": {
"schema": {
"type": "string"
}
},
"text/json": {
"schema": {
"type": "string"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"HlsSessionModel": {
"required": [
"channelNumber",
"state",
"transcodedUntil",
"lastAccess"
],
"type": "object",
"properties": {
"channelNumber": {
"type": "string",
"nullable": true
},
"state": {
"type": "string",
"nullable": true
},
"transcodedUntil": {
"type": "string",
"format": "date-time"
},
"lastAccess": {
"type": "string",
"format": "date-time"
}
}
},
"ScanShowRequest": {
"required": [
"showTitle"
],
"type": "object",
"properties": {
"showTitle": {
"type": "string",
"nullable": true
},
"deepScan": {
"type": "boolean",
"default": false
}
}
}
}
},
"tags": [
{
"name": "Channels"
},
{
"name": "Libraries"
},
{
"name": "Maintenance"
},
{
"name": "Sessions"
},
{
"name": "Version"
}
]
}

12
docker/Dockerfile

@ -5,9 +5,18 @@ COPY --from=dotnet-runtime /usr/share/dotnet /usr/share/dotnet @@ -5,9 +5,18 @@ COPY --from=dotnet-runtime /usr/share/dotnet /usr/share/dotnet
# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:9.0-noble-amd64 AS build
RUN apt-get update && apt-get install -y ca-certificates gnupg
RUN apt-get update && apt-get install -y ca-certificates gnupg default-jre-headless python3-pip
WORKDIR /source
# generate openapi client
COPY ErsatzTV/wwwroot/openapi/. /app/ErsatzTV/wwwroot/openapi/
RUN wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.15.0/openapi-generator-cli-7.15.0.jar
RUN java -jar openapi-generator-cli-7.15.0.jar generate -i /app/ErsatzTV/wwwroot/openapi/scripted-schedule.json -g python -o /app/etv-client --package-name etv_client
RUN rm -rf openapi-generator-cli-7.15.0.jar /app/ErsatzTV
RUN python3 -m pip install --target=/app/pythonlibs /app/etv-client
RUN rm -rf /app/etv-client
COPY scripts/scripted-schedules/. /app/scripted-schedules/
# copy csproj and restore as distinct layers
COPY *.sln .
COPY artwork/* ./artwork/
@ -43,6 +52,7 @@ ENV FONTCONFIG_PATH=/etc/fonts @@ -43,6 +52,7 @@ ENV FONTCONFIG_PATH=/etc/fonts
RUN fc-cache update
WORKDIR /app
COPY --from=build /app ./
ENV PYTHONPATH=/app/pythonlibs
ENV ETV_CONFIG_FOLDER=/config
ENV ETV_TRANSCODE_FOLDER=/transcode
ENV ETV_DISABLE_VULKAN=1

52
scripts/scripted-schedules/entrypoint.py

@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
#!/usr/bin/python3
import argparse
import importlib
import sys
from uuid import UUID
import etv_client
from etv_client.api import scripted_schedule_api
def main():
parser = argparse.ArgumentParser(description="Run an ETV scripted schedule")
parser.add_argument('host', help="The ETV host (e.g., http://localhost:8409)")
parser.add_argument('build_id', type=UUID, help="The build ID for the playout")
parser.add_argument('mode', choices=['reset', 'continue'], help="The playout build mode")
parser.add_argument('script_name', help="The name of the script module to use (e.g., one)")
known_args, unknown_args = parser.parse_known_args()
try:
script_module = importlib.import_module(f"scripts.{known_args.script_name}")
except ImportError:
print(f"Error: cannot find a script file named '{known_args.script_name}.py' in the 'scripts' directory.")
sys.exit(1)
configuration = etv_client.Configuration(host=known_args.host)
with etv_client.ApiClient(configuration) as api_client:
try:
define_content = getattr(script_module, 'define_content')
reset_playout = getattr(script_module, 'reset_playout')
build_playout = getattr(script_module, 'build_playout')
api_instance = scripted_schedule_api.ScriptedScheduleApi(api_client)
context = api_instance.get_context(known_args.build_id)
define_content(api_instance, context, known_args.build_id)
if known_args.mode == "reset":
reset_playout(api_instance, context, known_args.build_id)
build_playout(api_instance, context, known_args.build_id)
except etv_client.ApiException as e:
print(f"Exception when calling scripted schedule api: {e}\n")
except AttributeError as e:
print(f"Error: the '{known_args.script_name}' script is missing a required function. {e}")
if __name__ == "__main__":
main()
Loading…
Cancel
Save