Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/api/apim-config/content-types/apim-config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"environmentId": {
"type": "string"
},
"platform": {
"provider": {
"type": "enumeration",
"enum": [
"MuleSoft",
Expand Down
4 changes: 4 additions & 0 deletions src/api/apim-config/controllers/apim-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ module.exports = createCoreController('api::apim-config.apim-config', ({strapi})
where: {slug}
})

if (!entity) {
return ctx.notFound('Configuration not found');
}

const sanitizedEntity = await this.sanitizeOutput(entity);
return this.transformResponse(sanitizedEntity);
}
Expand Down
15 changes: 12 additions & 3 deletions src/api/library-api/content-types/library-api/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"slug": {
"type": "uid"
},
"provider": {
"type": "string"
},
"description": {
"type": "text"
},
Expand Down Expand Up @@ -50,13 +53,19 @@
},
"openDocType": {
"type": "enumeration",
"enum": ["api", "asyncapi"],
"enum": [
"api",
"asyncapi"
],
"required": true,
"default": "api"
},
"openDocFormat": {
"type": "enumeration",
"enum": ["json", "yaml"],
"enum": [
"json",
"yaml"
],
"required": true,
"default": "json"
},
Expand Down Expand Up @@ -108,4 +117,4 @@
]
}
}
}
}
21 changes: 5 additions & 16 deletions src/api/library-api/controllers/library-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,13 @@ module.exports = createCoreController('api::library-api.library-api', ({ strapi
return response;
},

async find(ctx) {
await strapi.service('api::library-api.library-api').syncFromIntegrator();
return await super.find(ctx);
},

async findOne(ctx) {
const response = await super.findOne(ctx);

const entity = response?.data;
const attrs = entity?.attributes;

if (attrs?.openDoc && attrs?.openDocFormat) {
try {
attrs.openDocParsed = parseOpenDoc(
attrs.openDoc,
attrs.openDocFormat
);
} catch (err) {
attrs.openDocParsed = null;
attrs.openDocParseError = err.message;
}
}

return response;
},
})
Expand Down
53 changes: 52 additions & 1 deletion src/api/library-api/services/library-api.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,53 @@
'use strict';

const { createCoreService } = require('@strapi/strapi').factories;
module.exports = createCoreService('api::library-api.library-api')
const axios = require('axios');

module.exports = createCoreService('api::library-api.library-api', ({ strapi }) => ({
async syncFromIntegrator() {
const configs = await strapi.db.query('api::apim-config.apim-config').findMany({
where: { active: true }
});

const integratorUrl = process.env.INTEGRATOR_URL;
const integratorApiKey = process.env.INTEGRATOR_KONG_API_KEY;

for (const config of configs) {
try {
const response = await axios.get(`${integratorUrl}/list-apis`, {
headers: {
'x-apimanager-id': config.provider,
'apiKey': integratorApiKey
}
});

const externalApis = response.data;

for (const api of externalApis) {
const existing = await strapi.db.query('api::library-api.library-api').findOne({
where: { slug: api.slug }
});

const data = {
...api,
provider: config.provider,
publishedAt: new Date(),
};

if (existing) {
await strapi.db.query('api::library-api.library-api').update({
where: { id: existing.id },
data
});
} else {
await strapi.db.query('api::library-api.library-api').create({
data
});
}
}
} catch (error) {
strapi.log.error(`Error ${config.provider}: ${error.message}`);
}
}
}
}));
Original file line number Diff line number Diff line change
Expand Up @@ -6133,6 +6133,9 @@
"slug": {
"type": "string"
},
"provider": {
"type": "string"
},
"description": {
"type": "string"
},
Expand Down Expand Up @@ -7589,6 +7592,9 @@
"slug": {
"type": "string"
},
"provider": {
"type": "string"
},
"description": {
"type": "string"
},
Expand Down Expand Up @@ -7796,6 +7802,9 @@
"slug": {
"type": "string"
},
"provider": {
"type": "string"
},
"description": {
"type": "string"
},
Expand Down Expand Up @@ -8738,6 +8747,9 @@
"slug": {
"type": "string"
},
"provider": {
"type": "string"
},
"description": {
"type": "string"
},
Expand Down
3 changes: 2 additions & 1 deletion types/generated/contentTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ export interface ApiApimConfigApimConfig extends Struct.CollectionTypeSchema {
Schema.Attribute.Private;
name: Schema.Attribute.String;
organizationId: Schema.Attribute.String;
platform: Schema.Attribute.Enumeration<['MuleSoft', 'Azure']> &
provider: Schema.Attribute.Enumeration<['MuleSoft', 'Azure']> &
Schema.Attribute.Required &
Schema.Attribute.DefaultTo<'MuleSoft'>;
publishedAt: Schema.Attribute.DateTime;
Expand Down Expand Up @@ -649,6 +649,7 @@ export interface ApiLibraryApiLibraryApi extends Struct.CollectionTypeSchema {
Schema.Attribute.DefaultTo<'api'>;
openDocUrl: Schema.Attribute.String;
products: Schema.Attribute.Relation<'manyToMany', 'api::product.product'>;
provider: Schema.Attribute.String;
publish: Schema.Attribute.Enumeration<['publicado', 'noPublicado']>;
publishedAt: Schema.Attribute.DateTime;
qualityRating: Schema.Attribute.Enumeration<['A', 'B', 'C', 'D', 'E']>;
Expand Down