This repository was archived by the owner on Jun 4, 2024. It is now read-only.
This repository was archived by the owner on Jun 4, 2024. It is now read-only.
Resolve all TODOs in code #180
Open
Description
Example:
src/lib/SchemaToDatabase.php
public function prepareModels():array
{
$models = [];
$openApi = $this->config->getOpenApi();
$junctions = $this->findJunctionSchemas();
foreach ($openApi->components->schemas as $schemaName => $openApiSchema) {
$schema = Yii::createObject(ComponentSchema::class, [$openApiSchema, $schemaName]);
if (!$this->canGenerateModel($schemaName, $schema)) {
continue;
}
if ($junctions->isJunctionSchema($schemaName)) {
$schemaName = $junctions->trimPrefix($schemaName);
}
/** @var \cebe\yii2openapi\lib\AttributeResolver $resolver */
$resolver = Yii::createObject(AttributeResolver::class, [$schemaName, $schema, $junctions, $this->config]);
$models[$schemaName] = $resolver->resolve();
}
foreach ($models as $model) {
foreach ($model->many2many as $relation) {
if (isset($models[$relation->viaModelName])) {
$relation->hasViaModel = true;
}
$relation->pkAttribute = $model->getPkAttribute();
$relation->relatedPkAttribute = $models[$relation->relatedSchemaName]->getPkAttribute();
}
}
// TODO generate inverse relations <------------ this one
return $models;
Metadata
Metadata
Assignees
Labels
No labels