Configure BaseUrl for imported OpenAPI feature

I am using Swagger/OpenAPI to autogenerate the api interface from a Django backend for an Aurelia frontend client.

This works really great, but I cant figure out how to configure the Base Url.

I can manually set it in the autogenerated files, but this gets overwritten whenever I regenerate the code.

In my main.ts I add the api as a feature and I thought i could do something like this:

    .feature('api', {basePath: '/path/to/api/'})

but that is not working. Does anyone have a tip for me?

1 Like

It really depends on what the generated files look like. The feature e.g can point to an index.ts which contains a configure function. So when the feature gets loaded this gets called first. In there you can manipulate or set things as you want. So if you can colocate the index.ts next to your generated files this should work.

1 Like

!Edited: no, this ( below) did not work actually. My manual edit of the basepath directly in the autogenerated code was still hanging around in some cached code. I will continue to hack around for a solution and post it here.

thanks @zewa666 , “configure function” was the key! I was trying to load some configuration as an object. I looked at how some other plugins were being registered.

Here is the correct way to configure the basePath:

    .feature('api', baseConfig => {
      baseConfig.configure({basePath: '/path/to/api/'});

For anyone that is interested in using openapi, here’s how I have things set up.

the openapi cli is installed using npm or yarn:

npm install @openapitools/openapi-generator-cli -g

In Django I am using the Django Rest Framwork together with drf_yasg ( Yet another Swagger generator ).

The command to autogenerate the API interfaces for Aurelia:

openapi-generator generate -g typescript-aurelia -o ./my/aureali-app/src/api/ -i --skip-validate-spec

The advantage is that you get all the typescript autosuggest options while writing code that connects to your server api. If you change your server side API, you can regenerate the typescript files. You get some minimal consistency checking when you build your aurelia app. If you try to access some fields that no longer exists you’ll get warnings and errors when you build your app.

By the way, a big “Thanks you!” to whoever wrote the aurelia exporters for openapi. I was not expecting this to all work so easily.