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
  • #9096
Closed
Open
Issue created Mar 26, 2021 by Administrator@rootContributor2 of 6 checklist items completed2/6 checklist items

[BUG] Generation of models with invalid imports (aspnetcore)

Created by: riede

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

After generating models for .Netcore 3.1 the models contains unused usings (imports). However, running dotnet build fails because one of the unused usings reference to a namespace that doesn't exist anymore. You can see it in the following image:

image

The referenced namespace exists when I generate all files. But I only need the models. The import seems to be a relict of generated files (necessary for generating the models) that are removed afterwards while the import still exists

openapi-generator version
❯ openapi-generator version
5.1.0
OpenAPI declaration file content or url

In the following you can find the openapi.json:

openapi.json

{
    "openapi": "3.0.2",
    "info": {
        "title": "TestProject",
        "version": "0.0.1"
    },
    "paths": {
        "/api/Product": {
            "get": {
                "tags": [
                    "Product"
                ],
                "summary": "Product",
                "operationId": "product_api_Product_get",
                "responses": {
                    "200": {
                        "description": "Successful Response",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "title": "Response Product Api Product Get",
                                    "type": "array",
                                    "items": {
                                        "$ref": "#/components/schemas/Product"
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "Product": {
                "title": "Product",
                "required": [
                    "id"
                ],
                "type": "object",
                "properties": {
                    "id": {
                        "title": "Id",
                        "type": "string",
                        "format": "uuid"
                    },
                    "machine": {
                        "title": "Machine",
                        "type": "string",
                        "nullable": true
                    }
                }
            }
        }
    }
}
Generation Details

config.json:

{
    "aspnetCoreVersion": 3.1,
    "swashbuckleVersion": "5.0.0",
    "packageName": "TestProject",
    "packageTitle": "TestProject",
    "sourceFolder": ""
}
Steps to reproduce
  • use the config.json and the openapi.json
  • run openapi-generator generate -i openapi.json -g aspnetcore --config config.json --global-property models,modelDocs=false
Expected behaviour

The models were generated at least without using TestProject.Converters;. Much better would be a solution where unused usings will be removed.

Related issues/PRs
Suggest a fix
Assignee
Assign to
Time tracking