Skip to content

Conversation

@davidharrigan
Copy link
Contributor

@davidharrigan davidharrigan commented Mar 24, 2017

PR checklist

  • Read the contribution guidelines.
  • Ran the shell/batch script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates)
  • Filed the PR against the correct branch: master for non-breaking changes and 2.3.0 branch for breaking (non-backward compatible) changes.

Description of the PR

Adds support for vendor media type JSON (ends with +json) as specified in RFC-3839.

PR made against master since the change is non-breaking and backwards compatible (still has the same support for application/json).

More details in the issue here: #5172

@davidharrigan davidharrigan changed the title [Fixes #5172] Allow vendor json media types [JAVA][#5172] Allow vendor json media types Mar 24, 2017
@ePaul
Copy link
Contributor

ePaul commented Mar 29, 2017

Could you rebase your branch onto current master, and possibly regenerate the samples afterwards?

I think some of the changes in the generated samples are already incorporated there, and this would make it easier to see what actually changed.

*/
public boolean isJsonMime(String mime) {
return mime != null && mime.matches("(?i)application\\/json(;.*)?");
String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are tab characters really allowed in media type names?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, according to the grammar described here in RFC-7230. You can see that HTAB corresponds to horizontal tab here in RFC-5234.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, thanks.

assertTrue(apiClient.isJsonMime("example/foo+bar+json"));
assertTrue(apiClient.isJsonMime("example/foo+json;x;y"));
assertTrue(apiClient.isJsonMime("example/foo+json\t;"));
assertTrue(apiClient.isJsonMime("Example/fOO+JSON"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want a real-live example, application/problem+json (from RFC 7807) is often used in APIs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing, I'll update these tests with some real-live example.

@davidharrigan
Copy link
Contributor Author

Looks like the failed test is fixed here: #5243

Failed tests:   testApiClient(io.swagger.client.api.PetApiTest): expected:<.../petstore.swagger.io[]/v2> but was:<.../petstore.swagger.io[:80]/v2>

@ePaul
Copy link
Contributor

ePaul commented Mar 29, 2017

Yes, sorry for the update proposal, I didn't mean to cause more issues by that, but simply forgot that current master is "broken" (for sample generation) until #5243 is merged.

@davidharrigan
Copy link
Contributor Author

no worries :)

@wing328 wing328 added this to the v2.2.3 milestone Mar 30, 2017
public boolean isJsonMime(String mime) {
return mime != null && mime.matches("(?i)application\\/json(;.*)?");
String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$";
return mime != null && mime.matches(jsonMime);
Copy link
Contributor

@wing328 wing328 Mar 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Later I will file a PR to put these 2 lines into one without declaring a temporary variable.

assertTrue(apiClient.isJsonMime("example/foo+bar+json"));
assertTrue(apiClient.isJsonMime("example/foo+json;x;y"));
assertTrue(apiClient.isJsonMime("example/foo+json\t;"));
assertTrue(apiClient.isJsonMime("Example/fOO+JSON"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll leverage these test cases in other API clients' unit tests

@wing328 wing328 merged commit fc01457 into swagger-api:master Mar 30, 2017
@wing328
Copy link
Contributor

wing328 commented Mar 30, 2017

@ePaul thanks for reviewing the change.

@davidharrigan thanks for the contribution, which has been merged into master.

@ePaul ePaul mentioned this pull request Apr 1, 2017
3 tasks
@davidharrigan davidharrigan deleted the FIX-5172 branch May 6, 2017 15:44
davidgri pushed a commit to davidgri/swagger-codegen that referenced this pull request May 11, 2017
)

* [swagger-api#5172] Allow vendor json media types

* Revert unnecessary diffs

* Update petstore sample

* Didn't run mvn after some edits

* Rerun ' ./bin/java-petstore-all.sh' and './bin/security/java-petstore-okhttp-gson.sh'

* Added more realistic test cases for isJsonMime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants