-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
File API #131
File API #131
Conversation
Related OpenApi schema part "/api/ReturnFile": {
"get": {
"tags": [
"ReturnFile"
],
"responses": {
"200": {
"description": "Success",
"content": {
"application/octet-stream": {
"schema": {
"type": "string",
"format": "binary"
}
}
}
}
}
}
},
"/api/ReturnFile/single": {
"post": {
"tags": [
"ReturnFile"
],
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"type": "object",
"properties": {
"file": {
"type": "string",
"format": "binary"
}
}
},
"encoding": {
"file": {
"style": "form"
}
}
}
}
},
"responses": {
"200": {
"description": "Success",
"content": {
"application/octet-stream": {
"schema": {
"type": "string",
"format": "binary"
}
}
}
}
}
}
},
"/api/ReturnFile/multiple": {
"post": {
"tags": [
"ReturnFile"
],
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"type": "object",
"properties": {
"files": {
"type": "array",
"items": {
"type": "string",
"format": "binary"
}
}
}
},
"encoding": {
"files": {
"style": "form"
}
}
}
}
},
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"type": "integer",
"format": "int32"
}
}
}
}
}
}
},
"/api/ReturnFile/form-with-file": {
"post": {
"tags": [
"ReturnFile"
],
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"type": "object",
"properties": {
"Name": {
"type": "string"
},
"File": {
"type": "string",
"format": "binary"
}
}
},
"encoding": {
"Name": {
"style": "form"
},
"File": {
"style": "form"
}
}
}
}
},
"responses": {
"200": {
"description": "Success",
"content": {
"application/octet-stream": {
"schema": {
"type": "string",
"format": "binary"
}
}
}
}
}
}
}, |
let data = WebAPI.OperationTypes.PostApiReturnFileSingle_formData(toStream text) | ||
let! stream = api.PostApiReturnFileSingle(data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not supper happy that we generate wrapper object around payload ...
but in OpenAPI payload described as one parameter requestBody
that we map to provided type
"/api/ReturnFile/single": {
"post": {
"tags": [
"ReturnFile"
],
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"type": "object",
"properties": {
"file": {
"type": "string",
"format": "binary"
}
}
},
"encoding": {
"file": {
"style": "form"
}
}
}
}
},
let filename = Guid.NewGuid().ToString() // asp.net core cannot deserialize IFormFile otherwise | ||
cnt.Add(new StreamContent(stream), name, filename) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another hack is that we have to provide file have for content disposition header, otherwise asp.net core backend cannot map it to IFormFile
, but this is not reflected in OpenAPI schema :'(
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"type": "object",
"properties": {
"file": {
"type": "string",
"format": "binary"
}
}
},
"encoding": {
"file": {
"style": "form"
}
}
}
}
},
I merge it, because it definitely better than nothing - we can improve in the future. |
@sergey-tihon this looks perfectly fine to me, thanks for carrying the torch here and adding this functionality :) As for your comment about needing the wrapper-type, that seems like something that can be added later as an additional overload if/when there's time. So then you'd have one overload with the wrapper-type (which you could mark as obsolete), and another overload with just the input stream (which I guess seems like the 'ideal' interface to me?) |
reworked version of #108 with desire to fix #59 and #61
Related links