Swagger-php adding a "schema" property on every Model property - swagger

(This is my first stack overflow post so go easy on me, haha)
I'm using:
-OpenApi (v3)
-L5-Swagger (wrapper of swagger-php & swagger-ui)
I'm using annotations to generate an OpenAPI spec. The spec is being generated without errors from the console. However, in each property for every model there's an additional property being added once it generates.
I've tried:
1. re-writing the model,
2. rewriting the properties in different ways
One of my models & the "id" property:
/**
* Class ActionPlan
*
* #OA\Schema(
* description="Action Plans",
* title="Action Plan Schema",
* required={
* "id",
* "name",
* "organization_id",
* "assessment_period_id",
* "completed",
* "created_by",
* "updated_by"
* },
* )
*
* #OA\Property(
* property="id",
* type="integer",
* format="int32",
* description="Action Plan ID"
* )
Here's what is being generated:
"ActionPlan": {
"title": "Action Plan Schema",
"description": "Action Plans",
"required": [
"id",
"name",
"organization_id",
"assessment_period_id",
"completed",
"created_by",
"updated_by"
],
"properties": {
"id": {
"schema": "ActionPlan",
"description": "Action Plan ID",
"type": "integer",
"format": "int32"
},
What am I doing that there's a "schema" property being generated?
When I put the spec file into Swagger editor, it says that ActionPlan.properties.id should NOT have additional properties. Additional property: schema.
I'm just wondering what's happening to make create "schema" property.
Thanks in advance!

This "error", I learned, is actually not an error at all. It's actually a very helpful feature that I was just unaware of! When an OA\Property is created outside of it's corresponding OA\Schema object, a "schema" property is added in each property to, I imagine, create a reference so we as developers don't lose become confused as to which OA\Schema a property belongs to. To remove this "schema" property, one just needs to move all the OA\Properties inside their corresponding OA\Schema object. Like so..
/**
* Class ActionPlan
*
* #OA\Schema(
* description="Action Plans",
* title="Action Plan Schema",
* required={
* "id",
* "name",
* "organization_id",
* "assessment_period_id",
* "completed",
* "created_by",
* "updated_by"
* },
* #OA\Property(
* property="id",
* type="integer",
* format="int32",
* description="Action Plan ID"
* )
* )
*/

Related

Ho to add multiple example items on swagger

Need help on how to do this on swagger.
#SWG\Property(property="LineItems", type="array", #SWG\Items(ref="#/definitions/LineItem"))
#SWG\Definition(
definition="LineItem",
required={"Description","Quantity","UnitAmount"},
#SWG\Property(property="Description", type="string", example="Item 1"),
#SWG\Property(property="Quantity", type="integer", example=100),
#SWG\Property(property="UnitAmount", type="float", example=11)
)
#SWG\Definition(
definition="LineItem2",
required={"Description","Quantity","UnitAmount"},
#SWG\Property(property="Description", type="string", example="Item 2"),
#SWG\Property(property="Quantity", type="integer", example=10),
#SWG\Property(property="UnitAmount", type="float", example=21)
)
I want to add LineItem and LineItem2 on LineItems property, I want the output should be like this
"LineItems": [
{
"Description": "Item 1",
"Quantity": 100,
"UnitAmount": 11,
},
{
"Description": "Item 2",
"Quantity": 100,
"UnitAmount": 22,
}
]
To display array example with multiple items in Swagger UI, you need an array-level example, such as:
LineItems:
type: array
items:
$ref: '#/definitions/LineItem'
# Multi-item example
example:
- Description: Item 1
Quantity: 100
UnitAmount: 11
- Description: Item 2
Quantity: 100
UnitAmount: 22
That is, there is a single definition for array items (LineItem), and the multi-item example is defined using the example keyword on the array level.
The Swagger-PHP version of this would be:
* #SWG\Property(
* property="LineItems",
* type="array",
* #SWG\Items(ref="#/definitions/LineItem"),
* example = {
* {"Description": "Item 1", "Quantity": 100, "UnitAmount": 11},
* {"Description": "Item 2", "Quantity": 100, "UnitAmount": 22}
* }
* )

Swagger query parameter template

