Skip to content

Instantly share code, notes, and snippets.

@dansp89
Last active December 9, 2023 04:42
Show Gist options
  • Save dansp89/876da81fd32e4bc7dcbb440eebc3a51e to your computer and use it in GitHub Desktop.
Save dansp89/876da81fd32e4bc7dcbb440eebc3a51e to your computer and use it in GitHub Desktop.
Strapi 4 - Override swagger default (E.G TS): ./src/index.ts
export default {
/**
* @file ./src/index.ts
* An asynchronous register function that runs before
* your application is initialized.
*
* This gives you an opportunity to extend code.
* @source <https://docs.strapi.io/dev-docs/plugins/documentation#providing-replacement-documentation>
*/
register({ strapi }) {
if (strapi.plugin('documentation')) {
const override = {
// Only run this override for version 1.0.0
info: { version: '1.0.0' },
paths: {
"/users-x/find/email/{email}": {
"get": {
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UserXResponse"
}
}
}
},
"400": {
"description": "Bad Request",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"401": {
"description": "Unauthorized",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"403": {
"description": "Forbidden",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"404": {
"description": "Not Found",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"500": {
"description": "Internal Server Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
},
"tags": [
"User-x"
],
"parameters": [
{
"name": "email",
"in": "path",
"description": "",
"deprecated": false,
"required": true,
"schema": {
"type": "string"
}
}
],
"operationId": "get/users-x/find/email/{email}"
}
},
"/users-x/find/username/{username}": {
"get": {
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UserXResponse"
}
}
}
},
"400": {
"description": "Bad Request",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"401": {
"description": "Unauthorized",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"403": {
"description": "Forbidden",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"404": {
"description": "Not Found",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"500": {
"description": "Internal Server Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
},
"tags": [
"User-x"
],
"parameters": [
{
"name": "username",
"in": "path",
"description": "",
"deprecated": false,
"required": true,
"schema": {
"type": "string"
}
}
],
"operationId": "get/users-x/find/username/{username}"
}
},
},
}
strapi
.plugin('documentation')
.service('override')
.registerOverride(override, { });
}
},
/**
* An asynchronous bootstrap function that runs before
* your application gets started.
*
* This gives you an opportunity to set up your data model,
* run jobs, or perform some special logic.
*/
bootstrap(/*{ strapi }*/) {},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment