OpenAPITools / OpenAPITools/openapi-generator
[BUG] [csharp-functions] custom packageName value is not used for usings in DefaultApi class
Nobody has claimed this yet.
- 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
Generator used: csharp-functions
After generation and without 'human' changes, solution is not building.
1st issue:
After setting up custom packageName, DefaultApi file generated with it has wrong using.
It has default using Org.OpenAPITools.Models;, but should be using FirstName.RestApiServer.Models; in this case.
2nd issue is that it does not put using System.Collections.Generic;.
After manually fixing these 2 usings, solution is compiling with success.
openapi-generator version
Using latest docker image. First time using that generator, so do not know if it is regression.
OpenAPI declaration file content or url
openapi: '3.0.3'
info:
title: TestApi
description: xyz
version: 1.0.0
servers:
- url: 'https://xyz/api'
description: Production server
- url: 'localhost/api'
description: TEST
paths:
/test:
get:
summary: "Test if server is working"
description: "Test if server is working"
responses:
'200':
description: OK
content:
application/json:
schema:
type: string
/matches:
get:
summary: "Get matches for user"
responses:
'200':
description: OK
content:
application/json:
schema:
type: array
items:
type: object
properties:
prop1:
type: integer
prop2:
type: string
Generation Details
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate `
-i /local/spec.yml `
-g csharp-functions `
-o /local/out/server `
--additional-properties=packageName=FirstName.RestApiServer
Steps to reproduce
- Run generation command
- Open solution in VS 2022.
- Try to compile it
Results from VS:
Build started at 11:03...
1>------ Build started: Project: FirstName.RestApiServer, Configuration: Debug Any CPU ------
1>D:\repos\GeneratorBug\out\server\src\FirstName.RestApiServer\Functions\DefaultApi.cs(14,7,14,10): error CS0246: The type or namespace name 'Org' could not be found (are you missing a using directive or an assembly reference?)
1>D:\repos\GeneratorBug\out\server\src\FirstName.RestApiServer\Functions\DefaultApi.cs(21,40,21,72): error CS0246: The type or namespace name 'List<>' could not be found (are you missing a using directive or an assembly reference?)
1>D:\repos\GeneratorBug\out\server\src\FirstName.RestApiServer\Functions\DefaultApi.cs(21,45,21,71): error CS0246: The type or namespace name 'MatchesGet200ResponseInner' could not be found (are you missing a using directive or an assembly reference?)
1>Done building project "FirstName.RestApiServer.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 11:03 and took 01,268 seconds ==========
Related issues/PRs
Do not know
Suggest a fix
Something with using list.
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 by reproducing the issue with spec.yml, the csharp-functions generator, and packageName=FirstName.RestApiServer, then inspect the generated src/FirstName.RestApiServer/Functions/DefaultApi.cs. Compare its using directives with the reported compiler errors and rebuild the generated solution in Visual Studio. Done means the generated project builds without manually changing DefaultApi.cs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, openapi
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100