Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the baseUrl of elixir APIs to be overridden #12268

Merged

Conversation

johannesE
Copy link
Contributor

Elixir uses config.exs files to store most configuration values. This change allows the baseURL to be overridden with dev.exs and prod.exs in a project using the generated code.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@mrmstn

@johannesE johannesE force-pushed the elixir-allow-base-url-override branch from 796ed8a to 303b028 Compare April 28, 2022 15:28
@mrmstn
Copy link
Contributor

mrmstn commented Apr 28, 2022

Awesome, thank you very much for your contribution :D!

I've added a comment to your code, every thing else looks good to me 👍

(And I'm also quite unsure about my sugestion. I would simply add it for the sake of backwords compatibilty)

@mrmstn
Copy link
Contributor

mrmstn commented Apr 28, 2022

A little off-topic – but I'm currently making some extra changes in my connection.ex (which haven't found its way to this generator) so you might also be interested in something like this:

https://github.com/mrmstn/nomad_client/blob/main/lib/nomad_client/connection.ex

This solution is much more flexible since it allows you to use multiple URLs and also give some extra room to add some more middlewares or changing the adapter for the specific module. I'm very interested in some feedback about this practice.

Nonetheless, I'm a great fan of this PR :)!

@johannesE
Copy link
Contributor Author

#12268 (comment)

Yes, that seems a lot more flexible and a little more complicated. Having the option to override the http adapter sounds great. We'd just need to document it with some examples and a link to the tesla configuration options. If you ever decide to give it a go for the main generator, I'll gladly check it out.

I'd probably change
config :tesla, NomadClient.Connection, ... to
config NomadClient.Connection, :tesla, ... though.

@wing328
Copy link
Member

wing328 commented May 1, 2022

Tested locally and the result is good:

Generated openapi_petstore app
You have configured application :open_api_petstore in your configuration file,
but the application is not available.

This usually means one of:

  1. You have not added the application as a dependency in a mix.exs file.

  2. You are configuring an application that does not really exist.

Please ensure :open_api_petstore exists or remove the configuration.

...

Finished in 0.2 seconds (0.00s async, 0.2s sync)
3 tests, 0 failures

Randomized with seed 183352
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  11.087 s
[INFO] Finished at: 2022-05-01T15:48:27+08:00
[INFO] ------------------------------------------------------------------------

@halostatue
Copy link
Contributor

@wing328 @mrmstn As I mentioned in #12751, there are changes that should be made to how the connection.ex is created, and the example provided by @mrmstn is very close to what I plan on doing as a future PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants