swagger-api / swagger-api/swagger-codegen

[Csharp] - ParameterDescriptor is nullable.

Open
#9,375 0 comments 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

I created my "OpenAPI.yaml" and I got ASPNetCore codes using OpenAPI Generator.
So, I started the Server and I access "http://localhost:xxxx/swagger/index.html" on the browser.
But I got Error.
I noticed that "par.ParameterDescriptor" is nullable.

(GeneratePathParamsValidationFilter.cs)

23:           foreach (var par in pars)
24:           {
25:               var attributes = ((ControllerParameterDescriptor)par.ParameterDescriptor).ParameterInfo.CustomAttributes; // here!

would you please check this?

Swagger-codegen version

3.0.2

Command line used for generation

I'm using Windows Power Schell.

docker run --rm -v ${PWD}:/work --workdir=/work openapitools/openapi-generator-cli generate -i ./root.yml -g aspnetcore  -o ./out/ASPNetCore -c ./config.yml
Steps to reproduce
  1. Create OpenAPI YAML file.
  2. Generate ASPNetCore code using openapi-generator-cli.
  3. Run the Server (using VisualStudio 2019) - debug mode.
  4. Access the Server on the Browser.
    -> Get Error on Visual Studio.
Suggest a fix/enhancement

I tried it, and it works fine.

//                var attributes = ((ControllerParameterDescriptor)par.ParameterDescriptor).ParameterInfo.CustomAttributes;  // Original is comment out.
                var cpd = (ControllerParameterDescriptor)par.ParameterDescriptor;
                var attributes = cpd == null ? null : cpd.ParameterInfo.CustomAttributes;

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 GeneratePathParamsValidationFilter.cs in the generated ASPNetCore server and reproduce the failure using the provided Docker command and OpenAPI YAML. Trace why par.ParameterDescriptor is nullable and verify the generated server starts and serves its Swagger page without the error.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.