We are working on Swagger Documentation for our Laravel REST API implementation.
Several of the POST endpoints will use CSV as the parameter content type.
Is there a way in Swagger to have the "Try It Now" function work with a CSV POST file upload?
Below is our documentation in progress
http://api.curvecompass.com/docs/#/
We have the Laravel POST function working correctly with the CSV endpoint, just not the Swagger docs.
swagger ui for open api 3.0 does not support file upload yet. you can watch the update here https://github.com/swagger-api/swagger-ui/issues/3641
You can try this.
consumes:
- multipart/form-data # and/or application/x-www-form-urlencoded
parameters:
- name: file
in: formData
description: The uploaded file data
required: true
type: file
Related
I am playing around with https://openapi-generator.tech/ and I have an example openapi.yaml file:
openapi: 3.1.0
info:
title: Sample API
description: My amazing description.
version: 0.0.9
servers:
- url: http://localhost:8080/v1
description: My amazing server description.
paths:
/users:
get:
summary: Returns a list of all users.
description: My amazing /users endpoint description.
responses:
"200":
description: (OK) A JSON array of user objects.
content:
application/json:
schema:
type: array
items:
type: string
I have tried the following generation command:
openapi-generator-cli generate -g go-gin-server --global-property=apiDocs=true -i ./openapi.yaml
both with, and without the --global-property=apiDocs=true part. Neither case generated an /api, /doc, or /docs endpoint.
What am I doing wrong?
Note that the server runs fine, i.e., I can curl the endpoints specified in the yaml file.
It doesn't look like the server stub generator go-gin-server supports adding this type of endpoint. If you look at the routers template that this generator uses you can see that no config option will generate an /api, /doc or /docs endpoint unless you have defined it in your spec.
It's not clear to me exactly what you are expecting from this endpoint, but you could define one of these endpoints in your spec and implement the behavior you would like, or you could customize the template to automatically add this endpoint during code generation
I have setup my python api service using djangorestframework and I am using drf_yasg for showing swagger docs for my api.
Here is glance of setup:
schema_view = get_schema_view(
openapi.Info(
title='My API',
default_version='v1',
description='rest service',
terms_of_service='',
contact=openapi.Contact(email='my#email'),
license=openapi.License(name='BSD License'),
),
public=False,
)
urlpatterns = [
path('pyapi/weather/', include('apps.weather.urls')),
re_path(r'^pyapi/swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),
re_path(r'^pyapi/swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
re_path(r'^pyapi/redoc/$', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
]
Next I setup this api with amazon ec2 and stuff, and I am using Amazon API Gateway to access the api from containers.
Now the problem is when I try to access that using api gateway domain, it returns swagger JSON instead of HTML.
I tried several things like setting Content-Type mappings in method response and integration response but nothing works.
In my local machine it shows html as expected, so I am suspecting problem is in my gateway settings.
I highly appreciate if someone can help!
Ok I solved mystery!
After tons of tries and looking here and there, I found there was problem in API Gateway Request header setting.
Actually drf-yasg also kind of weird let me tell you why.
After setting up urls as I shown in first image, if you try to access http://localhost:8000/pyapi/swagger/ it shows UI perfectly.
At that time value of request header is Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Now same URL if you pass request header "Accept: application/json" then istead of showing html UI, it shows swagger JSON! wutt!!
That I found in Amazon API Gateways's test method's output. It was by default sending "Accept: application/json" and thats why I was always getting swagger.json in output. That was showstopper thing!
I changed it to Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9 and now I could see UI perfectly!
I hope this will save time of many other people like me who are new to this kind of stuff!
I using apollo server, and have this mutation :
mutation {
updateData(
file1: fileOne,
file2: fileTwo,
file3: fileThree,
payload: {
id: "7e3583b4-5673-48df-a3cf-44a4ec33f0e1"
}
){
isSuccess
error
data
}
}
I want to test it using postman, because i didnt find any clue test it using graphql playground.
I already find how to test graphql from postman, but it doesn't contains information about file upload. graphql postman
I have an idea from apollo-upload-client to post using multipart-formdata but it still fail.
please help how to test graphql with apollo server for upload file mutation using postman?
thanks
I need to understand about how file upload works in node js (because I use nodejs ini this case)
I install multer for file upload middleware using nodejs and expressjs, if you use other framework or programming language, just try adjust it
In postman I use formdata
you can find the good step by step here
Upload file graphql using postman
I have the following openapi 3.0 compliant yaml file which I am trying to render via swagger. There are no errors reported in the yaml file, but the requestBody is not rendered on the swagger GUI. I just get a parameters field which is empty but nothing rendered for the request body, nor do I get any errors. Screenshot below.
paths:
/my-api:
post:
summary: My API Summary
description: My API Description
tags:
- Cost Center
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: '#/components/schemas/ReqBodyStruct'
What is the way to get the RequestBody also shown in the swagger gui ? Do I miss something ?
According to these two issues OAS 3.0: Support for media type examples (aka request/response body examples) #3437 and Examples are not showing #2651 from the Swagger UI github page this should be fixed in version 3.23.0 (of June 29, 2019).
I am using FineUploader 5.13.0 with the Azure Blob Storage end point.
I have it successfully uploading files directly to blob storage, and also successfully hitting my web server success endpoint when the upload is concluded.
However, I am looking for a way to include custom data in the post to the success endpoint.
This bit in the documentation seems to imply that it is possible.
Under the section "Optional server-side tasks" for "uploadSuccess.endpoint", it says it will send
"Any parameters/form fields you have associated with the file".
However, I just cannot seem to figure out how to do that.
This issue seems to refer to it, but doesn't give enough info.
https://github.com/FineUploader/fine-uploader/issues/1313
Note, I am not referring to the feature to hook into existing HTML forms as explained on this documentation page:
"Integrating with Existing HTML Forms"
https://docs.fineuploader.com/branch/master/features/forms.html
You might be looking for FineUploader's Request params. This allows you to add extra form data.
Eg:
new qq.FineUploader({
// elided
request: {
params: {
testing: "THIS IS A TEST"
}
}
});
This will show up in the multi-part body of the request: