forked from extern/bruno
feat: bruno lang - support parsing text body
This commit is contained in:
parent
24e11a864c
commit
a645d1459c
@ -12,6 +12,9 @@ const bodyJsonBegin = regex(/^body\s*\(\s*type\s*=\s*json\s*\)\s*\r?\n/);
|
||||
// body(type=graphql)
|
||||
const bodyGraphqlBegin = regex(/^body\s*\(\s*type\s*=\s*graphql\s*\)\s*\r?\n/);
|
||||
|
||||
// body(type=text)
|
||||
const bodyTextBegin = regex(/^body\s*\(\s*type\s*=\s*text\s*\)\s*\r?\n/);
|
||||
|
||||
const bodyEnd = regex(/^\/body\s*[\r?\n]*/);
|
||||
|
||||
const bodyJsonTag = between(bodyJsonBegin)(bodyEnd)(everyCharUntil(bodyEnd)).map((bodyJson) => {
|
||||
@ -51,7 +54,16 @@ const bodyGraphqlTag = between(bodyGraphqlBegin)(bodyEnd)(everyCharUntil(bodyEnd
|
||||
}
|
||||
});
|
||||
|
||||
const bodyTextTag = between(bodyTextBegin)(bodyEnd)(everyCharUntil(bodyEnd)).map((bodyText) => {
|
||||
return {
|
||||
body: {
|
||||
text: bodyText
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
bodyJsonTag,
|
||||
bodyGraphqlTag
|
||||
bodyGraphqlTag,
|
||||
bodyTextTag
|
||||
};
|
||||
|
@ -10,7 +10,8 @@ const paramsTag = require('./params-tag');
|
||||
const headersTag = require('./headers-tag');
|
||||
const {
|
||||
bodyJsonTag,
|
||||
bodyGraphqlTag
|
||||
bodyGraphqlTag,
|
||||
bodyTextTag
|
||||
} = require('./body-tag');
|
||||
|
||||
const bruToJson = (fileContents) => {
|
||||
@ -20,6 +21,7 @@ const bruToJson = (fileContents) => {
|
||||
headersTag,
|
||||
bodyJsonTag,
|
||||
bodyGraphqlTag,
|
||||
bodyTextTag,
|
||||
anyChar
|
||||
]));
|
||||
|
||||
|
@ -32,3 +32,7 @@ body(type=graphql)
|
||||
}
|
||||
/body
|
||||
|
||||
body(type=text)
|
||||
Hello, there. You must be from the past
|
||||
/body
|
||||
|
||||
|
@ -54,7 +54,8 @@ describe('bruToJson', () => {
|
||||
"json": '{"apikey":"secret","numbers":"+91998877665"}',
|
||||
"graphql": {
|
||||
"query": " {\n launchesPast {\n launch_success\n }\n }\n"
|
||||
}
|
||||
},
|
||||
"text": " Hello, there. You must be from the past\n"
|
||||
}
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user