swagger-codegen-generators
swagger-codegen-generators copied to clipboard
[c-sharp] Misleading version comment: OpenAPI spec version reports API version
Description
Files in the client folder generated for csharp contain a misleading comment near the head (Example for Simple API at API version 1.1.0 (no modifications from default, just a new version code) with OpenAPI spec 2.0 and 3.0):
/*
* Simple Inventory API
*
* This is a simple API
*
* OpenAPI spec version: 1.1.0
* Contact: [email protected]
* Generated by: https://github.com/swagger-api/swagger-codegen.git
*/
The comment indicates which OpenAPI specification was used to generate the client, when in fact it is the API version that's reported there.
Swagger-codegen version
3.0.28
Swagger declaration file content or url
Link: https://api.swaggerhub.com/apis/liam.baloh/all2/1.1.0 (it's the default simple inventory API for openAPI 2.0 with a new version made at 1.1.0 with no further modifications - same behaviour appears with openAPI 3.0)
{"swagger":"2.0","info":{"description":"This is a simple API","version":"1.1.0","title":"Simple Inventory API","contact":{"email":"[email protected]"},"license":{"name":"Apache 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0.html"}},"tags":[{"name":"admins","description":"Secured Admin-only calls"},{"name":"developers","description":"Operations available to regular developers"}],"paths":{"/inventory":{"get":{"tags":["developers"],"summary":"searches inventory","operationId":"searchInventory","description":"By passing in the appropriate options, you can search for\navailable inventory in the system\n","produces":["application/json"],"parameters":[{"in":"query","name":"searchString","description":"pass an optional search string for looking up inventory","required":false,"type":"string"},{"in":"query","name":"skip","description":"number of records to skip for pagination","type":"integer","format":"int32","minimum":0},{"in":"query","name":"limit","description":"maximum number of records to return","type":"integer","format":"int32","minimum":0,"maximum":50}],"responses":{"200":{"description":"search results matching criteria","schema":{"type":"array","items":{"$ref":"#/definitions/InventoryItem"}}},"400":{"description":"bad input parameter"}}},"post":{"tags":["admins"],"summary":"adds an inventory item","operationId":"addInventory","description":"Adds an item to the system","consumes":["application/json"],"produces":["application/json"],"parameters":[{"in":"body","name":"inventoryItem","description":"Inventory item to add","schema":{"$ref":"#/definitions/InventoryItem"}}],"responses":{"201":{"description":"item created"},"400":{"description":"invalid input, object invalid"},"409":{"description":"an existing item already exists"}}}}},"definitions":{"InventoryItem":{"type":"object","required":["id","name","manufacturer","releaseDate"],"properties":{"id":{"type":"string","format":"uuid","example":"d290f1ee-6c54-4b01-90e6-d701748f0851"},"name":{"type":"string","example":"Widget Adapter"},"releaseDate":{"type":"string","format":"date-time","example":"2016-08-29T09:12:33.001Z"},"manufacturer":{"$ref":"#/definitions/Manufacturer"}}},"Manufacturer":{"required":["name"],"properties":{"name":{"type":"string","example":"ACME Corporation"},"homePage":{"type":"string","format":"url","example":"https://www.acme-corp.com"},"phone":{"type":"string","example":"408-867-5309"}}}}}
Command line used for generation
java -jar swagger-codegen-cli.jar generate -i https://api.swaggerhub.com/apis/liam.baloh/all2/1.1.0 -l csharp -o C:\Export\csharp
(please modify the output folder (after -o) to a suitable folder on your computer)
Steps to reproduce
Open https://api.swaggerhub.com/apis/liam.baloh/all2/1.1.0 in your browser, if it's still there then:
1: Set up swagger codegen 3.0.28
2: execute in powershell java -jar swagger-codegen-cli.jar generate -i https://api.swaggerhub.com/apis/liam.baloh/all2/1.1.0 -l csharp -o C:\Export\csharp (modify output folder (-o) to a suitable folder on your computer)
3: open file: src/IO/Swagger/Client/ApiClient.cs
4: observe line 6: * OpenAPI spec version: 1.1.0
if the above url no longer exists:
1: Set up swagger codegen 3.0.28
2: create API on swaggerhub from simple inventory template on OpenAPI version 2.0 (or 3.0 for separate test)
3: create a new version of the API called 1.1.0 (no further modifications)
4: modify the url from app.swaggerhub.com to api.swaggerhub.com so it matches https://api.swaggerhub.com/apis/liam.baloh/all2/1.1.0 except with your username and api name
5: execute in powershell java -jar swagger-codegen-cli.jar generate -i https://api.swaggerhub.com/apis/liam.baloh/all2/1.1.0 -l csharp -o C:\Export\csharp (replace path to API (-i) and output folder (-o) with your values)
Related issues/PRs
I've not found anything
Suggest a fix/enhancement
https://github.com/swagger-api/swagger-codegen-generators/blob/master/src/main/resources/handlebars/csharp/partial_header.mustache#L10
Most likely fixed by rewording the comment header from OpenAPI spec version to something like API version.