Skip to content

Commit

Permalink
feat: tidying up formatting and doc comments (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinEberhardt authored Jan 4, 2023
1 parent 7bc4edc commit e232cee
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 162 deletions.
22 changes: 15 additions & 7 deletions helpers/createQueryStringSnippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const Handlebars = require("handlebars");
const toParamName = require("./toParamName");
const getParametersByType = require("./getParametersByType");
const newLine = "\n";
// currently we don't have a working c# code formatter, so we need to use this hack
const indent = " ";

const isStringType = (typeDef) =>
typeDef.type === "string" &&
Expand All @@ -18,8 +20,10 @@ const serialiseArrayParam = (param) => {
param.name
}={${isStringArrayParam(param) ? "HttpUtility.UrlEncode(p)" : "p"}}"))}`;

return `if(${safeParamName} != null && ${safeParamName}.Length > 0)
{ ${prefixSerialisedQueryParam(serialisedParam)} }`;
return `${indent}if (${safeParamName} != null && ${safeParamName}.Length > 0)
${indent}{
${prefixSerialisedQueryParam(serialisedParam)}
${indent}}`;
};

const serialiseObjectParam = (param) => {
Expand All @@ -33,8 +37,10 @@ const serialiseObjectParam = (param) => {
serialisedObject += serialisedParam + "&";
}

return `if(${safeParamName} != null)
{ ${prefixSerialisedQueryParam(serialisedObject.slice(0, -1))} }`;
return `${indent}if (${safeParamName} != null)
${indent}{
${prefixSerialisedQueryParam(serialisedObject.slice(0, -1))}
${indent}}`;
};

const serialisePrimitive = (param) => {
Expand All @@ -47,13 +53,15 @@ const serialisePrimitive = (param) => {
`${param.name}={${escaped}}`
);
return param._optional
? `if(${safeParamName} != null)
{ ${serialisedParam} }`
? `${indent}if (${safeParamName} != null)
${indent}{
${serialisedParam}
${indent}}`
: serialisedParam;
};

const prefixSerialisedQueryParam = (serialisedQueryParam) =>
`queryString.Append($"{(queryString.Length == 0 ? "?" : "&")}${serialisedQueryParam}");`;
`${indent}queryString.Append($"{(queryString.Length == 0 ? "?" : "&")}${serialisedQueryParam}");`;

const createQueryStringSnippet = (params) => {
const queryParams = getParametersByType(params, "query");
Expand Down
7 changes: 7 additions & 0 deletions helpers/docComment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const indent = (text) => {
// add three slashes before each newline and the start of the string
text = text.replace(/^/gm, "/// ");
return text;
};

module.exports = indent;
Loading

0 comments on commit e232cee

Please sign in to comment.