OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Csharp] Mustash templates remove explicit namespace for System.IO.Path
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated Client/ApiClient.cs from the supplied Docker command and trace it back to the C# Mustache templates changed by #18915. Compare the output with the report’s expected System.IO.Path qualification; done means generated code remains usable when the consuming project defines its own Path class.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100