✨ feat(actions): meta.openapi für Aktionen typisieren und validieren (#40)
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
Aktionen erscheinen in der generierten OpenAPI-Spec als /_actions/<name>. Dafür trägt die Action-Meta jetzt denselben openapi-Block wie eine Sammlung: - action.schema.json: meta.openapi referenziert openapi.schema.json (bisher lehnte additionalProperties: false den Block ab). - openapi.schema.json: Beschreibung deckt Sammlung und Aktion ab, get/getOne/ post/put/delete sind entsprechend erläutert. - index.d.ts: ActionMeta.openapi plus OpenapiMeta/OpenapiOperationMeta/ OpenapiParameter. - demo-api/actions/demo-action.yml und types-test/action-openapi.ts zeigen und prüfen die Form.
This commit is contained in:
1 parent
4e13d4ab9a
commit
11069d83d4
5 files changed
+110
-8
No files matched your search
@@ -0,0 +1,47 @@
|
||||
// Compile-time contract test for the action OpenAPI overrides (#40): an action
|
||||
// meta carries the same meta.openapi block a collection uses.
|
||||
|
||||
const meta: ActionMeta = {
|
||||
label: { de: "Kontaktformular", en: "Contact Form" },
|
||||
openapi: {
|
||||
disabled: false,
|
||||
get: {
|
||||
summary: { de: "Formular abrufen", en: "Get the form" },
|
||||
parameters: [
|
||||
{
|
||||
name: "lang",
|
||||
in: "query",
|
||||
required: false,
|
||||
schema: { type: "string" },
|
||||
},
|
||||
],
|
||||
responses: { "200": { description: "OK" } },
|
||||
security: [{ "X-Api-Token": [] }],
|
||||
},
|
||||
post: {
|
||||
summary: { de: "Formular senden", en: "Submit the form" },
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const info: ActionInfo = {
|
||||
name: "contact-form",
|
||||
meta,
|
||||
permissions: {
|
||||
public: { methods: { post: { allow: true } } },
|
||||
},
|
||||
}
|
||||
|
||||
type _MetaIsOpenapi = Expect<Equal<NonNullable<ActionInfo["meta"]>["openapi"], OpenapiMeta | undefined>>
|
||||
type _SummaryIsLocalized = Expect<Equal<NonNullable<OpenapiMeta["get"]>["summary"], LocalizedText | undefined>>
|
||||
|
||||
const disabled: boolean | undefined = meta.openapi?.post?.disabled
|
||||
type _DisabledIsBoolean = Expect<Equal<typeof disabled, boolean | undefined>>
|
||||
|
||||
// @ts-expect-error `in` is limited to the OpenAPI parameter locations
|
||||
const badParameter: OpenapiParameter = { name: "lang", in: "body" }
|
||||
|
||||
declare const expectTrue: Expect<true>
|
||||
void expectTrue
|
||||
void info
|
||||
void badParameter
|
||||
Reference in new issue
Block a user