Nswag adds the path of the generated file at the end of the generated file

Viewed 55

I am running into a strange issue with my Nswag generated file. After running the scrip for generating the code it is doing it successfully, but at the end of the file it is adding the path of the file itself.

I have already tried to:

  • Delete the node_modules folder and re-run npm install
  • Delete the package-lock.json file and re-run npm install
  • Re-run npm install
  • Found a single person having this issue who posted an issue in GitHub: https://github.com/RicoSuter/NSwag/issues/3172
  • Search the deep dark 3th page of Google

After script execution

That is what I get after I generate the file

function throwException(message: string, status: number, response: string, headers: { [key: string]: any; }, result?: any): any {
  throw new SwaggerException(message, status, response, headers, result);
}

C:\Users\USER_NAME\source\repos\SOLUTION_NAME\src\backend\api-client-extentions.ts

Any help is appreciated!

Setup:

Backend:

I have a C# project running as my backend providing all of the needed controllers that have to be translated with the Nswag

Frontend

I have a Microsoft SharePoint Online WebPart solution wrapped in a React framework.

Config files

config.api.nswag

{
  "runtime": "Default",
  "defaultVariables": null,
  "documentGenerator": {
    "fromDocument": {
      "url": "https://localhost:8081/swagger/BACKEND_PATH/swagger.json",
      "output": null,
      "newLineBehavior": "Auto"
    }
  },
  "codeGenerators": {
    "openApiToTypeScriptClient": {
      "className": "ApiClient",
      "moduleName": "",
      "namespace": "",
      "typeScriptVersion": 2.7,
      "template": "Fetch",
      "promiseType": "Promise",
      "httpClass": "HttpClient",
      "withCredentials": false,
      "useSingletonProvider": false,
      "injectionTokenType": "OpaqueToken",
      "rxJsVersion": 6.0,
      "dateTimeType": "Date",
      "nullValue": "Undefined",
      "generateClientClasses": true,
      "generateClientInterfaces": false,
      "generateOptionalParameters": false,
      "exportTypes": true,
      "wrapDtoExceptions": true,
      "exceptionClass": "SwaggerException",
      "clientBaseClass": "ApiClientBase",
      "wrapResponses": false,
      "wrapResponseMethods": [],
      "generateResponseClasses": true,
      "responseClass": "SwaggerResponse",
      "protectedMethods": [],
      "configurationClass": null,
      "useTransformOptionsMethod": true,
      "useTransformResultMethod": false,
      "generateDtoTypes": true,
      "operationGenerationMode": "SingleClientFromOperationId",
      "markOptionalProperties": true,
      "generateCloneMethod": false,
      "typeStyle": "Interface",
      "enumStyle": "Enum",
      "useLeafType": false,
      "classTypes": [],
      "extendedClasses": [],
      "extensionCode": "src/backend/api-client-extentions.ts",
      "generateDefaultValues": true,
      "excludedTypeNames": [],
      "excludedParameterNames": [],
      "handleReferences": false,
      "generateConstructorInterface": true,
      "convertConstructorInterfaceData": false,
      "importRequiredTypes": true,
      "useGetBaseUrlMethod": false,
      "baseUrlTokenName": "API_BASE_URL",
      "queryNullValue": "",
      "inlineNamedDictionaries": false,
      "inlineNamedAny": false,
      "templateDirectory": null,
      "typeNameGeneratorType": null,
      "propertyNameGeneratorType": null,
      "enumNameGeneratorType": null,
      "serviceHost": null,
      "serviceSchemes": null,
      "output": "src/backend/api-client-generated.ts",
      "newLineBehavior": "Auto"
    },    
  }
}

package.json

{
  "name": "test-new-solution",
  "version": "0.0.1",
  "private": true,
  "main": "lib/index.js",
  "scripts": {
    "build": "gulp bundle",
    "clean": "gulp clean",
    "test": "gulp test",
    "generate:nswag:api": "nswag run config.api.nswag"
  },
  "dependencies": {
    "react": "16.13.1",
    "react-dom": "16.13.1",
    "office-ui-fabric-react": "7.174.1",
    "@microsoft/sp-core-library": "1.14.0",
    "@microsoft/sp-property-pane": "1.14.0",
    "@microsoft/sp-webpart-base": "1.14.0",
    "@microsoft/sp-lodash-subset": "1.14.0",
    "@microsoft/sp-office-ui-fabric-core": "1.14.0",
    "nswag": "13.6.1"
  },
  "devDependencies": {
    "@types/react": "16.9.51",
    "@types/react-dom": "16.9.8",
    "@microsoft/sp-build-web": "1.14.0",
    "@microsoft/sp-tslint-rules": "1.14.0",
    "@microsoft/sp-module-interfaces": "1.14.0",
    "@microsoft/rush-stack-compiler-3.9": "0.4.47",
    "gulp": "~4.0.2",
    "ajv": "~5.2.2",
    "@types/webpack-env": "1.13.1",
    "@types/node": "^17.0.33"
  }
}

0 Answers
Related