Implemented fix for #6006. Mime-type support#6751
Implemented fix for #6006. Mime-type support#6751wing328 merged 6 commits intoswagger-api:masterfrom
Conversation
| return undefined; | ||
|
|
||
| let type = accepts.find(x => this.isJsonMime(x)); | ||
| if (type === undefined) |
| return undefined; | ||
|
|
||
| let type = contentTypes.find(x => this.isJsonMime(x)); | ||
| if (type === undefined) |
There was a problem hiding this comment.
I suggest using block braces { and } as usually linting rules discourage if statements without braces
| * @return {boolean} True if the given MIME is JSON, false otherwise. | ||
| */ | ||
| public isJsonMime(mime: string): boolean { | ||
| let jsonMimeRegEx = new RegExp("^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$"); |
There was a problem hiding this comment.
how about also supporting json patch mime types?
the latest version of the isJsonMime() method before it was removed can be found here:
https://github.com/swagger-api/swagger-codegen/pull/6574/files#diff-3ab1141e07abf8762d6e33d15c9d1f0eL63
public isJsonMime(mime: string): boolean {
const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
}
|
I'll merge it this weekend if there's no further feedback/question. |
|
I thought I could fix the merge conflicts by a new build. But that does not seem to be the way.@wing328 if there is anything I can/should do to get this PR merged, please let me know. |
|
You can fix the merge conflicts by rebasing your branch onto the current master. See https://help.github.com/articles/syncing-a-fork/ for updating your repos master branch to this repos master branch. Then you should be able to rebase (https://git-scm.com/docs/git-rebase) typescript_angular_mimetype_support onto master. |
|
I just resolved the merge conflicts. Will merge later ... |
|
@wing328 Thank you! You're the best! |
Technical committee: @TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx
PR checklist
./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.shand./bin/security/{LANG}-petstore.shif updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\.3.0.0branch for changes related to OpenAPI spec 3.0. Default:master.Description of the PR
Fix for #6006 and #6454. Since the fix done in #6454 has been removed.
I tested using the Angular-v2 and v4 scripts.
This fix is needed to support rest services that use mime-types for versioning.
The configuration has been expanded with methods that determine the correct Accepts and Content-Type (for non-form posts) mime-type and can be overridden if needed when creating a configuration. (If multiple versions are supported by the rest service, the correct filtering can be done there)
There is one thing I am not completely satisfied with and that is that all generated operations have a 'consumes' block. The reason behind that is that there should be no duplicate code in the 'api.service.mustache'. But I could not find a Mustache section that is equal to '#bodyParam' and '#hasFormParams' together.