OpenAPITools / OpenAPITools/openapi-generator

[BUG] invalid implementation of get_cowboy_config/2

Open
#6,354 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug Server: Erlang
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue? - any spec
  • Have you validated the input using an OpenAPI validator (example)? yes
  • What's the version of OpenAPI Generator used? v4.3.1
  • Have you search for related issues/PRs? yes
  • What's the actual output vs expected output? see suggest a fix section
  • [Optional] Bounty to sponsor the fix (example)
Description

invalid implementation of get_cowboy_config/2

openapi-generator version

v4.3.1 or the latest docker image

OpenAPI declaration file content or url

any valid declaration

Command line used for generation
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:v4.3.1 \
           -g erlang-server  -i /local/openapi.yaml -o /local/erlang_server
Steps to reproduce
  1. generate an erlang-server
  2. check *_server.erl file, notice invalid implementation of get_cowboy_config/2 / get_cowboy_config/3 functions.
Related issues/PRs

none

Suggest a fix
  • implementation of get_cowboy_config/2 should look like this:
get_cowboy_config(LogicHandler, ExtraOpts) ->
    DefaultOpts = get_default_opts(LogicHandler),
    DefaultEnv = maps:get(env, DefaultOpts, #{}),
    ExtraEnv = maps:get(env, ExtraOpts, #{}),
    Env = maps:merge(DefaultEnv, ExtraEnv),
    Opts = maps:merge(DefaultOpts, ExtraOpts),
    maps:put(env, Env, Opts).
  • remove get_cowboy_config/3 and store_key/3 local functions
  • change default value for cowboy_extra_opts from an empty list ([]) to an empty map (#{})
  ExtraOpts = maps:get(cowboy_extra_opts, Params, #{}),
  • add cowboy_extra_opts to the *_server:start/2 spec definition:
-spec start( ID :: any(), #{
    ip                => inet:ip_address(),
    port              => inet:port_number(),
    logic_handler     => module(),
    net_opts          => [],
    cowboy_extra_opts => cowboy:opts()
}) -> {ok, pid()} | {error, any()}.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Generate an erlang-server with the provided Docker command and inspect the generated *_server.erl file, focusing on get_cowboy_config/2, get_cowboy_config/3, and store_key/3. Compare the generated functions and start/2 specification with the requested behavior; done means the configuration uses map-based cowboy_extra_opts and the generated Erlang code is valid.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, erlang
Domain
api, backend, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.