Skip to content
Open
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
136 changes: 136 additions & 0 deletions .patches/openapi-extractor-mixed-object.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
--- a/src/OpenApiType.php
+++ b/src/OpenApiType.php
@@ -79,6 +79,87 @@

// https://github.com/OAI/OpenAPI-Specification/issues/1368#issuecomment-354037150
return $type !== 'object' && $anyOf === null && ($allOf === null || (($nullable ?? false) && count($allOf) === 1));
+ }
+
+ /**
+ * OpenAPI 3.0 ignores keywords beside a Reference Object. Description and
+ * a default that conforms to the schema have to live on a Schema Object
+ * that wraps the reference.
+ *
+ * @param array<string, array<string, mixed>> $schemas
+ */
+ private function hasSchemaObjectKeywords(bool $isParameter, array $schemas): bool {
+ if ($this->type !== null || $this->format !== null || $this->nullable || $this->deprecated) {
+ return true;
+ }
+ if ($this->hasDefaultValue && !$this->hasUnknownDefaultValue && !$this->shouldOmitDefault($schemas)) {
+ return true;
+ }
+ if ($this->enum !== null || $this->items !== null || $this->additionalProperties !== null) {
+ return true;
+ }
+ if ($this->description !== null && $this->description !== '' && !$isParameter) {
+ return true;
+ }
+ if ($this->minLength !== null || $this->maxLength !== null || $this->minimum !== null || $this->maximum !== null || $this->minItems !== null || $this->maxItems !== null) {
+ return true;
+ }
+ if ($this->required !== null || ($this->properties !== null && $this->properties !== [])) {
+ return true;
+ }
+ if ($this->oneOf !== null || $this->anyOf !== null || $this->allOf !== null) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * An empty PHP array is the extractor's stand-in for an unspecified object.
+ * Beside a $ref it used to be ignored. Promoting it makes the default an
+ * array while the referenced schema is an object.
+ *
+ * @param array<string, array<string, mixed>> $schemas
+ */
+ private function shouldOmitDefault(array $schemas): bool {
+ if (!is_array($this->defaultValue) || count($this->defaultValue) !== 0) {
+ return false;
+ }
+ if ($this->type === 'object' || $this->type === 'array') {
+ return false;
+ }
+
+ return $this->referencedSchemaIsObject($schemas);
+ }
+
+ /**
+ * @param array<string, array<string, mixed>> $schemas
+ */
+ private function referencedSchemaIsObject(array $schemas): bool {
+ $refs = [];
+ if ($this->ref !== null) {
+ $refs[] = $this->ref;
+ }
+ foreach ($this->allOf ?? [] as $member) {
+ if ($member->type === 'object') {
+ return true;
+ }
+ if ($member->ref !== null) {
+ $refs[] = $member->ref;
+ }
+ }
+ foreach ($refs as $ref) {
+ $prefix = '#/components/schemas/';
+ if (!str_starts_with($ref, $prefix)) {
+ continue;
+ }
+ $schema = $schemas[substr($ref, strlen($prefix))] ?? null;
+ if (is_array($schema) && ($schema['type'] ?? null) === 'object') {
+ return true;
+ }
+ }
+
+ return false;
}

/**
@@ -95,6 +176,18 @@
))->toArray($schemas, $isParameter);
}

+ if ($this->ref !== null && $this->hasSchemaObjectKeywords($isParameter, $schemas)) {
+ $reference = new self(
+ context: $this->context,
+ ref: $this->ref,
+ );
+ $schema = clone $this;
+ $schema->ref = null;
+ $schema->allOf = [...($schema->allOf ?? []), $reference];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The generalized $ref wrapper also affects schemas outside the policy endpoints.

In the regenerated openapi-full.json, properties such as file, settings, and coordinates now expose default: [] alongside allOf references to schemas declared as type: object. Previously, these defaults were ignored as $ref siblings.

This introduces an inconsistency between the effective schema and its declared default, potentially affecting generated clients.

Could we verify this with a focused schema-conformance and client-generation test? If the mismatch is confirmed, please correct it at the source/generator boundary and regenerate the contracts. The policy-value fix itself should be preserved.

+
+ return $schema->toArray($schemas, $isParameter);
+ }
+
$values = [];
if ($this->ref !== null) {
$values['$ref'] = $this->ref;
@@ -111,7 +204,7 @@
if ($this->deprecated) {
$values['deprecated'] = true;
}
- if ($this->hasDefaultValue && !$this->hasUnknownDefaultValue) {
+ if ($this->hasDefaultValue && !$this->hasUnknownDefaultValue && !$this->shouldOmitDefault($schemas)) {
$values['default'] = $this->type === 'object' && is_array($this->defaultValue) && count($this->defaultValue) === 0 ? new stdClass() : $this->defaultValue;
}
if ($this->enum !== null) {
@@ -243,6 +336,17 @@
$key = $node->genericTypes[0] instanceof IdentifierTypeNode ? $node->genericTypes[0]->name : $node->genericTypes[0]->type->name;
$allowedTypes = ['string', 'lowercase-string', 'non-empty-string', 'non-empty-lowercase-string', 'class-string'];
if (in_array($key, $allowedTypes, true)) {
+ $valueType = $node->genericTypes[1];
+ // array<string, mixed> is an object whose values are unrestricted.
+ // A nested `{type: object}` schema would reject scalars, lists and null.
+ if ($valueType instanceof IdentifierTypeNode && $valueType->name === 'mixed') {
+ return new OpenApiType(
+ context: $context,
+ type: 'object',
+ additionalProperties: true,
+ );
+ }
+
return new OpenApiType(
context: $context,
type: 'object',
21 changes: 13 additions & 8 deletions openapi-administration.json
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,7 @@
},
{
"type": "object",
"additionalProperties": {
"type": "object"
}
"additionalProperties": true
}
]
},
Expand Down Expand Up @@ -3979,8 +3977,12 @@
],
"properties": {
"value": {
"$ref": "#/components/schemas/EffectivePolicyValue",
"description": "Policy value to persist as an explicit system rule, even when it equals the default. Null removes the explicit system rule: the built-in default applies and lower layers may override it."
"description": "Policy value to persist as an explicit system rule, even when it equals the default. Null removes the explicit system rule: the built-in default applies and lower layers may override it.",
"allOf": [
{
"$ref": "#/components/schemas/EffectivePolicyValue"
}
]
},
"allowChildOverride": {
"type": "boolean",
Expand Down Expand Up @@ -4170,9 +4172,12 @@
"type": "object",
"properties": {
"values": {
"$ref": "#/components/schemas/PolicyValueMap",
"default": [],
"description": "Values to persist, keyed by policy identifier, each as an explicit system rule even when it equals the default. Null removes the explicit system rule of that policy: the built-in default applies and lower layers may override it."
"description": "Values to persist, keyed by policy identifier, each as an explicit system rule even when it equals the default. Null removes the explicit system rule of that policy: the built-in default applies and lower layers may override it.",
"allOf": [
{
"$ref": "#/components/schemas/PolicyValueMap"
}
]
},
"allowChildOverride": {
"type": "object",
Expand Down
Loading
Loading