Skip to content

Commit

Permalink
handle content type
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Dec 30, 2024
1 parent 5bd1192 commit 139186f
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/Generator/Spec/OpenAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
use PSX\OpenAPI\SecuritySchemes;
use PSX\OpenAPI\Server;
use PSX\OpenAPI\Tag;
use PSX\Schema\ContentType;
use PSX\Schema\Definitions;
use PSX\Schema\DefinitionsInterface;
use PSX\Schema\Generator;
Expand Down Expand Up @@ -255,13 +256,29 @@ protected function newTag(string $name, string $description): Tag
return $tag;
}

private function getMediaTypes(TypeInterface $type, DefinitionsInterface $definitions): MediaTypes
private function getMediaTypes(TypeInterface|ContentType $type, DefinitionsInterface $definitions): MediaTypes
{
$mediaType = new MediaType();
$mediaType->setSchema($this->resolveSchema($type, $definitions));
if ($type instanceof TypeInterface) {
$mediaType = new MediaType();
$mediaType->setSchema($this->resolveSchema($type, $definitions));

$mediaTypes = new MediaTypes();
$mediaTypes['application/json'] = $mediaType;
$mediaTypes = new MediaTypes();
$mediaTypes['application/json'] = $mediaType;
} else {
$schema = (object) [
'type' => 'string',
];

if ($type->getShape() === ContentType::BINARY) {
$schema->format = 'binary';
}

$mediaType = new MediaType();
$mediaType->setSchema($schema);

$mediaTypes = new MediaTypes();
$mediaTypes[$type->toString()] = $mediaType;
}

return $mediaTypes;
}
Expand Down

0 comments on commit 139186f

Please sign in to comment.