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)
|
// body(type=graphql)
|
||||||
const bodyGraphqlBegin = regex(/^body\s*\(\s*type\s*=\s*graphql\s*\)\s*\r?\n/);
|
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 bodyEnd = regex(/^\/body\s*[\r?\n]*/);
|
||||||
|
|
||||||
const bodyJsonTag = between(bodyJsonBegin)(bodyEnd)(everyCharUntil(bodyEnd)).map((bodyJson) => {
|
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 = {
|
module.exports = {
|
||||||
bodyJsonTag,
|
bodyJsonTag,
|
||||||
bodyGraphqlTag
|
bodyGraphqlTag,
|
||||||
|
bodyTextTag
|
||||||
};
|
};
|
||||||
|
@ -10,7 +10,8 @@ const paramsTag = require('./params-tag');
|
|||||||
const headersTag = require('./headers-tag');
|
const headersTag = require('./headers-tag');
|
||||||
const {
|
const {
|
||||||
bodyJsonTag,
|
bodyJsonTag,
|
||||||
bodyGraphqlTag
|
bodyGraphqlTag,
|
||||||
|
bodyTextTag
|
||||||
} = require('./body-tag');
|
} = require('./body-tag');
|
||||||
|
|
||||||
const bruToJson = (fileContents) => {
|
const bruToJson = (fileContents) => {
|
||||||
@ -20,6 +21,7 @@ const bruToJson = (fileContents) => {
|
|||||||
headersTag,
|
headersTag,
|
||||||
bodyJsonTag,
|
bodyJsonTag,
|
||||||
bodyGraphqlTag,
|
bodyGraphqlTag,
|
||||||
|
bodyTextTag,
|
||||||
anyChar
|
anyChar
|
||||||
]));
|
]));
|
||||||
|
|
||||||
|
@ -32,3 +32,7 @@ body(type=graphql)
|
|||||||
}
|
}
|
||||||
/body
|
/body
|
||||||
|
|
||||||
|
body(type=text)
|
||||||
|
Hello, there. You must be from the past
|
||||||
|
/body
|
||||||
|
|
||||||
|
@ -54,7 +54,8 @@ describe('bruToJson', () => {
|
|||||||
"json": '{"apikey":"secret","numbers":"+91998877665"}',
|
"json": '{"apikey":"secret","numbers":"+91998877665"}',
|
||||||
"graphql": {
|
"graphql": {
|
||||||
"query": " {\n launchesPast {\n launch_success\n }\n }\n"
|
"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