-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Schema: defining multiple types #45
Comments
Hi @happyDemon 👋 This functionality is provided through:
Example usage will be: OneOf::create()->schemas($schemaOne, $schemaTwo); |
Thanks for the quick reply, there's a little hiccup though, since they don't extend Assigning as a property on an object-type schema for example, or when trying to add it to the schema of a MediaType. Currently, as a workaround, I've implemented the functionality I needed locally in a separate OneOfProperty class |
@happyDemon you're right, I'll look at providing an update to fix this 👍 |
Greetings! I would also like to have this work out of the box. But meanwhile if anybody else is looking for workaround, it could be roughly done by adding a Schema-wrapper for SchemaComposition. Something like this: <?php
declare(strict_types=1);
namespace SomeNameSpace\Goes\Here;
use GoldSpecDigital\ObjectOrientedOAS\Objects\Schema;
use GoldSpecDigital\ObjectOrientedOAS\Objects\SchemaComposition;
class SchemaCompositionWrapper extends Schema
{
private SchemaComposition $composition;
public function composition(SchemaComposition $composition): self
{
$instance = clone $this;
$instance->composition = $composition;
return $instance;
}
protected function generate(): array
{
return array_merge(
parent::generate(),
$this->composition->toArray(),
);
}
} The usage is simple: $schema = SchemaCompositionWrapper::create()
->composition(
AnyOf::create()->schemas(...)
);
$mediaType->schema($schema); (As always, be cautious if you copy-paste this :) It's just a draft) |
I have an internal API that interfaces with multiple third-party APIs and normalizes the response to something more manageable.
Because of this, I have properties that can either be 'integer' or 'string' depending on the service.
Following the spec: https://swagger.io/docs/specification/data-models/data-types/ (mixed types) it should be possible by defining them as OneOff.
Which kind of works, but I lose the possibility to set a description and such.
Is this something that just hasn't been implemented in this library or are you omitting it for a specific reason?
The text was updated successfully, but these errors were encountered: