swagger-api / swagger-api/swagger-codegen
Angular project not recognizing ApiModule
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I am upgrading my project front end from Angular 6 to 11. With that I have upgraded from swagger cli 2.3.1 to 2.4.18. Swagger generates the service-client layer without issues and when I run npm install on my Angular project it installs without issues however when I serve the project and try to open it in the browser I'm getting an error that says ApiModule is undefined. I've searched for a solution but haven't had any luck.
Swagger-codegen version
2.4.18
Swagger declaration file content or url
Angular Code:
import { Configuration, ConfigurationParameters, ApiModule, BASE_PATH } from '@angular-p/logic-service-client';
import { PresentationService } from './main/onboarding/_services/presentation.service';
import { PresentationSharedService } from './services/presentation-shared.service';
export function apiConfigFactory (): Configuration {
const params: ConfigurationParameters = {
// set configuration parameters here.
};
return new Configuration(params);
}
@NgModule({
imports: [
ApiModule.forRoot(apiConfigFactory),
Service-Client AppModule Code:
export class ApiModule {
public static forRoot(configurationFactory: () => Configuration): ModuleWithProviders {
return {
ngModule: ApiModule,
providers: [ { provide: Configuration, useFactory: configurationFactory } ]
};
}
Command line used for generation
java -jar ${WORKSPACE}/build/swagger-codegen-cli-2.4.17.jar generate
-i ${WORKSPACE}/build/logic-service.json
-o ${WORKSPACE}/build
-l typescript-angular
--additional-properties npmName=@angular-p/logic-service-client,snapshot=true,ngVersion=11.1.0
Steps to reproduce
happens whenever I try to open the project in a browser.
Cannot read property 'forRoot' of undefined shows up in the console.
Related issues/PRs
none that I'm aware of
Suggest a fix/enhancement
just asking for help
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 with the generated Angular service-client AppModule code and the importing Angular module shown in the report. Reproduce the browser error after generating with swagger-codegen 2.4.18 and inspect why ApiModule is undefined when ApiModule.forRoot is called. Done means the generated client can be imported and the Angular project opens without this error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100