Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Due: Mar] openapi-generator fails to generate client #4572

Closed
lovis-ff opened this issue Mar 15, 2024 · 5 comments · Fixed by #4634
Closed

[Due: Mar] openapi-generator fails to generate client #4572

lovis-ff opened this issue Mar 15, 2024 · 5 comments · Fixed by #4634
Assignees
Labels
bug Something isn't working

Comments

@lovis-ff
Copy link

Describe the bug
I want to create a open-api client using an open api schema from SAP Business Accelerator Hub, specifically https://api.sap.com/api/OP_API_SALES_QUOTATION_SRV_0001/overview. I am getting ErrorWithCause: Could not write file "sales-quotation-header-api.ts"..
Digging a b it into the code I find that there is a syntax error in the created files

SyntaxError: ',' expected. (55:25)
  53 |   '$expand'?: Set<'*' | 'to_Item' | 'to_Partner' | 'to_PrecedingProcFlowDoc' | 'to_PricingElement' | 'to_RelatedObject' | 'to_SubsequentProcFlowDoc' | 'to_Text'>}) => new OpenApiRequestBuilder<APISALESQUOTATIONSRVASalesQuotationType>(
  54 |     'get',
> 55 |     '/A_SalesQuotation('{salesQuotation}')',
     |                         ^
  56 |     {
  57 |           pathParameters: { salesQuotation },

where it seems as if template literals are not used correctly, it should probably be

> 55 |     `/A_SalesQuotation('${salesQuotation}')`,

The generation does not work for .json or .yaml. The generation of the odata client via .edmx file works but is not sufficient for the use case.

To Reproduce
Steps to reproduce the behavior:

  1. Download open api json spec fromhttps://api.sap.com/api/OP_API_SALES_QUOTATION_SRV_0001/overview
  2. Execute npx openapi-generator --input <input-directory> --outputDir <output-directory> --clearOutputDir --skipValidation. Note, I do have to add --skipValidation because the generation would otherwise not work because of some naming issues of the endpoints.
  3. See error

Expected behavior
Successful generation of the open-api client.

Used Versions:

  • node version: v18.16.0
  • npm version: done with pnpm version 7.33.5
  • SAP Cloud SDK version you used as dependency: 3.12.1

Code Examples
If applicable, add code snippets as examples to help explain your problem. Please remove sensitive information.

Log file
Original error

[2024-03-15T10:23:25.021Z] ERROR    (cli): ErrorWithCause: Generation of services failed.
    at /Users/lovis/Documents/workspace/ms-platform-deploy/node_modules/.pnpm/@sap-cloud-sdk+openapi-generator@3.12.1/node_modules/@sap-cloud-sdk/openapi-generator/dist/cli.js:15:18
Caused by:
Error: Could not generate client. Errors: [
	ErrorWithCause: Could not write file "sales-quotation-header-api.ts".
]
    at finishAll (/Users/lovis/Documents/workspace/ms-platform-deploy/node_modules/.pnpm/@sap-cloud-sdk+util@3.12.1/node_modules/@sap-cloud-sdk/util/dist/promise.js:19:15)
    at async generateWithParsedOptions (/Users/lovis/Documents/workspace/ms-platform-deploy/node_modules/.pnpm/@sap-cloud-sdk+openapi-generator@3.12.1/node_modules/@sap-cloud-sdk/openapi-generator/dist/generator.js:59:9)

Debugged error

SyntaxError: ',' expected. (55:25)
  53 |   '$expand'?: Set<'*' | 'to_Item' | 'to_Partner' | 'to_PrecedingProcFlowDoc' | 'to_PricingElement' | 'to_RelatedObject' | 'to_SubsequentProcFlowDoc' | 'to_Text'>}) => new OpenApiRequestBuilder<APISALESQUOTATIONSRVASalesQuotationType>(
  54 |     'get',
> 55 |     '/A_SalesQuotation('{salesQuotation}')',
     |                         ^
  56 |     {
  57 |           pathParameters: { salesQuotation },
  58 |           queryParameters
    at Kq (file:///Users/lovis/Documents/workspace/ms-platform-deploy/node_modules/.pnpm/prettier@3.2.5/node_modules/prettier/plugins/typescript.mjs:23:498)
    at xz (file:///Users/lovis/Documents/workspace/ms-platform-deploy/node_modules/.pnpm/prettier@3.2.5/node_modules/prettier/plugins/typescript.mjs:25:794)
    at Object.Cz [as parse] (file:///Users/lovis/Documents/workspace/ms-platform-deploy/node_modules/.pnpm/prettier@3.2.5/node_modules/prettier/plugins/typescript.mjs:25:1194)
    at parse4 (file:///Users/lovis/Documents/workspace/ms-platform-deploy/node_modules/.pnpm/prettier@3.2.5/node_modules/prettier/index.mjs:22117:24)
    at async coreFormat (file:///Users/lovis/Documents/workspace/ms-platform-deploy/node_modules/.pnpm/prettier@3.2.5/node_modules/prettier/index.mjs:22607:7)
    at async formatWithCursor (file:///Users/lovis/Documents/workspace/ms-platform-deploy/node_modules/.pnpm/prettier@3.2.5/node_modules/prettier/index.mjs:22809:14)
    at async Module.format2 (file:///Users/lovis/Documents/workspace/ms-platform-deploy/node_modules/.pnpm/prettier@3.2.5/node_modules/prettier/index.mjs:24194:25)
    at async createFile (/Users/lovis/Documents/workspace/ms-platform-deploy/node_modules/.pnpm/@sap-cloud-sdk+generator-common@3.12.1/node_modules/@sap-cloud-sdk/generator-common/dist/file-writer/create-file.js:113:24)
    at async createApis (/Users/lovis/Documents/workspace/ms-platform-deploy/node_modules/.pnpm/@sap-cloud-sdk+openapi-generator@3.12.1/node_modules/@sap-cloud-sdk/openapi-generator/dist/generator.js:129:9)
    at async generateMandatorySources (/Users/lovis/Documents/workspace/ms-platform-deploy/node_modules/.pnpm/@sap-cloud-sdk+openapi-generator@3.12.1/node_modules/@sap-cloud-sdk/openapi-generator/dist/generator.js:122:5) {
  loc: { start: { line: 55, column: 25 }, end: { line: 55, column: 25 } },
  cause: Vm: ',' expected.
      at RB (file:///Users/lovis/Documents/workspace/ms-platform-deploy/node_modules/.pnpm/prettier@3.2.5/node_modules/prettier/plugins/typescript.mjs:21:119402)
      at YB (file:///Users/lovis/Documents/workspace/ms-platform-deploy/node_modules/.pnpm/prettier@3.2.5/node_modules/prettier/plugins/typescript.mjs:21:122980)
      at YU (file:///Users/lovis/Documents/workspace/ms-platform-deploy/node_modules/.pnpm/prettier@3.2.5/node_modules/prettier/plugins/typescript.mjs:21:191880)
      at $q (file:///Users/lovis/Documents/workspace/ms-platform-deploy/node_modules/.pnpm/prettier@3.2.5/node_modules/prettier/plugins/typescript.mjs:21:203680)
      at Xq (file:///Users/lovis/Documents/workspace/ms-platform-deploy/node_modules/.pnpm/prettier@3.2.5/node_modules/prettier/plugins/typescript.mjs:21:203346)
      at file:///Users/lovis/Documents/workspace/ms-platform-deploy/node_modules/.pnpm/prettier@3.2.5/node_modules/prettier/plugins/typescript.mjs:25:1160
      at Zq (file:///Users/lovis/Documents/workspace/ms-platform-deploy/node_modules/.pnpm/prettier@3.2.5/node_modules/prettier/plugins/typescript.mjs:23:652)
      at Object.Cz [as parse] (file:///Users/lovis/Documents/workspace/ms-platform-deploy/node_modules/.pnpm/prettier@3.2.5/node_modules/prettier/plugins/typescript.mjs:25:1132)
      at parse4 (file:///Users/lovis/Documents/workspace/ms-platform-deploy/node_modules/.pnpm/prettier@3.2.5/node_modules/prettier/index.mjs:22117:24)
      at async coreFormat (file:///Users/lovis/Documents/workspace/ms-platform-deploy/node_modules/.pnpm/prettier@3.2.5/node_modules/prettier/index.mjs:22607:7) {
    fileName: 'estree.ts',
    location: { start: [Object], end: [Object] }
  },
  codeFrame: "\x1B[0m \x1B[90m 53 |\x1B[39m   \x1B[32m'$expand'\x1B[39m\x1B[33m?\x1B[39m\x1B[33m:\x1B[39m \x1B[33mSet\x1B[39m\x1B[33m<\x1B[39m\x1B[32m'*'\x1B[39m \x1B[33m|\x1B[39m \x1B[32m'to_Item'\x1B[39m \x1B[33m|\x1B[39m \x1B[32m'to_Partner'\x1B[39m \x1B[33m|\x1B[39m \x1B[32m'to_PrecedingProcFlowDoc'\x1B[39m \x1B[33m|\x1B[39m \x1B[32m'to_PricingElement'\x1B[39m \x1B[33m|\x1B[39m \x1B[32m'to_RelatedObject'\x1B[39m \x1B[33m|\x1B[39m \x1B[32m'to_SubsequentProcFlowDoc'\x1B[39m \x1B[33m|\x1B[39m \x1B[32m'to_Text'\x1B[39m\x1B[33m>\x1B[39m}) \x1B[33m=>\x1B[39m \x1B[36mnew\x1B[39m \x1B[33mOpenApiRequestBuilder\x1B[39m\x1B[33m<\x1B[39m\x1B[33mAPISALESQUOTATIONSRVASalesQuotationType\x1B[39m\x1B[33m>\x1B[39m(\x1B[0m\n" +
    "\x1B[0m \x1B[90m 54 |\x1B[39m     \x1B[32m'get'\x1B[39m\x1B[33m,\x1B[39m\x1B[0m\n" +
    "\x1B[0m\x1B[31m\x1B[1m>\x1B[22m\x1B[39m\x1B[90m 55 |\x1B[39m     \x1B[32m'/A_SalesQuotation('\x1B[39m{salesQuotation}\x1B[32m')'\x1B[39m\x1B[33m,\x1B[39m\x1B[0m\n" +
    '\x1B[0m \x1B[90m    |\x1B[39m                         \x1B[31m\x1B[1m^\x1B[22m\x1B[39m\x1B[0m\n' +
    '\x1B[0m \x1B[90m 56 |\x1B[39m     {\x1B[0m\n' +
    '\x1B[0m \x1B[90m 57 |\x1B[39m           pathParameters\x1B[33m:\x1B[39m { salesQuotation }\x1B[33m,\x1B[39m\x1B[0m\n' +
    '\x1B[0m \x1B[90m 58 |\x1B[39m           queryParameters\x1B[0m'
}

Impact / Priority

Affected development phase: Development

Impact: Blocked

Timeline: Go-Live is in 2 weeks.

@lovis-ff lovis-ff added the bug Something isn't working label Mar 15, 2024
@mr-flannery
Copy link
Contributor

Hi @lovis-ff ,

thanks for getting in touch with us. I was able to reproduce the bug. We'll let you know if we have another update.

@jjtang1985 jjtang1985 changed the title openapi-generator fails to generate client [Due: Mar] openapi-generator fails to generate client Mar 18, 2024
@lovis-ff
Copy link
Author

Hi @mr-flannery,
are there any updates from your side?

@mr-flannery
Copy link
Contributor

Hi @lovis-ff ,

unfortatunately, no. I currently cannot give you an estimate of when we're going to tackle this. If this is a blocker for you, I would suggest calling the API for which you're trying to generate the client manually for now.

@deekshas8
Copy link
Contributor

Hi @lovis-ff ,

The PR with the fix was merged, we will release a new version soon. In the meanwhile, please try out the canary version.

@lovis-ff
Copy link
Author

Thanks. I tested with version 3.14.0 and the generation works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants