chore: fix lang constructs

This commit is contained in:
Siddharth Gelera
2025-09-25 15:56:22 +05:30
parent 7b89ccebf5
commit f4dce1e44e
2 changed files with 38 additions and 2 deletions

View File

@@ -29,7 +29,7 @@ const { safeParseJson, outdentString } = require('./utils');
*
*/
const grammar = ohm.grammar(`Bru {
BruFile = (meta | http | grpc | query | params | headers | metadata | auths | bodies | varsandassert | script | tests | settings | docs)*
BruFile = (meta | http | grpc | ws | query | params | headers | metadata | auths | bodies | varsandassert | script | tests | settings | docs)*
auths = authawsv4 | authbasic | authbearer | authdigest | authNTLM | authOAuth2 | authwsse | authapikey | authOauth2Configs
bodies = bodyjson | bodytext | bodyxml | bodysparql | bodygraphql | bodygraphqlvars | bodyforms | body | bodygrpc
bodyforms = bodyformurlencoded | bodymultipart | bodyfile
@@ -88,6 +88,7 @@ const grammar = ohm.grammar(`Bru {
http = get | post | put | delete | patch | options | head | connect | trace | httpcustom
grpc = "grpc" dictionary
ws = "ws" dictionary
get = "get" dictionary
post = "post" dictionary
put = "put" dictionary
@@ -420,6 +421,11 @@ const sem = grammar.createSemantics().addAttribute('ast', {
grpc: mapPairListToKeyValPair(dictionary.ast)
};
},
ws(_1, dictionary) {
return {
ws: mapPairListToKeyValPair(dictionary.ast)
};
},
get(_1, dictionary) {
return {
http: {

View File

@@ -17,7 +17,7 @@ const stripLastLine = (text) => {
};
const jsonToBru = (json) => {
const { meta, http, grpc, params, headers, metadata, auth, body, script, tests, vars, assertions, settings, docs } = json;
const { meta, http, grpc, ws, params, headers, metadata, auth, body, script, tests, vars, assertions, settings, docs } = json;
let bru = '';
@@ -95,6 +95,36 @@ const jsonToBru = (json) => {
bru += `
}
`;
}
if (ws && ws.url) {
bru += `ws {
url: ${ws.url}`;
if (ws.method && ws.method.length) {
bru += `
method: ${ws.method}`;
}
if (ws.body && ws.body.length) {
bru += `
body: ${ws.body}`;
}
if (ws.auth && ws.auth.length) {
bru += `
auth: ${ws.auth}`;
}
if (ws.methodType && ws.methodType.length) {
bru += `
methodType: ${ws.methodType}`;
}
bru += `
}
`;
}