swagger-api / swagger-api/swagger-codegen

[codegen] CodegenOperation.pathWithoutBaseName() appears broken isRestful* methods

Open
#10,025 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

Most of the CodegenOperation.isRestful methods call pathWithoutBaseName.

This tries to remove the string "/baseName" from the path. Usually, this is evaluated against something. In my api case, my path is GET "/api/v1/addresses/{id}" as an example. However the baseName is "AddressResource". Naturally AddressResource does not appear in the path. It matches my resource class name, but that string also does not appear in my swagger spec. As my baseName does not appear on the path, this method can never work.

As I am writing my own template, it's possible I missed something

In examining the other templates, I cannot see any existing templates invoke this method.

Swagger-codegen version

3.0.16

Swagger declaration file content or url

Trimmed to just the method

    "/api/v1/addresses/{id}" : {
      "get" : {
        "tags" : [ "address-resource" ],
        "summary" : "getAddress",
        "operationId" : "getAddressUsingGET",
        "produces" : [ "application/json" ],
        "parameters" : [ {
          "name" : "id",
          "in" : "path",
          "description" : "id",
          "required" : true,
          "type" : "string"
        } ]
Related issues/PRs

https://github.com/swagger-api/swagger-codegen/issues/4030

This is a related issue, and came up in my search. It's similar, and I agree there are problems with isMemberPath() also. I'd probably say tweak these to be a bit more open.

Suggest a fix/enhancement

I'm happy to try to code some suggested alternatives for these methods. I'd appreciate a pointer to what I might be doing wrong with CodegenOperation.baseName though, as it does not appear to match the path. Is there a debug option or unit test I can breakpoint in here and read all the data?

I can understand the idea of pathWithoutBaseName, but I'm not sure how it can cope with myriad api designs and work. I'm keen to hear your design choices behind it, but I'd be inclined to drop it altogether. The features of isRestfulShow, Index, Create, etc, are great and I want them in my template. I don't yet see why it needs to care a about the structure of my path though.

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 at CodegenOperation.pathWithoutBaseName() and the isRestful* methods, then trace how baseName is populated and used for the supplied path example. The payload names no source file or test; done means the intended path/baseName behavior is clarified and covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi
Domain
tooling
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.