swagger-api / swagger-api/swagger-codegen
[CSharp] parameter type: file generation error
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
There are 2 operations in declaration file - UploadFile and GetOperationProfileFiles and 2 models - File and FileReponse.
Operation UploadFile have parameter with name file, operation GetOperationProfileFiles has response schema type: file.
In generated C# client, the response type for GetOperationProfileFiles is ModelFile instead of System.IO.Stream if there is a parameter with name file in UploadFile endpoint or model with name file in definitions. If both model and parameter are renamed to something else, i.e. qfile, the response type is generated correctly.
Swagger-codegen version
Version: 2.4.17
Swagger declaration file content or url
swagger: '2.0'
info:
version: 1.2.1
title: '-'
description: a
contact:
name: a
url: http://localhost
security:
- bearerAuth: []
schemes:
- https
consumes:
- application/json
- text/json
produces:
- application/json
host: localhost:443
basePath: /
securityDefinitions:
bearerAuth:
type: oauth2
flow: password
tokenUrl: 'http://localhost'
scopes:
test: test
tags:
- name: file
paths:
'/networks/{networkID}/files':
post:
tags:
- file
operationId: UploadFile
consumes:
- application/octet-stream
parameters:
- name: networkID
in: path
type: string
format: uuid
required: true
- name: file
in: body
schema:
type: string
format: binary
responses:
201:
description: Created
schema:
$ref: '#/definitions/FileResponse'
'/networks/{networkID}/operationProfiles/{operationProfileID}/files/{fileID}':
get:
tags:
- file
description: Download a file used in an operation profile settings.
operationId: GetOperationProfileFiles
parameters:
- name: networkID
in: path
type: string
format: uuid
required: true
- name: operationProfileID
in: path
type: integer
required: true
- name: fileID
in: path
type: integer
required: true
produces:
- application/octet-stream
responses:
200:
description: OK
schema:
description: Byte stream.
type: file
headers:
Name:
type: string
description: file name.
CreatedAt:
description: The time when the file was created.
type: string
format: datetime ISO 8601
ModifiedAt:
description: The time when the file was modified.
type: string
format: datetime ISO 8601
Content-Length:
description: Length of the file content.
type: number
format: int64
definitions:
File:
description: file information.
type: object
properties:
contentLength:
description: Length of the file content.
type: integer
format: int64
example: 335
FileResponse:
description: file response information.
type: object
properties:
data:
$ref: '#/definitions/File'
Command line used for generation
Export is done via Swagger Cloud.
Steps to reproduce
Generate csharp client SDK using Swagger Cloud and look at IO.Swagger.Api.IFileApi.GetOperationProfileFiles signature - ModelFile is response type instead of System.IO.Stream.
The following error can be fixed by renaming model File to qFile for example and renaming UploadFile operation's parameter file to qfile
Suggest a fix/enhancement
Having model with name File or parameter with name file in endpoints should not affect the generated type for a parameter with type: file.
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
Reproduce the issue from the supplied Swagger declaration and inspect the generated IO.Swagger.Api.IFileApi.GetOperationProfileFiles signature. Compare results with the file model and UploadFile parameter renamed, then trace the generator behavior that selects the response type. Done means a type: file response remains System.IO.Stream regardless of those names.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100