OpenAPITools / OpenAPITools/openapi-generator

[BUG] The "partial" modelClassModifier doesn't seem to work for aspnetcore generator.

Open
#9,819 2 comments 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

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 (example)
Description

According to OpenAPI generator doc, modelClassModifier can be used to generate partial model for aspnetcore generator. So I'm expecting the following command gives me partial model classes.

openapi-generator-cli generate -g aspnetcore -i test.json -o ./src/ --additional-properties=aspnetCoreVersion=5.0,packageName=MyNamespace,sourceFolder=,operationResultTask=true,classModifier=abstract,modelClassModifier=partial,buildTarget=library,swashbuckleVersion=5.0.0

But it turns out the generated C# model classes don't have "partial" modifier.

openapi-generator version

5.1.1 and latest master

OpenAPI declaration file content or url

Here is the content of test.json used in the above command line.

{
    "openapi":"3.0.2",
    "info": {
        "title":"Test APIs",
        "version":"1.0"
    },
    "servers": [
        {"url":"/"}
    ],
    "components": {
        "schemas": {
            "TestObj": {
                "type":"object",
                "properties": {
                    "name": {
                        "type": "string"
                    }
                }
            }
        }
    },
    "paths": {
        "/tests": {
            "post": {
                "tags": [
                    "Tests"
                ],
                "description": "Create a new test object.",
                "requestBody": {
                    "description": "The test object to create.",
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/TestObj"
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    }
}
Generation Details
Steps to reproduce
  1. Save the above OpenAPI definition into a file called test.json.
  2. Run the following command line in the same directory where test.json lives.
openapi-generator-cli generate -g aspnetcore -i test.json -o ./src/ --additional-properties=aspnetCoreVersion=5.0,packageName=MyNamespace,sourceFolder=,operationResultTask=true,classModifier=abstract,modelClassModifier=partial,buildTarget=library,swashbuckleVersion=5.0.0

Expected result:

The generated C# model class should have "partial" modifier.

namespace MyNamespace.Models
{ 
    /// <summary>
    /// 
    /// </summary>
    [DataContract]
    public partial class TestObj : IEquatable<TestObj>
    {

Actual result:

The generated C# model class doesn't have "partial" modifier.

namespace MyNamespace.Models
{ 
    /// <summary>
    /// 
    /// </summary>
    [DataContract]
    public class TestObj : IEquatable<TestObj>
    {
Related issues/PRs
Suggest a fix

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 by running the provided openapi-generator-cli command with test.json and inspect the generated aspnetcore C# model output. Trace the aspnetcore generator entry point and its model template or modifier handling to determine why modelClassModifier is ignored. Done means the generated TestObj declaration includes the requested partial modifier.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.