OpenAPITools / OpenAPITools/openapi-generator

[BUG] generator name: aspnetcore - generator type server. Actions in controller not found when using swaggerUI/openapiUI

Open
#17,396 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Dear development team,

following issue occured:

openapi-yml part (base url is not just server):
servers:

  • url: 'https://{server}/myBase'
    variables:
    server:
    default: localhost
    description: address of the server

Generated server stub.

Action part in Controller (important is Route, seems to be correct):
[HttpPost]
[Route("/myBase/weight/hu")]
[Consumes("application/json")]
[ValidateModelState]
[SwaggerOperation("ReceiveHuWeight")]
public virtual IActionResult ReceiveHuWeight([FromBody]List huWeight)

In Startup.cs
ConfigureServices....
.AddSwaggerGen(c =>
{....
c.DocumentFilter("/rest/cpi"); // possibly not correct

Leads to http error 404, when testing api in SwaggerUI/OpenapiUI of generated server

When removing " c.DocumentFilter("/rest/cpi");" everything works fine.

yaml has been created by customer and is not changeable. That means service has to start with base URL
"https://{server}/myBase"

Would you please check it and, if possible, do a fix to generator?

Best regards
Jörg

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 generated Startup.cs, the BasePathFilter configuration, and the controller route shown in the issue. Reproduce the 404 through SwaggerUI/OpenapiUI with the server URL https://{server}/myBase, then trace how the /rest/cpi filter interacts with /myBase. Done means the generated server and its UI resolve the documented base URL without requiring the YAML to change.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.