openapi-generator
openapi-generator copied to clipboard
[BUG] [ASPNETCORE] - Invalid model namespace added if no models exist
Bug Report Checklist
- [x] Have you provided a full/minimal spec to reproduce the issue?
- [x] Have you validated the input using an OpenAPI validator (example)?
- [x] Have you tested with the latest master to confirm the issue still exists?
- [x] Have you searched for related issues/PRs?
- [x] What's the actual output vs expected output?
- [ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Generate an OpenAPI declaration file, which contains no models for ASPNETCORE
. In the generated controllers an invalid namespace to Models
is added, which does not exist.
openapi-generator version
Version: 6.0.1
OpenAPI declaration file content or url
device_registration_api.yaml:
openapi: 3.0.1
info:
title: Device Registration API
description: API of the device registration server where phones get their configuration and firmware.
version: 1.0.0
contact:
name: WD
servers:
- url: 'http://localhost:3000'
tags:
- name: API
description: ''
paths:
'/CTL{MAC}.tlv':
get:
tags:
- API
summary: Get CTL file of the given MAC address
description: 'This file is not necessarily required by the phone for the registration process. To keep the file system organized, CTL files should be looked up in a subfolder `ctl` or may be retrieved from a database.'
operationId: getCTLByMACAddress
parameters:
- name: MAC
in: path
description: The MAC address of the phone requesting the CTL file
required: true
schema:
type: string
responses:
'200':
description: Requested file is found and is returned to the phone
'404':
description: Not Found
parameters:
- schema:
type: string
name: MAC
in: path
required: true
description: The MAC address of the requesting device
Generation Details
openApiGeneratorConfig.json:
{
"packageName": "DeviceRegistrationApi",
"packageTitle": "DeviceRegistrationApi",
"packageCopyright": "WD2023",
"packageVersion": "1.0",
"aspnetCoreVersion": "6.0",
"buildTarget": "library",
"isLibrary": "true",
"operationIsAsync": "true",
"operationResultTask": "true",
"nullableReferenceTypes": "true",
"operationModifier": "abstract",
"swashbuckleVersion": "6.0.0",
"useNewtonsoft": "false",
"sourceFolder": ""
}
Steps to reproduce
- Create file
device_registration_api.yaml
containing the OpenAPI declaration - Create file
openApiGeneratorConfig.json
containing the generation details - Run
openapi-generator-cli generate -i .\device_registration_api.yaml -g aspnetcore -c .\openApiGeneratorConfig.json -o .\out
- Open file
out/DeviceRegistrationApi/Controllers/APIApi.cs
, which contains the lineusing DeviceRegistrationApi.Models;
, however namespaceModels
does not exist and thus building the application will fail.
Related issues/PRs
No related issues found
Suggest a fix
As no models are specified in the OpenAPI file, no models are generated and thus no Models
namespace exists, which is correct. So the controllers should not have a namespace to Models
, however the generator still adds a reference, which is wrong. I assume, controller generation does not check if there were models generated.