Skip to content

Commit

Permalink
Fixes OpenApiResponse association permenantly modifying the Schema
Browse files Browse the repository at this point in the history
Resolves #363
  • Loading branch information
cnizzardini authored Dec 27, 2021
1 parent a53bc2d commit 869c8c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/Lib/Operation/OperationResponseAssociation.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,12 @@ private function findSchema(Table $table, string $schemaMode): Schema

$entityName = $this->inflector::singularize($table->getAlias());

return $this->swagger->getSchemaByName($entityName . '-' . $schemaMode) ??
$this->buildAssociatedSchema($entityName, $table->getAlias());
$schema = $this->swagger->getSchemaByName($entityName . '-' . $schemaMode);
if ($schema) {
return clone $schema;
}

return clone $this->buildAssociatedSchema($entityName, $table->getAlias());
}

/**
Expand Down
8 changes: 7 additions & 1 deletion tests/TestCase/Lib/Operation/OperationResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,10 @@ public function test_associations(): void
])
);

$swagger = (new SwaggerFactory($this->config, new RouteScanner($this->router, $this->config)))->create();

$operationResponse = new OperationResponse(
(new SwaggerFactory($this->config, new RouteScanner($this->router, $this->config)))->create(),
$swagger,
$this->config,
new Operation('hello', 'get'),
$route,
Expand All @@ -383,6 +385,10 @@ public function test_associations(): void
$operation = $operationResponse->getOperationWithResponses();
$content = $operation->getResponseByCode('200')->getContentByMimeType('application/json');
$this->assertArrayHasKey('department_employees', $content->getSchema()->getProperties());

// issue #363 association schema should only modify the operations response schema and not the main schema.
$schema = $swagger->getSchemaByName('Employee-Read');
$this->assertArrayNotHasKey('department_employees', $schema->getProperties());
}

public function test_text_plain_mime_type(): void
Expand Down

0 comments on commit 869c8c9

Please sign in to comment.