-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Description
The newest version of the api generator v7.7.0 (#18915) removes specific namespaces (System.IO.Path) for templates on Csharp. This produces autogenerated code that may have conflict when imported to an existing project if there is an existing Path class.
To solve the problem, either the existing project has to rename their classes or add the missing namespaces in the autogenerated code.
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?
On the latest release the issue #18915 remove namespaces from the mustash templates ware added.
- What's the actual output vs expected output?
actual output:
ApiClient.cs
internal object Deserialize(RestResponse response, Type type)
{
if (type == typeof(byte[])) // return byte array
{
return response.RawBytes;
}
// TODO: ? if (type.IsAssignableFrom(typeof(Stream)))
if (type == typeof(Stream))
{
var bytes = response.RawBytes;
if (response.Headers != null)
{
var filePath = string.IsNullOrEmpty(_configuration.TempFolderPath)
? Path.GetTempPath()
: _configuration.TempFolderPath;Expected:
internal object Deserialize(RestResponse response, Type type)
{
if (type == typeof(byte[])) // return byte array
{
return response.RawBytes;
}
// TODO: ? if (type.IsAssignableFrom(typeof(Stream)))
if (type == typeof(Stream))
{
var bytes = response.RawBytes;
if (response.Headers != null)
{
var filePath = string.IsNullOrEmpty(_configuration.TempFolderPath)
? global::System.IO.Path.GetTempPath() //Full namespace or import using Path = global::System.IO.Path; at the top
: _configuration.TempFolderPath;- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The newest version of the api generator v7.7.0 (#18915) removes specific namespaces (System.IO.Path) for templates on Csharp. This produces autogenerated code that may have conflict when imported to an existing project if there is an existing Path class.
openapi-generator version
v7.7.0
OpenAPI declaration file content or url
Using a single schema the generated code removes the namespaces
openapi: 3.0.1
info:
title: Testing single
version: 0.0.1
paths:
/single/session/{userId}:
get:
summary: Single endpoint session
parameters:
- name: userId
in: path
description: The identity of the user.
required: true
schema:
type: string
responses:
'200':
description: Session found
content:
application/json:
schema:
$ref: '#/components/schemas/Session'
example:
userId: bob
created: 1698256753
'400':
description: Bad Request.
'404':
description: If no session found
components:
schemas:
Session:
type: object
properties:
userId:
type: string
description: Identify the user for the active session.
created:
type: integer
description: Identify the creation of the session.
format: int64
additionalProperties: false
description: Represents the active session of the user.Generation Details
Executing the docker
Steps to reproduce
Execute the lastes version
docker run --rm openapitools/openapi-generator-cli:v7.7.0 generate -i ./swagger.json --package-name Sdk.Simple -g csharp -o ./Sdk/Simple --additional-properties targetFramework=net8.0
The output code in /Sdk.Simple /Client/ApiClient.cs does not have the namespaces
Related issues/PRs
#18915 removed namespaces for PATH
Suggest a fix
Fully qualify the autogenerate clases to avoid collision when importing on another project