How to add content-disposition header in OpenAPI 2.0 specifications - openapi

I am new to OpenAPI specification and currently working on a project which uses OpenAPI specification 2.0. We also use swagger-codegen to generate REST interface from this specification file.
Now, I am stuck in a scenario where I have to pass an Excel file as a output to the REST call so to do that I need to mention content-disposition in response header for this REST API in OpenAPI specification so that auto generated code also has the same thing.
Is there a way to do that so that my auto generated code automatically detects that header?
....
Object res = service.exportData(body);
return Response.ok(res).build();
....

Related

Invalid entity passed while trying below method [duplicate]

I am using Karate 0.9.0 version and I want to upload data using csv file. As per new update, it is converting data into JSON. But my API supports csv file format for upload function. How can I upload csv file in post request without converting data into json?
Example
Given path 'xxx/upload'
And header Authorization = xxx
And header Content-Type = 'text/csv'
And request read('classpath:xxx.csv')
When method POST
Then status 202
P.S. This example was working in Karate version: 0.9.0.RC5
Thanks, that is indeed an edge case we hadn't thought of, but you have 2 options that will work nicely:
1) rename your CSV file to *.txt
And request read('classpath:xxx.txt')
2) use the karate.readAsString() API
And request karate.readAsString('classpath:xxx.csv')

SOAP message without header - how to process?

I've tried web search to find answer to my question but found only articles like how to create SOAP message without header.
In wikipedia on SOAP:
SOAP header : A collection of one or more header blocks targeted at
each SOAP receiver. SOAP body : Contains the body of the message
intended for the SOAP receiver. The interpretation and processing of
SOAP body is defined by header blocks.
And:
A SOAP message is an ordinary XML document containing the following
elements:
Element - Required
Header - No
Body - Yes
...
How can be a message without header if processing of body is defined in header?
The SOAP header is optional. If a header is required, it is mainly mentioned in the WSDL file, that is bound to the webservice. The WSDL defines the functions of a webservice and the types, that are bound to the functions. It depends on how a function is defined. Some definitions need an action attribute in the soap header. Others are used by directly mentioning them in the SOAP Body. To keep it short: how a SOAP message should look like is more or less strictly defined in the webservice definition (wsdl).

Searching for a javascript library to validate JSON against OpenAPI schema

I am searching for a JS library (ideally usable in the browser) to:
check a particular JSON payload (typically a response from an API) against an OpenAPI 3.0 schema (YAML or JSON)
ideally decorate that JSON payload with information extracted from the OpenAPI 3.0 schema (eg. documentation information)
alternatively allow callbacks to external handling functions for each error / match in the validation step
As for...
You could try one of the following:
https://jsonschemalint.com/#/version/draft-07/markup/json
https://www.jsonschemavalidator.net/#
I would look into and try to build your requirements on top of ajv
https://github.com/epoberezkin/ajv

Nancy - return pdf stream via ajax

Is there any sample out there how to return a pdf stream (e.g. generated by Crystal Report) from a nancy module via an ajax request?
I'm not sure what you mean by "ajax request" and why it matters, but recently we had to solve similar problem - i.e. returning pdf, generated from other tool. We ended up using as a template a binary processor, utilizing the content negotiation.
You can modify the binary processor to work with application/pdf MIME type and "pdf" file extensions, so it returns the proper response whenever the request has an Accept header of "application/pdf" or when the request is like http://example.com/reports/report.pdf.
Using this, and assuming you have IReportEngine with Stream GetReportByName(string name), your module will look like (pseudo code):
Get["reports/{reportName}"] = _ => _engine.GetReportByName(_.reportName);

How to produce both xml and json for a rest based service?

I am trying to produce both xml and json from my rest service.
#Produces({"application/xml", "application/json"})
However, when I try to use the service using curl/SOAPUI, I get back either xml or json depending on which is mentioned first. In simple words, only the first method is considered. Is there a workaround?
You should check this link out - oracle docs for #Produces
The spec says that it does indeed default to the first one if that is acceptable as specified by the media type on the request. You should check your soapUI tool and see what headers you are sending. If they are both being sent you will get a response with the first one listed in your #Produces annotation.