Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,16 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
op.vendorExtensions.put("x-comment-type", "void");
}
// Create a variable to add typing for return value of interface
if (op.returnType != null) {
if (op.returnType == null) {
op.vendorExtensions.put("x-return-type", "void");
} else if (op.isArray || op.isMap || isApplicationJsonOrApplicationXml(op)
|| !op.returnTypeIsPrimitive // it could make sense to remove it, but it would break retro-compatibility
) {
op.vendorExtensions.put("x-return-type", "array|object|null");
} else if ("binary".equals(op.returnProperty.dataFormat)) {
op.vendorExtensions.put("x-return-type", "mixed");
} else {
op.vendorExtensions.put("x-return-type", "void");
op.vendorExtensions.put("x-return-type", op.returnType);
}

// Add operation's authentication methods to whole interface
Expand All @@ -438,6 +444,18 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
return objs;
}

private boolean isApplicationJsonOrApplicationXml(CodegenOperation op) {
if (op.produces != null) {
for(Map<String, String> produce : op.produces) {
String mediaType = produce.get("mediaType");
if (isJsonMimeType(mediaType) || isXmlMimeType(mediaType)) {
return true;
}
}
}
return false;
}

@Override
public ModelsMap postProcessModels(ModelsMap objs) {
objs = super.postProcessModels(objs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ class Controller extends AbstractController
return 'application/xml';
}

if (in_array('*/*', $accept)) {
return $produced[0];
}

// If we reach this point, we don't have a common ground between server and client
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ class JmsSerializer implements SerializerInterface
*/
public function serialize($data, string $format): string
{
return SerializerBuilder::create()->build()->serialize($data, $this->convertFormat($format));
$convertFormat = $this->convertFormat($format);
if ($convertFormat !== null) {
return SerializerBuilder::create()->build()->serialize($data, $convertFormat);
} else {
// don't use var_export if $data is already a string: it may corrupt binary strings
return is_string($data) ? $data : var_export($data, true);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ protected function getOutputFormat(string $accept, array $produced): ?string
return 'application/xml';
}

if (in_array('*/*', $accept)) {
return $produced[0];
}

// If we reach this point, we don't have a common ground between server and client
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ public function __construct()
*/
public function serialize($data, string $format): string
{
return SerializerBuilder::create()->build()->serialize($data, $this->convertFormat($format));
$convertFormat = $this->convertFormat($format);
if ($convertFormat !== null) {
return SerializerBuilder::create()->build()->serialize($data, $convertFormat);
} else {
// don't use var_export if $data is already a string: it may corrupt binary strings
return is_string($data) ? $data : var_export($data, true);
}
}

/**
Expand Down
Loading