go swagger how to add support for all mime type - mime-types

Swagger by default supports application/json as Content type. And if I want to add other Content types then "produces" or "consumes" fields needs to updated in the swagger JSON file. Client may send any type of Data. Is there a way to support any Content type (remove the validation for Content type or regex like *) in swagger

As far as I have worked on go-swagger, you will have to mention in the swagger-spec file and generate the code again in order to do that. You can use / to describe that the endpoint can generate all type of data. But you can not modify it after you have generated the code using go-swagger.
You can directly modify the generated files but it's not recommended.

Related

Formatting Text Area will not format when using Advanced Custom Fields? Delivered using GraphQL

I am trying to format the content of 'Text Area' when using WordPress's Advanced Custom Fields. I am using React to build the project.
In an attempt to debug, I have been following this documentation and set my options to resemble the image referenced. Including Text Area as one of my custom fields and setting the New Lines option to Automatically add paragraphs
The documentation then goes on to show an example using PHP to render the content.
I am using graphQL to fetch my data, and delivering the contents as follows:
<div className="media-description-area">
{this.props.activeDescription}
</div>
with activeDescription being destructured from the object that the GraphQL request delivers.
The text as its being set in the field itself looks like this, with spacing included:
The formatting tags are being rendered directly into the string itself, this how it is appearing in the document:
Does anyone know how why this is? I am referring to the field directly so it appears as this formatting is being delivered from WordPress itself
activeDescription: objects[0].items[0].projectDescription,
Thank You

Caddy2: how to set MIME type and Content-disposition for a file extension?

What is the way to configure/override how certain MIME types are handled?
For example, with the default configuration a python file (.py) is served with Content-disposition": attachment which opens a file save dialog rather than displaying inline plain text in the browser.
I've identified one possible approach:
#py {
path *.py
}
header #py Content-Type text/plain
While this works, it looks more of a hack rather than adding/modifying a mime type, given that it's simply setting a header based on a substring match. Is this the only possible approach?
What defines that a specific MIME type should be served inline or have "Content-disposition": attachment? Does caddy expose a straightforward way to configure how MIME types are handled?
The correct mime type for .py files is application/x-python-code or text/x-python. How can I configure caddy to treat these types as inline plain text, and not add the Content-disposition": attachment header? Forcing text/plain works as a workaround, but I am assuming there is a cleaner way to do it.

How to parse and play Blob/Binary data from database in Angular 5

In my Angular 5 application, I am retrieving data which is stored as VARBINARY(MAX) in SQL Server database. It looks like this in the database field: 0xFEA47E451A40AE4571E51F...
When I retrieve it from database using a GET call via .NET WebAPI, it is shown like this in console from my Angular app: aFwwbUYFjhvbv=bhBGVJHvchjhcbsHKfvHbbh...
I know the MIME type of this data (it is either MP3 or WAV). How can I parse/read this data in Angular 5 client and play it using an HTML <audio> component?
I have looked at several related solutions but none seem to be applicable due to one error or another, or perhaps there is a lack of understanding on my part.
My assumptions are that Blob data has the audio content which I can play. I have to convert it to a File first. This is what I am trying:
const file = new File([blobData], "audio.mp3")
this.audioSource = URL.createObjectURL(file)
And in the HTML, I assign audioSource as the source of an HTML5 component.
<audio [src]="audioSource" type="audio/mp3"></audio>
This results in a net::ERR_UNKNOWN_URL_SCHEME error.
I tried sanitizer.bypassSecurityTrustUrl(this.audioSource) as well but this doesn't work either. What am I doing wrong, and how can I get the intended effect?
please check this answer : https://stackoverflow.com/a/40329529/1160236
if you have blob data with correct binaries all you have to do is to create URL using URL.createObjectURL(blob) then pass it to the audio tag as a source. (check step-3)
if you don't have blob data with correct binaries you can create blob data as shown in step-2.
I have created an Angular example which uses DomSanitizer via a custom pipe.
<audio [src]="audioSource | safe:'url'" id="audio" controls #audioTag></audio>
Reference : https://stackoverflow.com/a/40329529/1160236
Angular implementation using reference : https://stackblitz.com/edit/angular-audio-blob
DomSanitizer example: https://medium.com/#swarnakishore/angular-safe-pipe-implementation-to-bypass-domsanitizer-stripping-out-content-c1bf0f1cc36b
I hope this will help. just remember all you need is valid blob data.

Override a default mime-type when using the Sling MimeTypeService

I am using the Sling MimeTypeService in order to get an appropriate extension for a given file & trying to override a default extension with my own.
E.g. if I had a method:
#Reference
MimeTypeService mimeTypeService;
public void getPlainTextAsDiff() {
mimeTypeService.registerMimeType("text/plain", ".diff");
mimeTypeService.getExtension("text/plain"); //returns ".txt"
}
This returns ".txt" rather than ".diff", ignoring the first line of the method.
This also seems to be inline with the documentation:
A MIME type may be mapped to multiple extensions (e.g. text/plain to
txt, log, ...). This method is expected to returned one of those
extensions. It is up to the implementation to select an appropriate
extension if multiple mappings exist for a single MIME type.
[My emphasis]
I'm wondering if it's possible to circumvent this somehow, e.g. deregistering a mime-type or ranking those available, so that in the case above "diff" would guaranteed to be returned?
You can extend mime type mappings by providing MimeTypeProvider services, but looking at the MimeTypeServiceImpl code it looks like those are not sorted by service ranking. If I'm correct, you won't have a way to prioritize you MimeTypeProviders. You might want to experiment with this and submit an enhancement request or patch.

CakePHP RequestHandler: setContent/renderAs/respondAs .. what?

Can someone please explain these functions:
RequestHandlerComponent::renderAs()
RequestHandlerComponent::respondAs()
RequestHandlerComponent::setContent()
It feels slightly redundant to have all three of them (as public methods anyway). If I want to respond to a request with a PDF file, does that mean I'd have to call all three functions? How should I use these in my controller?
They're all different. From the API Docs:
renderAs
Sets the layout and template paths for the content type defined by $type.
I.e. more or less a shortcut for $this->layout = '...' and $this->render(...).
respondAs
Sets the response header based on type map index name. If DEBUG is greater than 2, the header is not set.
Outputs header(...).
setContent
Adds/sets the Content-type(s) for the given name. This method allows content-types to be mapped to friendly aliases (or extensions), which allows RequestHandler to automatically respond to requests of that type in the startup method.
Doesn't actually do anything to the output, just allows you to add new types that are not defined by default.
For outputting a PDF (assuming you have it as a file already) you should actually use a Media View.

Resources