Use .Composite for models (better swagger)

This commit is contained in:
Zoe Roux 2025-05-02 00:35:49 +02:00
parent 9cb9301a35
commit 7203155747
No known key found for this signature in database
14 changed files with 38 additions and 39 deletions

View File

@ -45,7 +45,7 @@ export const CollectionTranslation = t.Object({
logo: t.Nullable(Image),
});
export const Collection = t.Intersect([
export const Collection = t.Composite([
Resource(),
CollectionTranslation,
BaseCollection,
@ -64,7 +64,7 @@ export const FullCollection = t.Intersect([
]);
export type FullCollection = Prettify<typeof FullCollection.static>;
export const SeedCollection = t.Intersect([
export const SeedCollection = t.Composite([
t.Omit(BaseCollection, ["kind", "startAir", "endAir", "nextRefresh"]),
t.Object({
slug: t.String({ format: "slug" }),
@ -72,7 +72,7 @@ export const SeedCollection = t.Intersect([
description: "The language code this collection's items were made in.",
}),
translations: TranslationRecord(
t.Intersect([
t.Composite([
t.Omit(CollectionTranslation, [
"poster",
"thumbnail",

View File

@ -12,7 +12,7 @@ import {
import { EmbeddedVideo } from "../video";
import { BaseEntry, EntryTranslation } from "./base-entry";
export const BaseEpisode = t.Intersect([
export const BaseEpisode = t.Composite([
t.Object({
kind: t.Literal("episode"),
order: t.Number({ minimum: 1, description: "Absolute playback order." }),
@ -23,7 +23,7 @@ export const BaseEpisode = t.Intersect([
BaseEntry(),
]);
export const Episode = t.Intersect([
export const Episode = t.Composite([
Resource(),
EntryTranslation(),
BaseEpisode,
@ -35,7 +35,7 @@ export const Episode = t.Intersect([
]);
export type Episode = Prettify<typeof Episode.static>;
export const SeedEpisode = t.Intersect([
export const SeedEpisode = t.Composite([
t.Omit(BaseEpisode, ["thumbnail", "nextRefresh"]),
t.Object({
thumbnail: t.Nullable(SeedImage),

View File

@ -16,7 +16,7 @@ export const ExtraType = t.UnionEnum([
]);
export type ExtraType = typeof ExtraType.static;
export const BaseExtra = t.Intersect(
export const BaseExtra = t.Composite(
[
t.Object({
kind: ExtraType,
@ -32,7 +32,7 @@ export const BaseExtra = t.Intersect(
},
);
export const Extra = t.Intersect([
export const Extra = t.Composite([
Resource(),
BaseExtra,
t.Object({
@ -42,7 +42,7 @@ export const Extra = t.Intersect([
]);
export type Extra = Prettify<typeof Extra.static>;
export const SeedExtra = t.Intersect([
export const SeedExtra = t.Composite([
t.Omit(BaseExtra, ["thumbnail"]),
t.Object({
slug: t.String({ format: "slug" }),

View File

@ -13,7 +13,7 @@ import {
import { EmbeddedVideo } from "../video";
import { BaseEntry, EntryTranslation } from "./base-entry";
export const BaseMovieEntry = t.Intersect(
export const BaseMovieEntry = t.Composite(
[
t.Object({
kind: t.Literal("movie"),
@ -33,7 +33,7 @@ export const BaseMovieEntry = t.Intersect(
},
);
export const MovieEntryTranslation = t.Intersect([
export const MovieEntryTranslation = t.Composite([
EntryTranslation(),
t.Object({
tagline: t.Nullable(t.String()),
@ -41,7 +41,7 @@ export const MovieEntryTranslation = t.Intersect([
}),
]);
export const MovieEntry = t.Intersect([
export const MovieEntry = t.Composite([
Resource(),
MovieEntryTranslation,
BaseMovieEntry,
@ -53,7 +53,7 @@ export const MovieEntry = t.Intersect([
]);
export type MovieEntry = Prettify<typeof MovieEntry.static>;
export const SeedMovieEntry = t.Intersect([
export const SeedMovieEntry = t.Composite([
t.Omit(BaseMovieEntry, ["thumbnail", "nextRefresh"]),
t.Object({
slug: t.Optional(t.String({ format: "slug" })),

View File

@ -12,7 +12,7 @@ import {
import { EmbeddedVideo } from "../video";
import { BaseEntry, EntryTranslation } from "./base-entry";
export const BaseSpecial = t.Intersect(
export const BaseSpecial = t.Composite(
[
t.Object({
kind: t.Literal("special"),
@ -33,7 +33,7 @@ export const BaseSpecial = t.Intersect(
},
);
export const Special = t.Intersect([
export const Special = t.Composite([
Resource(),
EntryTranslation(),
BaseSpecial,
@ -45,7 +45,7 @@ export const Special = t.Intersect([
]);
export type Special = Prettify<typeof Special.static>;
export const SeedSpecial = t.Intersect([
export const SeedSpecial = t.Composite([
t.Omit(BaseSpecial, ["thumbnail", "nextRefresh"]),
t.Object({
thumbnail: t.Nullable(SeedImage),

View File

@ -3,7 +3,6 @@ import type { Video } from "~/models/video";
export const bubbleVideo: Video = {
id: "3cd436ee-01ff-4f45-ba98-62aabeb22f25",
slug: "bubble",
path: "/video/Bubble/Bubble (2022).mkv",
rendering: "459429fa062adeebedcc2bb04b9965de0262bfa453369783132d261be79021bd",
part: null,

View File

@ -48,7 +48,7 @@ export const MovieTranslation = t.Object({
});
export type MovieTranslation = typeof MovieTranslation.static;
export const Movie = t.Intersect([
export const Movie = t.Composite([
Resource(),
MovieTranslation,
BaseMovie,
@ -71,7 +71,7 @@ export const FullMovie = t.Intersect([
]);
export type FullMovie = Prettify<typeof FullMovie.static>;
export const SeedMovie = t.Intersect([
export const SeedMovie = t.Composite([
t.Omit(BaseMovie, ["kind", "nextRefresh"]),
t.Object({
slug: t.String({ format: "slug", examples: ["bubble"] }),
@ -79,7 +79,7 @@ export const SeedMovie = t.Intersect([
description: "The language code this movie was made in.",
}),
translations: TranslationRecord(
t.Intersect([
t.Composite([
t.Omit(MovieTranslation, ["poster", "thumbnail", "banner", "logo"]),
t.Object({
poster: t.Nullable(SeedImage),

View File

@ -27,7 +27,7 @@ export const SeasonTranslation = t.Object({
});
export type SeasonTranslation = typeof SeasonTranslation.static;
export const Season = t.Intersect([
export const Season = t.Composite([
Resource(),
SeasonTranslation,
BaseSeason,
@ -35,11 +35,11 @@ export const Season = t.Intersect([
]);
export type Season = Prettify<typeof Season.static>;
export const SeedSeason = t.Intersect([
export const SeedSeason = t.Composite([
t.Omit(BaseSeason, ["nextRefresh"]),
t.Object({
translations: TranslationRecord(
t.Intersect([
t.Composite([
t.Omit(SeasonTranslation, ["poster", "thumbnail", "banner"]),
t.Object({
poster: t.Nullable(SeedImage),

View File

@ -58,7 +58,7 @@ export const SerieTranslation = t.Object({
});
export type SerieTranslation = typeof SerieTranslation.static;
export const Serie = t.Intersect([
export const Serie = t.Composite([
Resource(),
SerieTranslation,
BaseSerie,
@ -87,7 +87,7 @@ export const FullSerie = t.Intersect([
]);
export type FullSerie = Prettify<typeof FullSerie.static>;
export const SeedSerie = t.Intersect([
export const SeedSerie = t.Composite([
t.Omit(BaseSerie, ["kind", "nextRefresh"]),
t.Object({
slug: t.String({ format: "slug" }),
@ -95,7 +95,7 @@ export const SeedSerie = t.Intersect([
description: "The language code this serie was made in.",
}),
translations: TranslationRecord(
t.Intersect([
t.Composite([
t.Omit(SerieTranslation, ["poster", "thumbnail", "banner", "logo"]),
t.Object({
poster: t.Nullable(SeedImage),

View File

@ -4,7 +4,7 @@ import { Movie } from "./movie";
import { Serie } from "./serie";
export const Show = t.Union([
t.Intersect([Movie, t.Object({ kind: t.Literal("movie") })]),
t.Intersect([Serie, t.Object({ kind: t.Literal("serie") })]),
t.Intersect([Collection, t.Object({ kind: t.Literal("collection") })]),
t.Composite([t.Object({ kind: t.Literal("movie") }), Movie]),
t.Composite([t.Object({ kind: t.Literal("serie") }), Serie]),
t.Composite([t.Object({ kind: t.Literal("collection") }), Collection]),
]);

View File

@ -28,19 +28,19 @@ const StaffData = t.Object({
image: t.Nullable(Image),
externalId: ExternalId(),
});
export const Staff = t.Intersect([Resource(), StaffData, DbMetadata]);
export const Staff = t.Composite([Resource(), StaffData, DbMetadata]);
export type Staff = typeof Staff.static;
export const SeedStaff = t.Intersect([
export const SeedStaff = t.Composite([
t.Omit(Role, ["character"]),
t.Object({
character: t.Intersect([
character: t.Composite([
t.Omit(Character, ["image"]),
t.Object({
image: t.Nullable(SeedImage),
}),
]),
staff: t.Intersect([
staff: t.Composite([
t.Object({
slug: t.String({ format: "slug" }),
image: t.Nullable(SeedImage),

View File

@ -14,7 +14,7 @@ export const StudioTranslation = t.Object({
});
export type StudioTranslation = typeof StudioTranslation.static;
export const Studio = t.Intersect([
export const Studio = t.Composite([
Resource(),
StudioTranslation,
BaseStudio,
@ -22,12 +22,12 @@ export const Studio = t.Intersect([
]);
export type Studio = Prettify<typeof Studio.static>;
export const SeedStudio = t.Intersect([
export const SeedStudio = t.Composite([
BaseStudio,
t.Object({
slug: t.String({ format: "slug" }),
translations: TranslationRecord(
t.Intersect([
t.Composite([
t.Omit(StudioTranslation, ["logo"]),
t.Object({
logo: t.Nullable(SeedImage),

View File

@ -113,7 +113,7 @@ export const SeedVideo = t.Object({
});
export type SeedVideo = Prettify<typeof SeedVideo.static>;
export const Video = t.Intersect([
export const Video = t.Composite([
t.Object({
id: t.String({ format: "uuid" }),
}),
@ -123,7 +123,7 @@ export const Video = t.Intersect([
export type Video = Prettify<typeof Video.static>;
// type used in entry responses (the slug comes from the entryVideoJoin)
export const EmbeddedVideo = t.Intersect([
export const EmbeddedVideo = t.Composite([
t.Object({ slug: t.String({ format: "slug" }) }),
t.Omit(Video, ["guess", "createdAt", "updatedAt"]),
]);

View File

@ -20,7 +20,7 @@ export const SerieWatchStatus = t.Object({
});
export type SerieWatchStatus = typeof SerieWatchStatus.static;
export const MovieWatchStatus = t.Intersect([
export const MovieWatchStatus = t.Composite([
t.Omit(SerieWatchStatus, ["startedAt", "seenCount"]),
t.Object({
percent: t.Integer({