Skip to content

Commit

Permalink
application/json Content-Type header (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinming-Hu authored Feb 24, 2022
1 parent 46397c7 commit 4f46235
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/cppGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,10 @@ export async function generateCppLibrary(
// request body
let requestHasBody = false;
let requestIsStream = false;
const requestIsJson =
operation.requests?.[0].protocol.http?.["knownMediaType"] === "json";
const requesteIsXml =
operation.requests?.[0].protocol.http?.["knownMediaType"] === "xml";
let isOperationOptionsReferenced = false; // use this to figure out if we need (void)options
console.assert(
operation.requests?.length === 1,
Expand Down Expand Up @@ -619,11 +623,7 @@ export async function generateCppLibrary(
requestHasBody = true;
const variableName = requestBody.language.default.name;
let variable = new CppVariable(variableName, bodyModelType);
const requestIsJson =
operation.requests?.[0].protocol.http?.["knownMediaType"] ===
"json";
const requesteIsXml =
operation.requests?.[0].protocol.http?.["knownMediaType"] === "xml";

operationOptionsDefinition.members.push(variable);
if (requesteIsXml) {
variable.xmlSerialization = new CppTypes.XmlSerializationAction(
Expand Down Expand Up @@ -724,12 +724,21 @@ export async function generateCppLibrary(
// query parameters and HTTP request headers
// TODO: check if we can find this Content-Type header in swagger, instead of hard-coding it here
if (requestHasBody && !requestIsStream) {
operationFunctionDefinition.codeBlocks.push(
new CodeBlocks.SetHTTPRequestHeader(
'"application/xml; charset=UTF-8"',
"Content-Type"
)
);
if (requesteIsXml) {
operationFunctionDefinition.codeBlocks.push(
new CodeBlocks.SetHTTPRequestHeader(
'"application/xml; charset=UTF-8"',
"Content-Type"
)
);
} else if (requestIsJson) {
operationFunctionDefinition.codeBlocks.push(
new CodeBlocks.SetHTTPRequestHeader(
'"application/json"',
"Content-Type"
)
);
}
operationFunctionDefinition.codeBlocks.push(
new CodeBlocks.SetContentLengthHttpRequestHeader()
);
Expand Down

0 comments on commit 4f46235

Please sign in to comment.