OpenAPITools / OpenAPITools/openapi-generator

[BUG][angular-typescript] can't generate client, throws java.nio.file.NoSuchFileException

Open
#12,191 7 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
Description

I'm trying to generate an angular client with typescript-angular, and I'm getting the following error:

➜  ng-openapi-gen-test git:(main) ✗ npm run openapi-generator

> ng-openapi-gen-test@1.0.0 openapi-generator
> openapi-generator-cli generate -i openapi.yaml -g typescript-angular -o /output-openapi-generator

[main] INFO  o.o.codegen.DefaultGenerator - Generating with dryRun=false
[main] INFO  o.o.c.ignore.CodegenIgnoreProcessor - Output directory (/output-openapi-generator) does not exist, or is inaccessible. No file (.openapi-generator-ignore) will be evaluated.
[main] INFO  o.o.codegen.DefaultGenerator - OpenAPI Generator: typescript-angular (client)
[main] INFO  o.o.codegen.DefaultGenerator - Generator 'typescript-angular' is considered stable.
[main] INFO  o.o.c.l.AbstractTypeScriptClientCodegen - Hint: Environment variable 'TS_POST_PROCESS_FILE' (optional) not defined. E.g. to format the source code, please try 'export TS_POST_PROCESS_FILE="/usr/local/bin/prettier --write"' (Linux/Mac)
[main] INFO  o.o.c.l.AbstractTypeScriptClientCodegen - Note: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).
[main] INFO  o.o.c.l.TypeScriptAngularClientCodegen - generating code for Angular 13.0.1 ...
[main] INFO  o.o.c.l.TypeScriptAngularClientCodegen -   (you can select the angular version by setting the additionalProperty ngVersion)
[main] INFO  o.o.codegen.TemplateManager - writing file /output-openapi-generator/model/./post.ts
Exception in thread "main" java.lang.RuntimeException: Could not generate model 'Post'
        at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:532)
        at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:888)
        at org.openapitools.codegen.cmd.Generate.execute(Generate.java:441)
        at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Caused by: java.nio.file.NoSuchFileException: /output-openapi-generator/model/./post.ts
        at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
        at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
        at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
        at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:214)
        at java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:434)
        at java.nio.file.Files.newOutputStream(Files.java:216)
        at java.nio.file.Files.write(Files.java:3292)
        at org.openapitools.codegen.TemplateManager.writeToFileRaw(TemplateManager.java:255)
        at org.openapitools.codegen.TemplateManager.writeToFile(TemplateManager.java:237)
        at org.openapitools.codegen.TemplateManager.writeToFile(TemplateManager.java:198)
        at org.openapitools.codegen.TemplateManager.write(TemplateManager.java:164)
        at org.openapitools.codegen.DefaultGenerator.processTemplateToFile(DefaultGenerator.java:1034)
        at org.openapitools.codegen.DefaultGenerator.processTemplateToFile(DefaultGenerator.java:1021)
        at org.openapitools.codegen.DefaultGenerator.generateModel(DefaultGenerator.java:388)
        at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:523)
        ... 4 more
openapi-generator version

^2.4.26

OpenAPI declaration file content or url

Link

Generation Details

openapi-generator-cli generate -i openapi.yaml -g typescript-angular -o /output-openapi-generator

Steps to reproduce

Clone this repo and run npm run openapi-generator
https://github.com/marcellkiss/ng-openapi-gen-debug

Related issues/PRs

--

Suggest a fix

No idea, I tried it with two different openapi files (openapi.json and openapi.yaml in the repo) and both lead to the same result.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce with the linked ng-openapi-gen-debug repository and the shown openapi-generator-cli command. Start from the TypeScriptAngularClientCodegen model generation path and the DefaultGenerator/TemplateManager stack trace, then compare the output directory handling around model/post.ts. Done means the typescript-angular client generates successfully without NoSuchFileException.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, java, openapi, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.