Skip to content

[BUG][Csharp][GenericHost] OpenApi 3.1: Model property of type map/additionalproperties gets generated as object#18772

Merged
wing328 merged 3 commits into
OpenAPITools:masterfrom
koendelaat:bugfix/additionalproperties-aka-map-treated-as-plain-object
Jun 2, 2024
Merged

[BUG][Csharp][GenericHost] OpenApi 3.1: Model property of type map/additionalproperties gets generated as object#18772
wing328 merged 3 commits into
OpenAPITools:masterfrom
koendelaat:bugfix/additionalproperties-aka-map-treated-as-plain-object

Conversation

@gerwinjansen
Copy link
Copy Markdown
Contributor

PR #17624 introduced an issue when generating code for a model with a property of type map/additionalproperties

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/configs/*.yaml
    ./bin/utils/export_docs_generators.sh
    

Input

Response:
  type: object
  properties:
    success:
      type: boolean
    results:
      additionalProperties: #key-value map
        oneOf:
          - $ref: '#/components/schemas/FileResult'
          - $ref: '#/components/schemas/StringResult'
  required:
    - success
    - results

Expected output

public Response(bool success, Dictionary<string, ResponseResultsValue>? results = default)
{
    Success = success;
    Results = results;
    OnCreated();
}

Actual output

public Response(bool success, Object? results = default)
{
    Success = success;
    Results = results;
    OnCreated();
}

@@ -0,0 +1,14 @@
# for csharp generichost
generatorName: csharp
outputDir: samples/client/petstore/csharp/generichost/net8/OneOfDiscriminator-3.1.0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the PR, which looks good me.

after merging, i'll replace this test (sample) with a unit test instead similar to other 3.1 tests we've added so far.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done via #18828

@wing328 wing328 merged commit c08afa3 into OpenAPITools:master Jun 2, 2024
@wing328 wing328 mentioned this pull request Jun 2, 2024
5 tasks
@wing328 wing328 added this to the 7.7.0 milestone Jun 2, 2024
welshm pushed a commit to welshm/openapi-generator that referenced this pull request Jun 5, 2024
…ditionalproperties gets generated as object (OpenAPITools#18772)

* Fix the bug + add test case

* Add sample output

* Update version number in new sample output

---------

Co-authored-by: Gerwin Jansen <gerwinjansen@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants