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
  • #11426
Closed
Open
Issue created Jan 27, 2022 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][CSHARP-NETCORE] OneOf generator for not nullable primitives generates invalid code.

Created by: jafin

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request
Description

A template that contains oneOf logic for a not nullable primitives generates invalid code.

openapi-generator version

5.4 and ff7c2bdb

OpenAPI declaration file content or url

Part of schema relating to this bug report:

PolymorphicProperty:
  oneOf:
  - type: boolean
  - type: string
  - type: object
  - type: array
     items:
  $ref: '#/components/schemas/StringArrayItem'
StringArrayItem:
  type: string
  format: string			

Full schema: https://gist.github.com/jafin/5b06f1a09e8a8c983bf25d61c47c1f4e

Generation Details

Checking non nullable primitive for null.

existing (compile error)

public PolymorphicProperty(bool actualInstance)
{
	//...
	this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}

for primitives should not have the conditional check, i.e.

public PolymorphicProperty(bool actualInstance)
{
	//...
	this.ActualInstance = actualInstance;
}

XML Comments should be escaped to accomodate to Generic <> Types

existing

/// <summary>
/// Initializes a new instance of the <see cref="PolymorphicProperty" /> class
/// with the <see cref="List<string>" /> class
/// </summary>
/// <param name="actualInstance">An instance of List<string>.</param>

better

/// <summary>
/// Initializes a new instance of the <see cref="PolymorphicProperty" /> class
/// with the <see cref="List&lt;string&gt;" /> class
/// </summary>
/// <param name="actualInstance">An instance of List&lt;string&gt;.</param>

Getter for Generic Type has an invalid method name

existing (won't compile)

public List<string> GetList<string>()

should maybe be:

public List<string> GetListString()
Steps to reproduce

Generate csharp code:

java -jar openapi-generator-cli.jar generate -i firefly-iii-1.5.5.yaml -g csharp-netcore --library httpclient
Related issues/PRs
Suggest a fix
Assignee
Assign to
Time tracking