OpenAPITools / OpenAPITools/openapi-generator

Mandatory parameters are assigned default values when generating Unity SDK using OpenAPI-Generator

Open
#15,565 1 comment 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

Hello,

I am using openapi-generator to create an SDK for Unity. Here is my generation script:

openapi-generator-cli generate -i swagger.json -g csharp-netcore --library unityWebRequest -o sdk-unity/ --skip-validate-spec --global-property modelTests=false --global-property apiTests=false --global-property modelDocs=false --global-property apiDocs=false --additional-properties packageName=BX.Rest

I have noticed that all methods in the resulting SDK have default values for their parameters, even for those that are marked as required in the swagger.json. Here's an example:

/// <param name="tutorialName">tutorialName (required).</param>
public CreateTutorialRaceBody(string tutorialName = default(string)) 

This seems strange because mandatory parameters shouldn't have default values.

I expect mandatory parameters not to have default values in the generated code.

Is there a solution to this issue? Perhaps I am missing something or there are additional parameters that I should be using?

Thanks

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 generation command, swagger.json, and the generated C# model such as CreateTutorialRaceBody. Check how required parameters are represented when using csharp-netcore with the unityWebRequest library. Done means generated required parameters no longer receive default values while optional parameters retain appropriate defaults.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, openapi, unity
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.