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
  • Merge requests
  • !11427

fix: [csharp-netcore]: oneOf fixes for Primitive types

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/jafin/fix/csharp-oneOf into master Jan 27, 2022
  • Overview 0
  • Commits 2
  • Pipelines 0
  • Changes 31

Created by: jafin

  • Conditionals for string and Object to still throw ArgumentException but NOT for non nullable primitives
  • Escape type in XML comment to avoid issues with types rendering. Relates to #11426 11426

Part of schema causing challenges:

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

-An oneOf notnullable with primitives as options would generate non functioning code in the csharp-netcore generator.

Issues encountered

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.");
}

change: (only for primitives, Note: I noticed that Object and string are returning isPrimitive:true in the model, so extra checks where made for these types)

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 invalid method name

existing (won't compile)

public List<string> GetList<string>()

changes to:

public List<string> GetListString()

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh

TRIED TO RUN /bin/generate-sample.sh but it errors with

samples/openapi3/client/petstore/java/jersey2-java8-special-charactersCan't load config class with name 'java-micronaut-server'

EDIT : .Possibly misunderstood , was able to run and update generated code

/bin/generate-samples.sh ./bin/configs/csharp-netcore*

Please advise if there is anything more I should do for this PR, I am new to this repo and nill exposure to Java.

  • File the PR against the correct branch: master (5.3.0), 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request. @mandrean @frankyjuang @shibayan @Blackclaws @lucamazzanti
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/jafin/fix/csharp-oneOf