feat: bruno lang support for parsing xml body

This commit is contained in:
Anoop M D 2023-01-15 05:03:58 +05:30
parent a645d1459c
commit 5e1d6cba4a
5 changed files with 27 additions and 14 deletions

View File

@ -61,17 +61,11 @@ assert
}
/assert
vars
1 petId $res.data.id
/vars
readme
docs
Documentation about the request
/readme
/docs
response-example
name Created
status 201
response-example(name="Created", status=201)
headers
1 content-type application/json
1 accept-language en-US,en;q=0.9,hi;q=0.8

View File

@ -15,7 +15,10 @@ 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]*/);
// body(type=xml)
const bodyXmlBegin = regex(/^body\s*\(\s*type\s*=\s*xml\s*\)\s*\r?\n/);
const bodyEnd = regex(/^[\r?\n]+\/body\s*[\r?\n]*/);
const bodyJsonTag = between(bodyJsonBegin)(bodyEnd)(everyCharUntil(bodyEnd)).map((bodyJson) => {
if(bodyJson && bodyJson.length) {
@ -62,8 +65,17 @@ const bodyTextTag = between(bodyTextBegin)(bodyEnd)(everyCharUntil(bodyEnd)).map
}
});
const bodyXmlTag = between(bodyXmlBegin)(bodyEnd)(everyCharUntil(bodyEnd)).map((bodyXml) => {
return {
body: {
xml: bodyXml
}
}
});
module.exports = {
bodyJsonTag,
bodyGraphqlTag,
bodyTextTag
bodyTextTag,
bodyXmlTag
};

View File

@ -11,7 +11,8 @@ const headersTag = require('./headers-tag');
const {
bodyJsonTag,
bodyGraphqlTag,
bodyTextTag
bodyTextTag,
bodyXmlTag
} = require('./body-tag');
const bruToJson = (fileContents) => {
@ -22,6 +23,7 @@ const bruToJson = (fileContents) => {
bodyJsonTag,
bodyGraphqlTag,
bodyTextTag,
bodyXmlTag,
anyChar
]));

View File

@ -36,3 +36,7 @@ body(type=text)
Hello, there. You must be from the past
/body
body(type=xml)
<body>back to the ice age</body>
/body

View File

@ -53,9 +53,10 @@ describe('bruToJson', () => {
"body": {
"json": '{"apikey":"secret","numbers":"+91998877665"}',
"graphql": {
"query": " {\n launchesPast {\n launch_success\n }\n }\n"
"query": " {\n launchesPast {\n launch_success\n }\n }"
},
"text": " Hello, there. You must be from the past\n"
"text": " Hello, there. You must be from the past",
"xml": " <body>back to the ice age</body>"
}
});
});