swagger-api / swagger-api/swagger-codegen
[ANGULAR-TYPSCRIPT] Error during template compile of 'SwaggerModule' Only initialized variables and constants can be referenced in decorators because the value of this variable is needed by the template compiler in 'BASE_PATH' 'BASE_PATH' references 'BASE_PATH' 'BASE_PATH' is not initialized at
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
We generate an Typscripte Api client for Angular with this Mavenplugin https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen-maven-plugin . After that we publish the generated client code to a private npm repro. Then we integrate it into an Angular project and embed like in this tutorial: https://angular.schule/blog/2018-04-swagger-codegen .
after building the project with the folowing command
ng serve --prod
We get the follwing error:
Error during template compile of 'SwaggerModule' Only initialized variables and constants can be referenced in decorators because the value of this variable is needed by the template compiler in 'BASE_PATH' 'BASE_PATH' references 'BASE_PATH' 'BASE_PATH' is not initialized at ..
ng serve without production works totaly fine.
Swagger-codegen version
2.31
Swagger declaration file content or url
Command line used for generation
<language>typescript-angular</language>
<output>...</output>
<configOptions>
<packageName>labcom.agriportal</packageName>
<npmName>@swagger/AgriportalProxy</npmName>
<npmVersion>0.0.4</npmVersion>
<snapshot>true</snapshot>
<ngVersion>5.2.10</ngVersion>
<npmRepository>... </npmRepository>
</configOptions>
Steps to reproduce
- generate Typscript Api Client for Angular 5.2.10
- publish to npm
- import it into an plain angular project
- Set BASE_PATH in the AppModule like:
import { ApiModule, BASE_PATH } from 'swaggerPackage ... providers: [{ provide: BASE_PATH, useValue: environment.API_BASE_PATH }], ' - Build project in production mode with:
ng serve --prod
Related issues/PRs
Suggest a fix/enhancement
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by generating the TypeScript Angular client with swagger-codegen 2.31 using ngVersion 5.2.10, then reproduce the failure with ng serve --prod. Inspect the generated SwaggerModule and BASE_PATH usage referenced by the error, comparing production and non-production builds. Done means the generated client builds in production while still allowing BASE_PATH to be provided from the AppModule.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, typescript
- Domain
- build-system, frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100