swagger-api / swagger-api/swagger-codegen

[ELM] Functions generated from operationId can have invalid names

Open
#10,587 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

The operationId field of paths can have values which are not valid Elm identifiers. It seems that these values are used unmodified to produce Elm function names, meaning that the generator produces invalid Elm code.

This happens, for example, when operationId values contain "."s, as is common when using connexion.

Swagger-codegen version

2.4.17

Swagger declaration file content or url
basePath: /
consumes:
- application/json
info:
  description: An API
  title: An API
  version: '1.0'
paths:
  /:
    get:
      operationId: get.foo.bar
      responses:
        '200':
          description: Success
produces:
- application/json
swagger: '2.0'
Command line used for generation

swagger-codegen generate -i broken.yaml -l elm -o gen

Steps to reproduce
  1. Put the above YAML into broken.yaml
  2. Run the command above
Suggest a fix/enhancement

At least for my purposes, replacing '.' with '_' in the function names would do the trick. There may be more characters in valid operationId's which are invalid in Elm identifiers, though, so someone who knows the spec should find all translations that need to happen.

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

Start by running the provided broken.yaml declaration with swagger-codegen generate -i broken.yaml -l elm -o gen, then inspect the generated Elm function name for get.foo.bar. Trace how operationId values reach the Elm output and account for invalid identifier characters; done means the generated code is valid Elm for this example and other invalid operationId values are handled consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
elm
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.