MCPcopy
hub / github.com/usebruno/bruno / jsonToBru

Function jsonToBru

packages/bruno-lang/v2/src/jsonToBru.js:16–781  ·  view source on GitHub ↗
(json)

Source from the content-addressed store, hash-verified

14};
15
16const jsonToBru = (json) => {
17 const { meta, http, grpc, ws, params, headers, metadata, auth, body, script, tests, vars, assertions, settings, docs, examples } = json;
18
19 let bru = '';
20
21 if (meta) {
22 bru += 'meta {\n';
23
24 const tags = meta.tags;
25 delete meta.tags;
26
27 for (const key in meta) {
28 bru += ` ${key}: ${meta[key]}\n`;
29 }
30
31 if (tags && tags.length) {
32 bru += ` tags: [\n`;
33 for (const tag of tags) {
34 bru += ` ${tag}\n`;
35 }
36 bru += ` ]\n`;
37 }
38
39 bru += '}\n\n';
40 }
41
42 if (http?.method) {
43 const { method, url, body, auth } = http;
44 const standardMethods = new Set(['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace', 'connect']);
45
46 const isStandard = standardMethods.has(method);
47
48 bru += isStandard ? `${method} {` : `http {\n method: ${method}`;
49 bru += `\n url: ${getValueUrl(url)}`;
50
51 if (body?.length) {
52 bru += `\n body: ${body}`;
53 }
54
55 if (auth?.length) {
56 bru += `\n auth: ${auth}`;
57 }
58
59 bru += `\n}\n\n`;
60 }
61
62 if (grpc && grpc.url) {
63 bru += `grpc {
64 url: ${grpc.url}`;
65
66 if (grpc.method && grpc.method.length) {
67 bru += `
68 method: ${grpc.method}`;
69 }
70
71 if (grpc.body && grpc.body.length) {
72 bru += `
73 body: ${grpc.body}`;

Callers 6

index.spec.jsFile · 0.50
oauth1.spec.jsFile · 0.50
settings.spec.jsFile · 0.50
examples.spec.jsFile · 0.50

Calls 14

getValueUrlFunction · 0.85
serializeAnnotationsFunction · 0.85
getKeyStringFunction · 0.85
getValueStringFunction · 0.85
jsonToExampleBruFunction · 0.85
enabledFunction · 0.70
indentStringFunction · 0.70
disabledFunction · 0.70
stripLastLineFunction · 0.70
hasMethod · 0.45
filterMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected