swagger-api / swagger-api/swagger-codegen
[ELIXIR] Inconsistency between code docs and generated code
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
The optional params are underscored in the code documentation. But the opts keyword list requires them to be in the form given by the baseName, which is coming directly (unprocessed) from the Swagger definition.
# NOTE: This class is auto generated by the swagger code generator program.
# https://github.com/swagger-api/swagger-codegen.git
# Do not edit the class manually.
defmodule Sample.Api.Default do
@moduledoc """
API calls for all endpoints tagged `Default`.
"""
alias Sample.Connection
import Sample.RequestBuilder
@doc """
Add sample
## Parameters
- connection (Sample.Connection): Connection to server
- opts (KeywordList): [optional] Optional parameters
- :sample_name (Somestring): Sample Name
## Returns
{:ok, %{}} on success
{:error, info} on failure
"""
@spec add_sample(Tesla.Env.client, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
def add_sample(connection, opts \\ []) do
optional_params = %{
:"SampleName" => :body
}
%{}
|> method(:post)
|> url("/sample")
|> add_optional_params(optional_params, opts)
|> Enum.into([])
|> (&Connection.request(connection, &1)).()
|> decode(false)
end
end
Swagger-codegen version
2.4.0-Snapshot
Swagger declaration file content or url
swagger: "2.0"
info:
description: "Sample"
version: "1.0.0"
title: "Sample"
basePath: "/"
schemes:
- "http"
paths:
/sample:
post:
summary: "Add sample"
description: ""
operationId: "addSample"
parameters:
- in: "body"
name: "SampleName"
description: "Sample Name"
schema:
$ref: "#/somestring"
responses:
405:
description: "Invalid input"
Command line used for generation
/run-in-docker.sh generate -i sample-swagger.yaml -l elixir -o /gen/sample
Steps to reproduce
Run the command above with the provided input.
Related issues/PRs
Suggest a fix/enhancement
In the following mustache template
https://github.com/swagger-api/swagger-codegen/blob/4b9ee1f1940dba349d49dfb499b813f4cbb5858c/modules/swagger-codegen/src/main/resources/elixir/api.mustache#L37
the parameter isn't properly underscored. 'underscoring' them like in the documentation would fix it. However this introduces backward incompatibilities and I am not sure what's the policiy wrt. to such changes. Otherwise I could contribute a fix.
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 modules/swagger-codegen/src/main/resources/elixir/api.mustache at the referenced line, then generate the sample from the provided Swagger declaration using /run-in-docker.sh. Compare the parameter spelling in the generated documentation with the opts keyword list. Done means the generated Elixir API presents and accepts consistent parameter names, with compatibility implications understood.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- elixir
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100