Add new Swagger Doc for the pusher

This commit is contained in:
CEC
2022-04-28 11:39:08 +02:00
parent 231facbae2
commit 53b084ea7f
15 changed files with 498 additions and 71 deletions
+6 -4
View File
@@ -1,4 +1,5 @@
import { z } from "zod";
import {extendApi} from "@anatine/zod-openapi";
/*
* WARNING! The original file is in /messages/JsonMessages.
@@ -6,10 +7,11 @@ import { z } from "zod";
*/
export const isAdminApiData = z.object({
userUuid: z.string(),
email: z.nullable(z.string()),
roomUrl: z.string(),
mapUrlStart: z.string(),
// @ts-ignore
userUuid: extendApi(z.string(), {example: '998ce839-3dea-4698-8b41-ebbdf7688ad9'}),
email: extendApi(z.nullable(z.string()), {description: 'The email of the current user.', example: 'example@workadventu.re'}),
roomUrl: extendApi(z.string(), {example: '/@/teamSlug/worldSlug/roomSlug'}),
mapUrlStart: extendApi(z.string(), {description: 'The full URL to the JSON map file', example: 'https://myuser.github.io/myrepo/map.json'}),
messages: z.optional(z.array(z.unknown())),
});
+55 -32
View File
@@ -1,46 +1,69 @@
import { z } from "zod";
import {extendApi} from "@anatine/zod-openapi";
/*
* WARNING! The original file is in /messages/JsonMessages.
* All other files are automatically copied from this file on container startup / build
*/
export const isErrorApiErrorData = z.object({
export const isErrorApiErrorData = extendApi(
// @ts-ignore
type: z.literal("error"),
code: z.string(),
title: z.string(),
subtitle: z.string(),
details: z.string(),
image: z.string(),
});
z.object({
type: z.literal("error"),
code: extendApi(z.string(), {description: 'The system code of an error, it must be in SCREAMING_SNAKE_CASE.', example: 'ROOM_NOT_FOUND'}),
title: extendApi(z.string(), {description: "Big title displayed on the error screen.", example: "ERROR"}),
subtitle: extendApi(z.string(), {description: "Subtitle displayed to let the user know what is the main subject of the error.", example: "The room was not found."}),
details: extendApi(z.string(), {description: "Some others details on what the user can do if he don't understand the error.", example: "If you would like more information, you can contact the administrator or us at example@workadventu.re."}),
image: extendApi(z.string(), {description: "The URL of the image displayed just under the logo in the error screen.", example: 'https://example.com/error.png'}),
}),
{
description: 'This is an error that can be returned by the API, its type must be equal to "error".\n If such an error is caught, an error screen will be displayed.',
}
);
export const isErrorApiRetryData = z.object({
type: z.literal("retry"),
code: z.string(),
title: z.string(),
subtitle: z.string(),
details: z.string(),
image: z.string(),
buttonTitle: z.optional(z.nullable(z.string())),
timeToRetry: z.number(),
canRetryManual: z.boolean(),
});
export const isErrorApiRetryData = extendApi(
z.object({
type: z.literal("retry"),
code: extendApi(z.string(), {description: 'The system code of an error, it must be in SCREAMING_SNAKE_CASE. \n It will not be displayed to the user.', example: 'WORLD_FULL'}),
title: extendApi(z.string(), {description: "Big title displayed on the error screen.", example: "ERROR"}),
subtitle: extendApi(z.string(), {description: "Subtitle displayed to let the user know what is the main subject of the error.", example: "Too successful, your WorkAdventure world is full!"}),
details: extendApi(z.string(), {description: "Some others details on what the user can do if he don't understand the error.", example: "New automatic attempt in 30 seconds"}),
image: extendApi(z.string(), {description: "The URL of the image displayed just under the logo in the waiting screen.", example: 'https://example.com/wait.png'}),
buttonTitle: extendApi(z.optional(z.nullable(z.string())), {description: "If this is not defined the button and the parameter canRetryManual is set to true, the button will be not displayed at all.", example: "Retry"}),
timeToRetry: extendApi(z.number(), {description: "This is the time (in millisecond) between the next auto refresh of the page.", example: 30_000}),
canRetryManual: extendApi(z.boolean(), {description: "This boolean show or hide the button to let the user refresh manually the current page.", example: true}),
}),
{
description: 'This is an error that can be returned by the API, its type must be equal to "retry".\n' +
'If such an error is caught, a waiting screen will be displayed.',
}
);
export const isErrorApiRedirectData = z.object({
type: z.literal("redirect"),
urlToRedirect: z.string(),
});
export const isErrorApiRedirectData = extendApi(
z.object({
type: z.literal("redirect"),
urlToRedirect: extendApi(z.string(), {description: 'A URL specified to redirect the user onto it directly', example: '/contact-us'}),
}),
{
description: 'This is an error that can be returned by the API, its type must be equal to "redirect".\n' +
'If such an error is caught, the user will be automatically redirected to urlToRedirect.',
}
);
export const isErrorApiUnauthorizedData = z.object({
type: z.literal("unauthorized"),
code: z.string(),
title: z.string(),
subtitle: z.string(),
details: z.string(),
image: z.string(),
buttonTitle: z.optional(z.nullable(z.string())),
});
export const isErrorApiUnauthorizedData = extendApi(
z.object({
type: z.literal("unauthorized"),
code: extendApi(z.string(), {description: "This is the system code of an error, it must be in SCREAMING_SNAKE_CASE.", example: "USER_ACCESS_FORBIDDEN"}),
title: extendApi(z.string(), {description: "Big title displayed on the error screen.", example: "ERROR"}),
subtitle: extendApi(z.string(), {description: "Subtitle displayed to let the user know what is the main subject of the error.", example: "You can't access this place."}),
details: extendApi(z.string(), {description: "Some others details on what the user can do if he don't understand the error.", example: "If you would like more information, you can contact the administrator or us at example@workadventu.re."}),
image: extendApi(z.string(), {description: "The URL of the image displayed just under the logo in the error screen.", example: 'https://example.com/error.png'}),
buttonTitle: extendApi(z.optional(z.nullable(z.string())), {description: "If this is not defined the button to logout will be not displayed.", example: "Log out"}),
}),
{
description: 'This is an error that can be returned by the API, its type must be equal to "unauthorized".\n' +
'If such an error is caught, an error screen will be displayed with a button to let him logout and go to login page.',
});
export const isErrorApiData = z.discriminatedUnion("type", [
isErrorApiErrorData,
+11 -9
View File
@@ -1,4 +1,5 @@
import { z } from "zod";
import {extendApi} from "@anatine/zod-openapi";
/*
* WARNING! The original file is in /messages/JsonMessages.
@@ -6,20 +7,21 @@ import { z } from "zod";
*/
export const isMapDetailsData = z.object({
mapUrl: z.string(),
authenticationMandatory: z.optional(z.nullable(z.boolean())),
group: z.nullable(z.string()),
// @ts-ignore
mapUrl: extendApi(z.string(), {description: 'The full URL to the JSON map file', example: 'https://myuser.github.io/myrepo/map.json'}),
authenticationMandatory: extendApi(z.optional(z.nullable(z.boolean())), {description: 'Whether the authentication is mandatory or not for this map', example: true}),
group: extendApi(z.nullable(z.string()), {description: 'The group this room is part of (maps the notion of "world" in WorkAdventure SAAS)', example: 'myorg/myworld'}),
contactPage: z.optional(z.nullable(z.string())),
iframeAuthentication: z.optional(z.nullable(z.string())),
contactPage: extendApi(z.optional(z.nullable(z.string())), {description: 'The URL to the contact page', example: 'https://mycompany.com/contact-us'}),
iframeAuthentication: extendApi(z.optional(z.nullable(z.string())), {description: 'The URL of the authentication Iframe', example: 'https://mycompany.com/authc'}),
// The date (in ISO 8601 format) at which the room will expire
expireOn: z.optional(z.string()),
expireOn: extendApi(z.optional(z.string()), {description: 'The date (in ISO 8601 format) at which the room will expire', example: '2022-11-05T08:15:30-05:00'}),
// Whether the "report" feature is enabled or not on this room
canReport: z.optional(z.boolean()),
canReport: extendApi(z.optional(z.boolean()), {description: 'Whether the "report" feature is enabled or not on this room', example: true}),
// The URL of the logo image on the loading screen
loadingLogo: z.optional(z.nullable(z.string())),
loadingLogo: extendApi(z.optional(z.nullable(z.string())), {description: 'The URL of the image to be used on the loading page', example: 'https://example.com/logo.png'}),
// The URL of the logo image on "LoginScene"
loginSceneLogo: z.optional(z.nullable(z.string())),
loginSceneLogo: extendApi(z.optional(z.nullable(z.string())), {description: 'The URL of the image to be used on the LoginScene', example: 'https://example.com/logo_login.png'}),
});
export type MapDetailsData = z.infer<typeof isMapDetailsData>;
+2
View File
@@ -18,8 +18,10 @@
"pretty-check": "yarn prettier --check 'JsonMessages/**/*.ts'"
},
"dependencies": {
"@anatine/zod-openapi": "^1.3.0",
"google-protobuf": "^3.13.0",
"grpc": "^1.24.4",
"openapi3-ts": "^2.0.2",
"ts-proto": "^1.96.0",
"zod": "^3.14.3"
},
+26 -1
View File
@@ -2,6 +2,14 @@
# yarn lockfile v1
"@anatine/zod-openapi@^1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@anatine/zod-openapi/-/zod-openapi-1.3.0.tgz#b5b38c3d821b79674226aa7b327c88c371860d0d"
integrity sha512-l54DypUdDsIq1Uwjv4ib9IBkTXMKZQLUj7qvdFL51EExC5LdSSqOlTOyaVVZZGYgWPKM7ZjGklhdoknLz4EC+w==
dependencies:
ts-deepmerge "^1.1.0"
validator "^13.7.0"
"@babel/code-frame@^7.0.0":
version "7.10.4"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.10.4.tgz#168da1a36e90da68ae8d49c0f1b48c7c6249213a"
@@ -3241,6 +3249,13 @@ onetime@^5.1.0, onetime@^5.1.2:
dependencies:
mimic-fn "^2.1.0"
openapi3-ts@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/openapi3-ts/-/openapi3-ts-2.0.2.tgz#a200dd838bf24c9086c8eedcfeb380b7eb31e82a"
integrity sha512-TxhYBMoqx9frXyOgnRHufjQfPXomTIHYKhSKJ6jHfj13kS8OEIhvmE8CTuQyKtjjWttAjX5DPxM1vmalEpo8Qw==
dependencies:
yaml "^1.10.2"
optionator@^0.9.1:
version "0.9.1"
resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.9.1.tgz#4f236a6373dae0566a6d43e1326674f50c291499"
@@ -4284,6 +4299,11 @@ tough-cookie@~2.5.0:
psl "^1.1.28"
punycode "^2.1.1"
ts-deepmerge@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/ts-deepmerge/-/ts-deepmerge-1.1.0.tgz#4236ae102199affe2e77690dcf198a420160eef2"
integrity sha512-VvwaV/6RyYMwT9d8dClmfHIsG2PCdm6WY430QKOIbPRR50Y/1Q2ilp4i2XEZeHFcNqfaYnAQzpyUC6XA0AqqBg==
ts-poet@^4.5.0:
version "4.6.1"
resolved "https://registry.yarnpkg.com/ts-poet/-/ts-poet-4.6.1.tgz#015dc823d726655af9f095c900f84ed7c60e2dd3"
@@ -4487,6 +4507,11 @@ validate-npm-package-name@^3.0.0:
dependencies:
builtins "^1.0.3"
validator@^13.7.0:
version "13.7.0"
resolved "https://registry.yarnpkg.com/validator/-/validator-13.7.0.tgz#4f9658ba13ba8f3d82ee881d3516489ea85c0857"
integrity sha512-nYXQLCBkpJ8X6ltALua9dRrZDHVYxjJ1wgskNt1lH9fzGjs3tgojGSCBjmEPwkWS1y29+DrizMTW19Pr9uB2nw==
verror@1.10.0:
version "1.10.0"
resolved "https://registry.yarnpkg.com/verror/-/verror-1.10.0.tgz#3a105ca17053af55d6e270c1f8288682e18da400"
@@ -4593,7 +4618,7 @@ yallist@^3.0.0, yallist@^3.0.3:
resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.1.1.tgz#dbb7daf9bfd8bac9ab45ebf602b8cbad0d5d08fd"
integrity sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==
yaml@^1.10.0:
yaml@^1.10.0, yaml@^1.10.2:
version "1.10.2"
resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.2.tgz#2301c5ffbf12b467de8da2333a459e29e7920e4b"
integrity sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==