implementing controllers
fjahangiri opened this issue · comments
I'm not so familiar with Laravel . am I supposed to implement controllers? for example can I add something like this to openapi.json file and this operation woiuld be implemented automatically?
"/pets": {
"get": {
"description": "Returns all pets from the system that the user has access to",
"responses": {
"200": {
"description": "A list of pets.",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/pet"
}
}
}
}
}
}
}
}
Hi, there is an implementation with props and types which is more strict and powerful then just a scheme in terms of input data. You can get as an example Article entity from tests/functional/oas/
for example Attributes:
"ArticleAttributes": {
"description": "Article attributes description",
"type": "object",
"properties": {
"title": {
"type": "string",
"required": true,
"minLength": 16,
"maxLength": 256
},
"description": {
"required": true,
"type": "string",
"minLength": 32,
"maxLength": 1024,
"facets": {
"spell_check": true,
"spell_language": "en"
}
},
"url": {
"required": false,
"type": "string",
"minLength": 16,
"maxLength": 255,
"facets": {
"index": {
"idx_url": "unique"
}
}
},
"show_in_top": {
"description": "Show at the top of main page",
"required": false,
"type": "boolean"
},
"status": {
"description": "The state of an article",
"enum": [
"draft",
"published",
"postponed",
"archived"
],
"facets": {
"state_machine": {
"initial": [
"draft"
],
"draft": [
"published"
],
"published": [
"archived",
"postponed"
],
"postponed": [
"published",
"archived"
],
"archived": []
}
}
},
"topic_id": {
"description": "ManyToOne Topic relationship",
"required": true,
"type": "integer",
"minimum": 1,
"maximum": 6,
"facets": {
"index": {
"idx_fk_topic_id": "foreign",
"references": "id",
"on": "topic",
"onDelete": "cascade",
"onUpdate": "cascade"
}
}
},
"rate": {
"type": "number",
"minimum": 3,
"maximum": 9,
"format": "double"
},
"date_posted": {
"type": "date-only"
},
"time_to_live": {
"type": "time-only"
},
"deleted_at": {
"type": "datetime"
}
}
},
and
the Article object itself:
"Article": {
"type": "object",
"properties": {
"type": "Type",
"id": "SID",
"attributes": "ArticleAttributes",
"relationships": {
"type": "TagRelationships[] | TopicRelationships"
},
"cache": {
"type": "Redis",
"properties": {
"stampede_xfetch": {
"type": "boolean",
"default": true
},
"stampede_beta": {
"type": "number",
"default": 1.5
},
"ttl": {
"type": "integer",
"default": 300
}
}
}
}
},
I ran the api generator(I used existing example in test/functional/aos), this part of code seems to not be implemented :
<?php
namespace Modules\V3\Http\Controllers;
class ArticleController extends DefaultController
{
// >>>props>>>
// <<<props<<<
// >>>methods>>>
/**
.
.
.
am I suppose to add props and methods and implement inside of get and delete and other methods manually? or is there a way to specify this in .yaml file used for generating and then get final result automatically?
actually what I understand generally is that I can't use generated code as a REST api server directly and I have to complete implementation of APIs in controllers and generated codes include routes and entities. am I right? thank you so much for answering .
All props are generated in Requests, you can see an example here https://github.com/SoliDry/laravel-api/blob/master/Modules/V3/Http/Requests/ArticleFormRequest.php
and all the relations in Entities - https://github.com/SoliDry/laravel-api/blob/master/Modules/V3/Entities/Article.php
All those props, entities, methods, relations already bound together.
There should not be any implementation in Controller - it will work automatically (requests will be working with content from db CRUD ops, bulks etc), no props or methods should be implemented by hands. It is shown in Demos also.
I get it. Thanks😃