ng-openapi-gen icon indicating copy to clipboard operation
ng-openapi-gen copied to clipboard

#342 - introduce standalone flag

Open mumenthalers opened this issue 11 months ago • 3 comments

closes #342

changes:

  • standalone option added
  • prevent module being generated when standalone is set
  • generate and export provideApiConfiguration (accepting value or factory)

mumenthalers avatar Jan 01 '25 10:01 mumenthalers

Will this work in case of multiple schemas? I for example have 2 BE services (schemas) and I have to generate 2 different configs, which generate 2 different modules.

Example: ChatApiModule and UserApiModule

Which i then import:

importProvidersFrom([
    UserApiModule.forRoot({ rootUrl: USER_SERVICE_ENDPOINT_PREFIX }),
    ChatApiModule.forRoot({ rootUrl: CHAT_SERVICE_ENDPOINT_PREFIX }),
]),

Will your solution work in this use case?

scurk1415 avatar Jan 08 '25 13:01 scurk1415

yes - it works the same way as module (which defaults to ApiModule).
You need to provide a custom name for the configurationClass

{
  "$schema": "../node_modules/ng-openapi-gen/ng-openapi-gen-schema.json",
  "input": "user-api.yaml",
  "module": false,
  "configuration": "UserApiConfiguration"
}
{
  "$schema": "../node_modules/ng-openapi-gen/ng-openapi-gen-schema.json",
  "input": "chat-api.yaml",
  "module": false,
  "configuration": "ChatApiConfiguration"
}

then you can use it like

bootstrapApplication(AppComponent, {
  providers: [
    provideUserApiConfiguration({ rootUrl: USER_SERVICE_ENDPOINT_PREFIX }),
    provideChatApiConfiguration({ rootUrl: CHAT_SERVICE_ENDPOINT_PREFIX }),
  ]
})

mumenthalers avatar Jan 08 '25 15:01 mumenthalers

@luisfpg, is there anything I can do to help expedite this PR? We're very much looking forward to seeing this option being implemented.

colsen1991 avatar Jan 28 '25 14:01 colsen1991

Any updates?

michael-pisman avatar Mar 25 '25 02:03 michael-pisman

I've tested this. Looks great!

ivebeenlinuxed avatar Jun 13 '25 11:06 ivebeenlinuxed

@mumenthalers I see there are some conflicts to resolve now. I hope this can be merged soon. 🤞

bioc-druzgami avatar Aug 14 '25 10:08 bioc-druzgami