I have on query parameter which is little bit complex and i have my own syntax to make that value. Its has more then one variable to make one complete string value.
Let suppose name of parameter is index which has row and column like to make this value 20:30
index = { row: 20, col:30 }
index2 = { row: 20, col:30, chr: 15 }
Now i wanted to make it as
example.com?index=20:30
example.com?index2=20:30:15
Can someone tell me how can i define this in swagger ?
Thank you.
Make your swagger parameter a string and in your code behind handle the splitting into multiple variables...
I do exactly that here:
http://turoapi.azurewebsites.net/swagger/ui/index#/Echo/Echo_Get
"parameters": [
{
"name": "location",
"in": "query",
"description": "SoFL= 26.16,-80.20",
"required": true,
"type": "string"
},
That location is (Latitude,Longitude) and I split it with a C# TypeConverter
...and the request looks like:
http://turoapi.azurewebsites.net/api/Echo?location=26.16,-80.20
The code for that WebApi is here:
https://github.com/heldersepu/TuroApi

Order CollectionType in FormType with many-to-many relation

I have a relation many-to-many.
In Entity "Progetti" i have:
/**
*
* #var \Doctrine\Common\Collections\ArrayCollection $attivita
*
* #ORM\ManyToMany(targetEntity="Attivita", inversedBy="progetti",cascade={"persist", "remove" })
* #ORM\JoinTable(name="progetti_attivita",
* joinColumns={#ORM\JoinColumn(name="progetti_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="attivita_id", referencedColumnName="id")}
* )
*/
protected $attivita;
In Entity "Attività" i have:
/**
*
* #var \Doctrine\Common\Collections\ArrayCollection $progetti
* #ORM\ManyToMany(targetEntity="Progetti", mappedBy="attivita")
*/
protected $progetti;
Ok.
The JoinTable "progetti_attivita" has "attivita_id" and "progetti_id".
Now i added a new field to the JoinTable "progetti_attivita" and i called it "position". it's an integer.
I have the ProgettiType Form:
$builder
->add('nomeProgetto')
->add('descProgetto')
->add('noteProgetto')
->add('attivita', CollectionType::class, array(
'entry_type' => AttivitaType::class,
'allow_add' => true,
));
Ok.
I have the form that display all "attività" for "progetti".
My question is:
How can i say to Form to display "attivita" ordered by "position" ?
If you always want your collection to be ordered then you can add the OrderBy property to your Doctrine mapping:
http://doctrine-orm.readthedocs.io/projects/doctrine-orm/en/latest/tutorials/ordered-associations.html
/**
* #ManyToMany(targetEntity="Attivita")
* #OrderBy({"position" = "ASC"})
**/
private $attivitas;
An alternative approach would be to add a getAttivitaOrdered method to your Progetti entity:
class Progetti
getAttivitaOrdered() // return ordered list
->add('attivitaOrdered', CollectionType::class ...
Not sure if you will need a setAttivitaOrdered method or not when you post.
And your question is actually a little bit confusing. Adding a property to your join table means that you need to use OneToMany and ManyToOne relations instead of ManyToMany. So a few more adjustments will be needed.

Get Yahoo weather in celsius via their API

Trying to make a query in YQL console. This one works fine:
select * from weather.forecast where woeid=1989965
But I want to get values in metric system (celsius), so I use this query:
select * from weather.forecast where woeid=1989965 and unit='c'
I get a null result:
{
"query": {
"count": 0,
"created": "2016-03-28T01:46:08Z",
"lang": "ru",
"results": null
}
}
I could convert values by myself, but I hope I can make it work out of the box...
Today I discovered, u='c' is worked. So, the answer for my own question would be:
select * from weather.forecast where woeid=1989965 and u='c'

Simulating an enum type in Propel: error trying to generate form classes

documento: {type: varchar, sqltype: enum, size:
"'F','DDT','RC','FOURTH_ELEMENT','PM','KV','VN','CMS'", required:
true, defaultValue: 'F', required: true}
I get the next error message (always with the fourth element, I mean
if i write 3 or less elements it doesn't give any error):
propel generating form classes
Cannot fetch TableMap for undefined
table: FOURTH_ELEMENT
[?php
/** * sfGuardUserProfile form base
class. * * #method
sfGuardUserProfile getObject() Returns
the current form's model object * *
#package ##PROJECT_NAME## *
#subpackage form * #author
AUTHOR_NAME * #version SVN: $Id: sfPropelFormGeneratedTemplate.php
24171 2009-11-19 16:37:50Z
Kris.Wallsmith $ */ abstract class
BasesfGuardUserProfileForm extends
BaseFormPropel { public function
setup() {
$this->setWidgets(array(
sf 1.4.
Javier
You should upgrade to Propel 1.6.3 in order to get the advanced columns feature (ENUM for instance): http://www.propelorm.org/cookbook/working-with-advanced-column-types.html#enum_columns.
William

Resources