Skip to content

Commit

Permalink
Added support for string responses (swagger-api#4057)
Browse files Browse the repository at this point in the history
* Added support for string responses

When a method/URL/response is defined to return string:
- If no content types are define, default to 'text/plain' instead of
  'application/json'
- Add response handler, that returns the reponse string as-is if response
  content-type is 'text/plain'

* Removed use of unused tag vendor tag

- The tag was vendorExtensions.x-codegen-response.isPrimitiveType
  • Loading branch information
plankswert authored and wing328 committed Nov 23, 2016
1 parent 932dc5f commit ba194ba
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,17 @@ pplx::task<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/r
utility::string_t responseHttpContentType;

// use JSON if possible
if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() )
if ( responseHttpContentTypes.size() == 0 )
{
{{#vendorExtensions.x-codegen-response.isString}}
responseHttpContentType = U("text/plain");
{{/vendorExtensions.x-codegen-response.isString}}
{{^vendorExtensions.x-codegen-response.isString}}
responseHttpContentType = U("application/json");
{{/vendorExtensions.x-codegen-response.isString}}
}
// JSON
else if ( responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() )
{
responseHttpContentType = U("application/json");
}
Expand All @@ -62,6 +72,13 @@ pplx::task<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/r
{
responseHttpContentType = U("multipart/form-data");
}
{{#vendorExtensions.x-codegen-response.isString}}
// plain text
else if( responseHttpContentTypes.find(U("text/plain")) != responseHttpContentTypes.end() )
{
responseHttpContentType = U("text/plain");
}
{{/vendorExtensions.x-codegen-response.isString}}
{{#vendorExtensions.x-codegen-response-ishttpcontent}}
else
{
Expand Down Expand Up @@ -266,7 +283,11 @@ pplx::task<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/r
{{/isMapContainer}}{{^isMapContainer}}{{#vendorExtensions.x-codegen-response.isPrimitiveType}}result = ModelBase::{{vendorExtensions.x-codegen-response.items.datatype}}FromJson(json);
{{/vendorExtensions.x-codegen-response.isPrimitiveType}}{{^vendorExtensions.x-codegen-response.isPrimitiveType}}{{#vendorExtensions.x-codegen-response.isString}}result = ModelBase::stringFromJson(json);
{{/vendorExtensions.x-codegen-response.isString}}{{^vendorExtensions.x-codegen-response.isString}}result->fromJson(json);{{/vendorExtensions.x-codegen-response.isString}}{{/vendorExtensions.x-codegen-response.isPrimitiveType}}{{/isMapContainer}}{{/isListContainer}}
}
}{{#vendorExtensions.x-codegen-response.isString}}
else if(responseHttpContentType == U("text/plain"))
{
result = response;
}{{/vendorExtensions.x-codegen-response.isString}}
// else if(responseHttpContentType == U("multipart/form-data"))
// {
// TODO multipart response parsing
Expand Down

0 comments on commit ba194ba

Please sign in to comment.