MCPcopy Create free account
hub / github.com/BrasilAPI/BrasilAPI / getJsonDoc

Function getJsonDoc

services/getJsonDoc.js:7–43  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5const docsDirectory = path.join(process.cwd(), 'pages/docs/doc');
6
7export function getJsonDoc() {
8 let spec = {};
9
10 const files = fs.readdirSync(docsDirectory);
11 const tags = [];
12 files.forEach((file) => {
13 if (file.split('.').pop() === 'json') {
14 const fullPath = path.join(docsDirectory, file);
15
16 const content = JSON.parse(fs.readFileSync(fullPath, 'utf-8'));
17 spec = merge(spec, content);
18
19 // Seção de tags sendo tratada dentro de um foreach pois o merge dos
20 // arrays estava trazendo problemas com repetição de tags e sobrescrevendo outras.
21 if (content.tags) {
22 Object.values(content.tags).forEach((tag) => {
23 tags.push(tag);
24 });
25 }
26 }
27 });
28
29 spec.tags = tags;
30
31 spec.tags.sort((a, b) => {
32 if (a.name.toLowerCase() === 'termos de uso') {
33 return -1;
34 }
35 if (b.name.toLowerCase() === 'termos de uso') {
36 return 1;
37 }
38
39 return a.name.localeCompare(b.name, 'pt-br');
40 });
41
42 return spec;
43}

Callers 1

getServerSidePropsFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected