From e232ceec354b7a634d9c35ce18d6db939089e81f Mon Sep 17 00:00:00 2001 From: Colin Eberhardt Date: Wed, 4 Jan 2023 13:19:27 +0000 Subject: [PATCH] feat: tidying up formatting and doc comments (#42) --- helpers/createQueryStringSnippet.js | 22 +++-- helpers/docComment.js | 7 ++ package-lock.json | 127 +++++++++++---------------- package.json | 3 - partials/model.handlebars | 17 ++-- partials/namespace.handlebars | 6 +- template/ApiClient.cs.handlebars | 95 ++++++++++++-------- template/ApiModel.cs.handlebars | 3 +- template/Configuration.cs.handlebars | 12 +-- template/IApiClient.cs.handlebars | 36 ++++++-- template/Info.cs.handlebars | 20 ++--- template/Startup.cs.handlebars | 2 +- 12 files changed, 188 insertions(+), 162 deletions(-) create mode 100644 helpers/docComment.js diff --git a/helpers/createQueryStringSnippet.js b/helpers/createQueryStringSnippet.js index be26d03..f0a8d5e 100644 --- a/helpers/createQueryStringSnippet.js +++ b/helpers/createQueryStringSnippet.js @@ -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" && @@ -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) => { @@ -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) => { @@ -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"); diff --git a/helpers/docComment.js b/helpers/docComment.js new file mode 100644 index 0000000..960bcab --- /dev/null +++ b/helpers/docComment.js @@ -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; diff --git a/package-lock.json b/package-lock.json index e13d52b..bdc46b1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,9 +8,6 @@ "name": "openapi-forge-csharp", "version": "0.1.0", "license": "MIT", - "dependencies": { - "shelljs": "^0.8.5" - }, "devDependencies": { "@commitlint/cli": "^17.1.2", "@commitlint/config-conventional": "^17.1.0", @@ -1037,7 +1034,8 @@ "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "dev": true }, "node_modules/before-after-hook": { "version": "2.2.3", @@ -1055,6 +1053,7 @@ "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, "dependencies": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -1205,7 +1204,8 @@ "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", + "dev": true }, "node_modules/conventional-changelog-angular": { "version": "5.0.13", @@ -2019,12 +2019,14 @@ "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", + "dev": true }, "node_modules/function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", + "dev": true }, "node_modules/get-caller-file": { "version": "2.0.5", @@ -2103,6 +2105,7 @@ "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "dev": true, "dependencies": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -2223,6 +2226,7 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "dev": true, "dependencies": { "function-bind": "^1.1.1" }, @@ -2379,6 +2383,7 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "dev": true, "dependencies": { "once": "^1.3.0", "wrappy": "1" @@ -2387,7 +2392,8 @@ "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "dev": true }, "node_modules/ini": { "version": "1.3.8", @@ -2395,14 +2401,6 @@ "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==", "dev": true }, - "node_modules/interpret": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.4.0.tgz", - "integrity": "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==", - "engines": { - "node": ">= 0.10" - } - }, "node_modules/into-stream": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/into-stream/-/into-stream-6.0.0.tgz", @@ -2429,6 +2427,7 @@ "version": "2.11.0", "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.11.0.tgz", "integrity": "sha512-RRjxlvLDkD1YJwDbroBHMb+cukurkDWNyHx7D3oNB5x9rb5ogcksMC5wHCadcXoo67gVr/+3GFySh3134zi6rw==", + "dev": true, "dependencies": { "has": "^1.0.3" }, @@ -2964,6 +2963,7 @@ "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, "dependencies": { "brace-expansion": "^1.1.7" }, @@ -5665,6 +5665,7 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "dev": true, "dependencies": { "wrappy": "1" } @@ -5857,6 +5858,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", + "dev": true, "engines": { "node": ">=0.10.0" } @@ -5873,7 +5875,8 @@ "node_modules/path-parse": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", - "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==" + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", + "dev": true }, "node_modules/path-type": { "version": "4.0.0", @@ -6240,17 +6243,6 @@ "util-deprecate": "~1.0.1" } }, - "node_modules/rechoir": { - "version": "0.6.2", - "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", - "integrity": "sha512-HFM8rkZ+i3zrV+4LQjwQ0W+ez98pApMGM3HUrN04j3CqzPOzl9nmP15Y8YXNm8QHGv/eacOVEjqhmWpkRV0NAw==", - "dependencies": { - "resolve": "^1.1.6" - }, - "engines": { - "node": ">= 0.10" - } - }, "node_modules/redent": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/redent/-/redent-3.0.0.tgz", @@ -6319,6 +6311,7 @@ "version": "1.22.1", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.1.tgz", "integrity": "sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw==", + "dev": true, "dependencies": { "is-core-module": "^2.9.0", "path-parse": "^1.0.7", @@ -6555,22 +6548,6 @@ "node": ">=8" } }, - "node_modules/shelljs": { - "version": "0.8.5", - "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.5.tgz", - "integrity": "sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==", - "dependencies": { - "glob": "^7.0.0", - "interpret": "^1.0.0", - "rechoir": "^0.6.2" - }, - "bin": { - "shjs": "bin/shjs" - }, - "engines": { - "node": ">=4" - } - }, "node_modules/signal-exit": { "version": "3.0.7", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", @@ -6881,6 +6858,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", + "dev": true, "engines": { "node": ">= 0.4" }, @@ -7246,7 +7224,8 @@ "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "dev": true }, "node_modules/xtend": { "version": "4.0.2", @@ -8129,7 +8108,8 @@ "balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "dev": true }, "before-after-hook": { "version": "2.2.3", @@ -8147,6 +8127,7 @@ "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -8259,7 +8240,8 @@ "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", + "dev": true }, "conventional-changelog-angular": { "version": "5.0.13", @@ -8865,12 +8847,14 @@ "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", + "dev": true }, "function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", + "dev": true }, "get-caller-file": { "version": "2.0.5", @@ -8936,6 +8920,7 @@ "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "dev": true, "requires": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -9021,6 +9006,7 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "dev": true, "requires": { "function-bind": "^1.1.1" } @@ -9125,6 +9111,7 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "dev": true, "requires": { "once": "^1.3.0", "wrappy": "1" @@ -9133,7 +9120,8 @@ "inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "dev": true }, "ini": { "version": "1.3.8", @@ -9141,11 +9129,6 @@ "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==", "dev": true }, - "interpret": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.4.0.tgz", - "integrity": "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==" - }, "into-stream": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/into-stream/-/into-stream-6.0.0.tgz", @@ -9166,6 +9149,7 @@ "version": "2.11.0", "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.11.0.tgz", "integrity": "sha512-RRjxlvLDkD1YJwDbroBHMb+cukurkDWNyHx7D3oNB5x9rb5ogcksMC5wHCadcXoo67gVr/+3GFySh3134zi6rw==", + "dev": true, "requires": { "has": "^1.0.3" } @@ -9573,6 +9557,7 @@ "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, "requires": { "brace-expansion": "^1.1.7" } @@ -11462,6 +11447,7 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "dev": true, "requires": { "wrappy": "1" } @@ -11596,7 +11582,8 @@ "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==" + "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", + "dev": true }, "path-key": { "version": "3.1.1", @@ -11607,7 +11594,8 @@ "path-parse": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", - "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==" + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", + "dev": true }, "path-type": { "version": "4.0.0", @@ -11871,14 +11859,6 @@ "util-deprecate": "~1.0.1" } }, - "rechoir": { - "version": "0.6.2", - "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", - "integrity": "sha512-HFM8rkZ+i3zrV+4LQjwQ0W+ez98pApMGM3HUrN04j3CqzPOzl9nmP15Y8YXNm8QHGv/eacOVEjqhmWpkRV0NAw==", - "requires": { - "resolve": "^1.1.6" - } - }, "redent": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/redent/-/redent-3.0.0.tgz", @@ -11929,6 +11909,7 @@ "version": "1.22.1", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.1.tgz", "integrity": "sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw==", + "dev": true, "requires": { "is-core-module": "^2.9.0", "path-parse": "^1.0.7", @@ -12097,16 +12078,6 @@ "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", "dev": true }, - "shelljs": { - "version": "0.8.5", - "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.5.tgz", - "integrity": "sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==", - "requires": { - "glob": "^7.0.0", - "interpret": "^1.0.0", - "rechoir": "^0.6.2" - } - }, "signal-exit": { "version": "3.0.7", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", @@ -12360,7 +12331,8 @@ "supports-preserve-symlinks-flag": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", - "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==" + "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", + "dev": true }, "temp-dir": { "version": "2.0.0", @@ -12631,7 +12603,8 @@ "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "dev": true }, "xtend": { "version": "4.0.2", diff --git a/package.json b/package.json index cf4dfe8..5111e37 100644 --- a/package.json +++ b/package.json @@ -47,8 +47,5 @@ }, "engines": { "node": ">=16.0.0" - }, - "dependencies": { - "shelljs": "^0.8.5" } } diff --git a/partials/model.handlebars b/partials/model.handlebars index 10c74f8..e167e41 100644 --- a/partials/model.handlebars +++ b/partials/model.handlebars @@ -1,20 +1,23 @@ {{#if description}} /** - * {{description}} + * {{description}} */ {{/if}} public class {{toClassName @key}} { {{#each properties}} + {{#if description}} - // {{description}} + /// + /// {{description}} + /// {{/if}} {{#if example}} - // e.g. {{example}} + /// + /// {{example}} + /// {{/if}} public {{nullableTypeConvert this}} {{@key}} { get; set; } -{{#unless @last}} - -{{/unless}} {{/each}} - } \ No newline at end of file + } + \ No newline at end of file diff --git a/partials/namespace.handlebars b/partials/namespace.handlebars index f4891f0..31723ba 100644 --- a/partials/namespace.handlebars +++ b/partials/namespace.handlebars @@ -1,5 +1 @@ -{{#if infoTitle}} -namespace {{toClassName infoTitle}} { -{{else}} -namespace OpenApiForge { -{{/if}} \ No newline at end of file +{{#if infoTitle}}namespace {{toClassName infoTitle}}{{else}}namespace OpenApiForge{{/if}} \ No newline at end of file diff --git a/template/ApiClient.cs.handlebars b/template/ApiClient.cs.handlebars index 88d9a1c..f4be51d 100644 --- a/template/ApiClient.cs.handlebars +++ b/template/ApiClient.cs.handlebars @@ -10,37 +10,63 @@ using System.Text.Json.Serialization; using System.Threading.Tasks; using System.Web; -{{>namespace info.title}} - {{#if info.title}} - // {{info.title}} - {{/if}} - {{#if _tag.description}}// {{_tag.description}}{{/if}} +/// +/// {{_info.title}} +/// +{{#if info.description}}{{docComment info.description}}{{/if}} +{{#if info.version}}/// {{info.version}}{{/if}} +{{>namespace info.title}} { + public class ApiClient{{_tag.name}} : IApiClient{{_tag.name}} { - private const string ContentType = "application/json"; - private readonly string _baseAddress; - private readonly HttpClient _client; + private const string ContentType = "application/json"; + private readonly string _baseAddress; + private readonly HttpClient _client; - public ApiClient{{_tag.name}}(HttpClient httpClient, Configuration config) - { - _client = httpClient; - _baseAddress = config.GetBaseAddress(); - } + public ApiClient{{_tag.name}}(HttpClient httpClient, Configuration config) + { + _client = httpClient; + _baseAddress = config.GetBaseAddress(); + } - {{#each paths}} - {{setVar "path" @key}} - {{#each this}} - {{#ifEquals ../../_tag.name _tag.name}} - {{#if (pathContentTypeSupported this)}} - {{#if tags}}// tags: {{tags}}{{/if}} - public async Task{{#if _response.schema}}<{{safeTypeConvert _response.schema}}>{{/if}} {{operationId}}({{#each _sortedParameters}}{{nullableTypeConvert schema _optional}} {{toParamName name}}{{#if (hasDefault schema.default)}} = {{{quoteIfString schema.default}}}{{/if}}{{#unless @last}}, {{/unless}}{{/each}}) - { + {{#each paths}} + {{~setVar "path" @key}} + {{~#each this}} + {{~#ifEquals ../../_tag.name _tag.name}} + {{~#if (pathContentTypeSupported this)}} + + {{#if summary}} + /// + /// {{summary}} + /// + {{/if}} + {{#if description}} + /// {{description}} + {{/if}} + {{#if tags}} + /// {{tags}} + {{/if}} + {{#each _sortedParameters}} + /// {{description}} + {{/each}} + public async Task{{#if _response.schema}}<{{safeTypeConvert _response.schema}}>{{/if}} {{operationId}}( + {{~#each _sortedParameters ~}} + {{~nullableTypeConvert schema _optional}} {{toParamName name ~}} + {{~#if (hasDefault schema.default)}} = {{{quoteIfString schema.default}}}{{/if ~}} + {{~#unless @last}}, {{/unless ~}} + {{~/each ~}} + ) + { {{createQueryStringSnippet _sortedParameters}} var requestUri = $"{_baseAddress}{{setPathParameters @root.path _sortedParameters}}{{#if (queryParametersExist _sortedParameters)}}{queryString}{{/if}}"; - var request = new HttpRequestMessage(new HttpMethod("{{@key}}"), requestUri){ - {{#if (bodyParameterExists _sortedParameters)}} - Content = new StringContent(JsonSerializer.Serialize(body), Encoding.UTF8, ContentType) - {{~/if}} }; + var request = new HttpRequestMessage(new HttpMethod("{{@key}}"), requestUri) + {{~#if (bodyParameterExists _sortedParameters) ~}} + { + Content = new StringContent(JsonSerializer.Serialize(body), Encoding.UTF8, ContentType) + }; + {{~else~}} + { }; + {{~/if~}} {{createHeaderParamsSnippet _sortedParameters}} var response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); @@ -48,18 +74,15 @@ using System.Web; var responseBody = await response.Content.ReadAsStringAsync(); {{createReturnStatement _response.schema}} {{/if}} - } - {{#unless @last}} - - {{/unless}} - {{else}} - public Task{{#if _response.schema}}<{{safeTypeConvert _response.schema}}>{{/if}} {{operationId}}({{#each _sortedParameters}}{{nullableTypeConvert schema _optional}} {{name}}{{#if schema.default}} = {{{quoteIfString schema.default}}}{{/if}}{{#unless @last}}, {{/unless}}{{/each}}) - { + } + {{else}} + public Task{{#if _response.schema}}<{{safeTypeConvert _response.schema}}>{{/if}} {{operationId}}({{#each _sortedParameters}}{{nullableTypeConvert schema _optional}} {{name}}{{#if schema.default}} = {{{quoteIfString schema.default}}}{{/if}}{{#unless @last}}, {{/unless}}{{/each}}) + { throw new NotImplementedException("Operation '{{operationId}}' most likely does not support json encoded requests which are not supported by openapi forge."); - } - {{/if}} + } + {{/if}} {{/ifEquals}} - {{/each}} - {{/each}} + {{/each}} + {{/each}} } } diff --git a/template/ApiModel.cs.handlebars b/template/ApiModel.cs.handlebars index 57c90c9..4b24e7e 100644 --- a/template/ApiModel.cs.handlebars +++ b/template/ApiModel.cs.handlebars @@ -1,8 +1,7 @@ using System; using System.Collections.Generic; -{{>namespace info.title}} - +{{>namespace info.title}} { {{#each components.schemas}} {{> model}} diff --git a/template/Configuration.cs.handlebars b/template/Configuration.cs.handlebars index 6b5575a..4e139c3 100644 --- a/template/Configuration.cs.handlebars +++ b/template/Configuration.cs.handlebars @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using System.Text; -{{>namespace info.title}} +{{>namespace info.title}} { public class Configuration { @@ -21,8 +21,8 @@ using System.Text; if(!string.IsNullOrWhiteSpace(BasePath)) { sb.Append(BasePath.StartsWith("/") - ? BasePath - : $"/{BasePath}"); + ? BasePath + : $"/{BasePath}"); } return RemoveTrailingSlash(sb).ToString(); @@ -30,9 +30,9 @@ using System.Text; private static StringBuilder RemoveTrailingSlash(StringBuilder sb) { - return sb.Length > 0 && sb[sb.Length - 1] == '/' - ? sb.Remove(sb.Length - 1, 1) - : sb; + return sb.Length > 0 && sb[sb.Length - 1] == '/' + ? sb.Remove(sb.Length - 1, 1) + : sb; } } } diff --git a/template/IApiClient.cs.handlebars b/template/IApiClient.cs.handlebars index d107dad..870eea1 100644 --- a/template/IApiClient.cs.handlebars +++ b/template/IApiClient.cs.handlebars @@ -2,21 +2,41 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -{{>namespace info.title}} +/// +/// {{_info.title}} +/// +{{#if info.description}}{{docComment info.description}}{{/if}} +{{#if info.version}}/// {{info.version}}{{/if}} +{{>namespace info.title}} { - // {{info.title}} public interface IApiClient{{_tag.name}} { {{#each paths}} {{setVar "path" @key}} {{#each this}} {{#ifEquals ../../_tag.name _tag.name}} - {{#if summary}}// {{summary}}{{/if}} - {{#if description}}// {{description}}{{/if}} - public Task{{#if _response.schema}}<{{safeTypeConvert _response.schema}}>{{/if}} {{operationId}}({{#each _sortedParameters}}{{nullableTypeConvert schema _optional}} {{toParamName name}}{{#if (hasDefault schema.default)}} = {{{quoteIfString schema.default}}}{{/if}}{{#unless @last}}, {{/unless}}{{/each}}); - {{#unless @last}} - - {{/unless}} + {{#if summary}} + /// + /// {{summary}} + /// + {{/if}} + {{#if description}} + /// {{description}} + {{/if}} + {{#if tags}} + /// {{tags}} + {{/if}} + {{#each _sortedParameters}} + /// {{description}} + {{/each}} + public Task{{#if _response.schema}}<{{safeTypeConvert _response.schema}}>{{/if}} {{operationId}}( + {{~#each _sortedParameters ~}} + {{~nullableTypeConvert schema _optional}} {{toParamName name ~}} + {{~#if (hasDefault schema.default)}} = {{{quoteIfString schema.default}}}{{/if ~}} + {{~#unless @last}}, {{/unless ~}} + {{~/each ~}} + ); + {{/ifEquals}} {{/each}} {{/each}} diff --git a/template/Info.cs.handlebars b/template/Info.cs.handlebars index b900f80..8d1b096 100644 --- a/template/Info.cs.handlebars +++ b/template/Info.cs.handlebars @@ -2,22 +2,21 @@ using System; using System.Collections.Generic; using System.Text; -{{>namespace info.title}} +{{>namespace info.title}} { public static class Info { {{#each _info}} - public static {{#if (isObj this) }}{{capitalizeFirst @key}}{{else}}String{{/if}} {{capitalizeFirst @key}} { get;set; }= + public static {{#if (isObj this) }}{{capitalizeFirst @key}}{{else}}String{{/if}} {{capitalizeFirst @key}} { get; set; } = {{#if (isObj this) }} - new {{capitalizeFirst @key}} { + new {{capitalizeFirst @key}} { {{#each this}} - {{capitalizeFirst @key}}= "{{this}}", + {{capitalizeFirst @key}}= "{{this}}", {{/each}} - }; + }; {{else}} - "{{this}}"; - + "{{this}}"; {{/if}} {{/each}} } @@ -26,10 +25,11 @@ using System.Text; {{#if (isObj this) }} public class {{capitalizeFirst @key}} { - {{#each this}} - public String {{capitalizeFirst @key}} {get;set;} - {{/each}} + {{#each this}} + public String {{capitalizeFirst @key}} {get; set;} + {{/each}} } + {{/if}} {{/each}} } diff --git a/template/Startup.cs.handlebars b/template/Startup.cs.handlebars index 896c09f..faa042d 100644 --- a/template/Startup.cs.handlebars +++ b/template/Startup.cs.handlebars @@ -3,7 +3,7 @@ using System.Linq; using System.Net.Http; using Microsoft.Extensions.DependencyInjection; -{{>namespace info.title}} +{{>namespace info.title}} { public static class Startup {