swagger-api / swagger-api/swagger-codegen

codegen is not correctly generating common parameters for any language

Open
#10,397 1 comment 1 reaction 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

Per the swagger documentation, I should be able to have common parameters that are shared by all operations. The problem is that when running codegen locally, the generated code does not have any path parameters. The below yaml produces code for any language (I've tried two).

What is very confusing is that if I use this exact yaml in https://editor.swagger.io/, the generated code does have the path parameters. I ran this for two different languages, typescript:

image

And C#:

image

Left is the code generated in editor.swagger.io and right is my generated code by running codegen locally.

In both cases, the .swagger-codegen\VERSION the file is 3.0.20 which is the one I'm using but the code generated by https://editor.swagger.io/ does have the parameter paths.

Swagger-codegen version

3.0.20 downloaded from https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.20/swagger-codegen-cli-3.0.20.jar

Swagger declaration file content or url

This simple yaml file reproduces the issue:

openapi: 3.0.2
info:
    title: title
    version: 1.0.0
paths:
    '/instances/{id}':
        summary: Manipulate a particular instance
        get:
            responses:
                '200':
                    description: Ok
                    content:
                        text/plain:
                          schema:
                            type: string
                            example: pong
            summary: Fetches an instance
        parameters:
            -   in: path
                name: id
                schema:
                    type: integer
                required: true
components:
    securitySchemes:
        bearerAuth:
            scheme: bearer
            bearerFormat: JWT
            type: http
Command line used for generation
java   ^
    -classpath bin/swagger-codegen-cli.jar   ^
    -DdebugOperations                                                           ^
    io.swagger.codegen.v3.Codegen                                               ^
    generate                                                                    ^
    -i enterpos-api.yaml                                                        ^
    -l typescript-angular                                                       ^
    -o generated-code/typescript-angular-builtin

And that generated this output: https://gist.github.com/alanboy/45ce792255e079dd0de4f70449ebf455

Steps to reproduce

Just running the command line will always reproduce the issue;

Suggest a fix/enhancement

I feel like this might be wrong usage or something wrong with my yaml but I can't figure out what.

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 with the supplied OpenAPI YAML and the io.swagger.codegen.v3.Codegen generate command, then inspect the -DdebugOperations output and compare it with the generated code shown in the linked gist. Trace how path-level parameters are handled before language templates are rendered. Done means the {id} parameter appears in generated code for the affected languages while preserving the documented reproduction.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, openapi, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.