Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Resolve all TODOs in code #180

Open
SOHELAHMED7 opened this issue May 31, 2024 · 0 comments
Open

Resolve all TODOs in code #180

SOHELAHMED7 opened this issue May 31, 2024 · 0 comments

Comments

@SOHELAHMED7
Copy link
Contributor

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;
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant