public function buildParameters() { $rules = $this->originalModel->rules(); foreach ($rules as $rule) { if (isset($rule['on']) && $rule['on'] !== $this->scenario) { continue; } if (is_array($rule[0])) { foreach ($rule[0] as $name) { if (!isset($this->parameters[$name])) { $this->parameters[$name] = []; } if ($rule[1] === 'required') { $this->parameters[$name]['required'] = true; } if (in_array($rule[1], ['string', 'number', 'integer', 'boolean'])) { $this->parameters[$name]['type'] = $rule[1]; } } } elseif (is_string($rule[0])) { $name = $rule[0]; if (!isset($this->parameters[$name])) { $this->parameters[$name] = []; } if ($rule[1] === 'required') { $this->parameters[$name]['required'] = true; } if (in_array($rule[1], ['string', 'number', 'integer', 'boolean'])) { $this->parameters[$name]['type'] = $rule[1]; } } } foreach ($this->parameters as $name => $items) { $this->parameters[$name]['description'] = $this->modelAnnotationParser->getPropertyDesc($name) ?: var2HumanReadable($name); $this->parameters[$name]['required'] = isset($this->parameters[$name]['required']) ? $this->parameters[$name]['required'] : false; if (!isset($this->parameters[$name]['type'])) { if ($this->annotationParser->getPropertyType($name) === Swagger::DATA_TYPE_OBJECT) { if (!is_null($objectClass = $this->annotationParser->getPropertyObjectClass($name))) { $subFormModel = new FormModel(new $objectClass(), REST::SCENARIO_DEFAULT); $this->subFormModels[] = $subFormModel; $this->parameters[$name]['$ref'] = "#/definitions/{$subFormModel->name}"; } else { $this->parameters[$name]['type'] = Swagger::DATA_TYPE_OBJECT; } } elseif ($this->annotationParser->getPropertyType($name) === Swagger::DATA_TYPE_OBJECT_ARRAY) { $this->parameters[$name]['type'] = Swagger::DATA_TYPE_ARRAY; if (!is_null($objectClass = $this->annotationParser->getPropertyObjectClass($name))) { $subFormModel = new FormModel(new $objectClass(), REST::SCENARIO_DEFAULT); $this->subFormModels[] = $subFormModel; $this->parameters[$name]['items']['$ref'] = "#/definitions/{$subFormModel->name}"; } else { $this->parameters[$name]['items']['type'] = Swagger::DATA_TYPE_STRING; } } else { $this->parameters[$name]['type'] = Swagger::DATA_TYPE_STRING; } } } }
public function getPathIdParameter() { return ['type' => Swagger::DATA_TYPE_INTEGER, 'in' => Swagger::PARAMETER_IN_PATH, 'required' => true, 'description' => $this->modelAnnotationParser->getPropertyDesc('id') ?: var2HumanReadable('id')]; }
private function buildBaseProperties() { foreach ($this->getFields() as $field) { if ($this->annotationParser->getPropertyType($field) === Swagger::DATA_TYPE_OBJECT) { if (!is_null($objectClass = $this->annotationParser->getPropertyObjectClass($field))) { $this->baseProperties[$field]['$ref'] = "#/definitions/{$objectClass}#BaseFields"; } else { $this->baseProperties[$field]['type'] = Swagger::DATA_TYPE_OBJECT; } } elseif ($this->annotationParser->getPropertyType($field) === Swagger::DATA_TYPE_OBJECT_ARRAY) { $this->baseProperties[$field]['type'] = Swagger::DATA_TYPE_ARRAY; if (!is_null($objectClass = $this->annotationParser->getPropertyObjectClass($field))) { $this->baseProperties[$field]['items']['$ref'] = "#/definitions/{$objectClass}#BaseFields"; } else { $this->baseProperties[$field]['items']['type'] = Swagger::DATA_TYPE_STRING; } } elseif ($this->annotationParser->getPropertyType($field) === Swagger::DATA_TYPE_ARRAY) { $this->properties[$field]['type'] = $this->annotationParser->getPropertyType($field); $this->properties[$field]['items']['type'] = Swagger::DATA_TYPE_STRING; } else { $this->baseProperties[$field]['type'] = $this->annotationParser->getPropertyType($field) ?: Swagger::DATA_TYPE_STRING; } $this->baseProperties[$field]['description'] = $this->annotationParser->getPropertyDesc($field) ?: var2HumanReadable($field); } }