* Further Elixir Client Improvements
Resolves#12731 and is the completion of the work that I started with
#12751.
The changes here are extensive and likely resolve an issue that I have
seen with the Ory SDK (ory/sdk#194). I have also been unable to run the
integration suite for Elixir as I am (trying) to run everything in
Docker (`./run-in-docker.sh`) as I *do not* have a suitable Java
development environment set up, and do not do enough Java work to really
justify it.
- Updated the README for Elixir projects. Aside from some improved
readability of the template by use of link references instead of
inline links, I have also fixed the examples:
- The `deps` example should have been putting a version constraint
related to `appVersion`.
- The `config` example should have been using `packageName` instead of
`appName`. This particular issue repeats.
- In all Elixir files:
- Changed the function `@docs` formatting:
- changed the ehading level for `Parameters` and `Returns` to h3
(`###` instead of `##`). This will make somewhat better looking
documentation that does not over-emphasize these details (which
are *not* documented in a normal Elixir way, but this is somewhat
to be expected with a code generator.) It may be desirable, after
testing, to change this to `h4` instead of `h3`.
- Put parameter names and most return types in in-line code blocks
(`` `hello` ``).
- Put return types, when there are multiple types, in a Markdown
list.
- Fixed a lot of the spacing. Most files will be *closer* to Elixir
standard formatting than they were. Because of the limitations of
Mustache, it is still recommended that people who generate Elixir
clients run `mix format` at least once on their codebase.
- `api.mustache`:
- Removed an awkward function pipeline call. If we specified at least
Elixir 1.12 (something that I do not recommend as we have recently
jumped from requiring Elixir 1.6 to Elixir 1.10), there is a better
way to specify this now with `Kernel.then/2`. In the meantime,
assigning the constructed request structure to a variable and then
making a separate pipeline for the request execution and handling
makes for *much* easier to read generated code.
- Fixed the extra space issue with `evaluate_response` call tuple
values; `{{=<% %>=}}` changes the tag types, so this change is
intentional.
- In `config.exs.mustache`, `runtime.exs.mustache`, `mix.exs.mustache`,
and `connection.ex.mustache`, use `packageName` instead of `appName`
for configuration specification. If `packageName` and `appName`
differed, we would end up with cases like ory/sdk#194.
- `connection.ex.mustache` has been almost entirely rewritten. The
changes started in order to eliminate a `@doc` compile-time warning,
but shifted to remove the old way of building Tesla client structs
with `use Tesla`. It works, but is no longer the recommended way of
building Tesla clients.
- The *recommended* way of building a Tesla Client would now be
`Tesla.client(Connection.middleware(), Connection.adapter())`.
- Exposed both `Connection.adapter/0` and `Connection.middleware/1`
for use. `Connection.middleware/1` has special handling for the
cases where OAuth2 or HTTP Basic Auth are defined in the
application, but do not currently handle any other auth methods.
- `deserializer.ex.mustache` has mostly been reformatted. There are
things that I do not like about it (I do not like pipelines with one
line), and I have expanded one function capture into an anonymous
function for readability.
- `request_builder.ex.mustache` has been updated with better
function and parameter descriptions and names. Please note that if
`request |> method(:delete) |> method(:post)` is supposed to produce
a `POST` operation, we will need to change from `Map.put_new/3` to
`Map.put/3`.
- Reordered `evaluate_response/2` so that it is the function documented,
and made `decode/2` and `response_mapping/3` private functions. As
far as I can tell, I have *not* changed the functionality.
* Address issues found in code review
- The example dependency code in the README had dropped the opening
brace for the tuple. This has been resolved.
- The default formatting of the API pipelines has been adjusted to
minimize possible changes from `mix format`.
* Update modules/openapi-generator/src/main/resources/elixir/api.mustache
Co-authored-by: Michael Ramstein <633688+mrmstn@users.noreply.github.com>
* Update modules/openapi-generator/src/main/resources/elixir/connection.ex.mustache
Co-authored-by: Michael Ramstein <633688+mrmstn@users.noreply.github.com>
* Update modules/openapi-generator/src/main/resources/elixir/connection.ex.mustache
Co-authored-by: Michael Ramstein <633688+mrmstn@users.noreply.github.com>
* Update templates based on review comments
Co-authored-by: Michael Ramstein <633688+mrmstn@users.noreply.github.com>
* Allow the baseUrl of elixir APIs to be overridden
* Run generator
* Add missing `:`
* Update modules/openapi-generator/src/main/resources/elixir/connection.ex.mustache
Co-authored-by: Michael Ramstein <633688+mrmstn@users.noreply.github.com>
* Generate sample with new change
Co-authored-by: Joe Eifert <joe@databerg.rocks>
Co-authored-by: Michael Ramstein <633688+mrmstn@users.noreply.github.com>
* [Elixir] update version / add test
* update samples (add missing 200 responses in petstore-with-fake-endpoints-models-for-testing.yaml)
* [Elixir] update to 1.6 version
* [Elixir] fix test petapi
* Update Tesla dependency and replace Poison with Jason
* Use new Tesla method to set headers
* Fix jason dependency definition
* Use list for Headers instead of a map
* Rollback to Poison because Jason does not support 'as:' option to decode to arbitrary struct
* Use new return signature from Tesla 1.0 in decode function
* catch error when a struct is given as second parameter to RequestBuilder.decode
* Update modules/openapi-generator/src/main/resources/elixir/request_builder.ex.mustache
Co-Authored-By: yknx4 <yknx.4.b@gmail.com>
* Update modules/openapi-generator/src/main/resources/elixir/request_builder.ex.mustache
Co-Authored-By: yknx4 <yknx.4.b@gmail.com>
* Evaluate response based on status code
* Generate Petstore
* pin poison to ~> 3.0.0 since 4.0.0 does not work atm
* run ./bin/openapi3/elixir-petstore.sh
* Fix dependencies and generate model classes
* Better elixir client generation.
Responses are parsed and serialized by Poison into the model structs.
Use shared helper functions to generate the request.
Extract client connection configuration from api calls.
Elixir client can sanitize the operationId
Correctly output the model variables. Fix typos
Fix path replacement when there are multiple replacements
Cannot separate globally shared parameters from operations
Error handling for the tesla response
update templates
Can generate clients that compile
Can make requests - parse optional params, build query
Add oauth to connection. Fix connection directory
Add basic auth helper for creating a connection
Fix map types. Fix guard clauses for creaing connections
Add licenceInfo template. Parse config for moduleName via standard invokerPackage option
Can provide and inject a license header into all source files
fix location of connection.ex
Move shared code into reusable modules
Elixir filenames should be underscored
Fix visibility of helper functions
Parse the packageName from config options
Handle date and datetime fields with DateTime.from_iso8601
Fix indentation
Update documentation, add typespecs
Generate a standard elixir .gitignore
typespec is calculated recursively in java
Use the JSON middleware and using Poison.Decoder.decode on already parsed structs
move decoded struct into java
Fix handling of non-json responses
Switch basic auth to use the provided Tesla.Middleware.BasicAuth
Update README template to include the appDescription
Update sample elixir client
remove junk client models that don't belong with petstore
Only implement Poison.Decoder protocol if needed
Update samples with skipped Poison.Deocder impl
* Handle multipart file uploads
Handle building form params in the body
Files are handled as strings for input
* Requests with no defined return type will return the Tesla.Env response
* Run the bin/elixir-petstore.sh
* Add elixir client
* Add test for elixir client
* Add shell script for generating sample codes for elixir client
It just copied from bin/bash-petstore.sh
* Make elixir-petstore.sh to generate sample codes for elixir client
* Add sample codes for elixir client