Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #783
Closed
Open
Issue created Aug 10, 2018 by Administrator@rootContributor

[C#] Issues with float type in models

Created by: albator1932

It is always in model properties afaik (at least that's where I have the issue), for instance I do have this JSON generated in my API:

FunctionParameters:{  
   description:"Represents the parameters for a function.",
   required:[  
      "dummy"
   ],
   type:"object",
   properties:{  
      dummy:{  
         format:"float",
         description:"Dummy value for illustration.",
         default:15,
         type:"number"
      }
   }
}

And the generated C# result will be:

public FunctionParameters(float? dummy = 15.0) {
	// use default value if no "dummy" provided
	if (dummy == null)
	{
		this.dummy = 15.0;
	}
	else
	{
		this.dummy = dummy;
	}
}

which gives these errors:

Error	CS1750	A value of type 'double' cannot be used as a default parameter because there are no standard conversions to type 'float?'
Error	CS0266	Cannot implicitly convert type 'double' to 'float?'. An explicit conversion exists (are you missing a cast?)

The generated C# code should be:

public FunctionParameters(float? dummy = 15.0f) {
	// use default value if no "dummy" provided
	if (dummy == null)
	{
		this.dummy = 15.0f;
	}
	else
	{
		this.dummy = dummy;
	}
}
Assignee
Assign to
Time tracking