From b124824a8d554f0d694b7f55851434c0b45b85f2 Mon Sep 17 00:00:00 2001
From: Jonathan Chan
Date: Thu, 12 Jun 2014 03:56:54 -0400
Subject: [PATCH 1/3] added file type to FormType Parser
---
DataTypes.php | 20 ++++++++++----------
Parser/FormTypeParser.php | 1 +
2 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/DataTypes.php b/DataTypes.php
index 7e02741..1df2190 100644
--- a/DataTypes.php
+++ b/DataTypes.php
@@ -18,27 +18,27 @@ namespace Nelmio\ApiDocBundle;
*/
class DataTypes
{
- const INTEGER = 'integer';
+ const INTEGER = 'integer';
- const FLOAT = 'float';
+ const FLOAT = 'float';
- const STRING = 'string';
+ const STRING = 'string';
- const BOOLEAN = 'boolean';
+ const BOOLEAN = 'boolean';
- const FILE = 'file';
+ const FILE = 'file';
- const ENUM = 'choice';
+ const ENUM = 'choice';
const COLLECTION = 'collection';
- const MODEL = 'model';
+ const MODEL = 'model';
- const DATE = 'date';
+ const DATE = 'date';
- const DATETIME = 'datetime';
+ const DATETIME = 'datetime';
- const TIME = 'time';
+ const TIME = 'time';
/**
* Returns true if the supplied `actualType` value is considered a primitive type. Returns false, otherwise.
diff --git a/Parser/FormTypeParser.php b/Parser/FormTypeParser.php
index bddfa05..14a4028 100644
--- a/Parser/FormTypeParser.php
+++ b/Parser/FormTypeParser.php
@@ -46,6 +46,7 @@ class FormTypeParser implements ParserInterface
'textarea' => DataTypes::STRING,
'country' => DataTypes::STRING,
'choice' => DataTypes::ENUM,
+ 'file' => DataTypes::FILE,
);
public function __construct(FormFactoryInterface $formFactory)
From 210596eae94436f05c49077c226dde3e3e12c8e1 Mon Sep 17 00:00:00 2001
From: Jonathan Chan
Date: Tue, 17 Jun 2014 00:10:34 -0400
Subject: [PATCH 2/3] adding support for different parameter types
---
Resources/views/layout.html.twig | 59 ++++++++++++++++++++++++++++++--
Resources/views/method.html.twig | 27 +++++++++++++--
2 files changed, 81 insertions(+), 5 deletions(-)
diff --git a/Resources/views/layout.html.twig b/Resources/views/layout.html.twig
index 2c964fe..b67a5c5 100644
--- a/Resources/views/layout.html.twig
+++ b/Resources/views/layout.html.twig
@@ -101,6 +101,39 @@
});
{% if enableSandbox %}
+ var setParameterType = function ($context,setType) {
+ // no 2nd argument, use default from parameters
+ if (typeof setType == "undefined") {
+ setType = $context.parent().attr("data-dataType");
+ $context.val(setType);
+ }
+
+ $context.parent().find('.value').remove();
+ var placeholder = "";
+ if ($context.parent().attr("data-dataType") != "" && typeof $context.parent().attr("data-dataType") != "undefined") {
+ placeholder += "[" + $context.parent().attr("data-dataType") + "] ";
+ }
+ if ($context.parent().attr("data-format") != "" && typeof $context.parent().attr("data-format") != "undefined") {
+ placeholder += $context.parent().attr("data-dataType");
+ }
+ if ($context.parent().attr("data-description") != "" && typeof $context.parent().attr("data-description") != "undefined") {
+ placeholder += $context.parent().attr("data-description");
+ } else {
+ placeholder += "Value";
+ }
+
+ switch(setType) {
+ case "boolean":
+ $('').insertAfter($context);
+ break;
+ case "file":
+ $('').insertAfter($context);
+ break;
+ default:
+ $('').insertAfter($context);
+ }
+ };
+
var toggleButtonText = function ($btn) {
if ($btn.text() === 'Default') {
$btn.text('Raw');
@@ -369,8 +402,30 @@
e.preventDefault();
});
- $('.pane.sandbox').on('click', '.add', function() {
- var html = $(this).parents('.pane').find('.tuple_template').html();
+
+ // sets the correct parameter type on load
+ $('.pane.sandbox .tuple_type').each(function() {
+ setParameterType($(this));
+ });
+
+
+ // handles parameter type change
+ $('.pane.sandbox').on('change', '.tuple_type', function() {
+ setParameterType($(this),$(this).val());
+ });
+
+
+
+ $('.pane.sandbox').on('click', '.add_parameter', function() {
+ var html = $(this).parents('.pane').find('.parameters_tuple_template').html();
+
+ $(this).before(html);
+
+ return false;
+ });
+
+ $('.pane.sandbox').on('click', '.add_header', function() {
+ var html = $(this).parents('.pane').find('.headers_tuple_template').html();
$(this).before(html);
diff --git a/Resources/views/method.html.twig b/Resources/views/method.html.twig
index b4b4ac2..8089805 100644
--- a/Resources/views/method.html.twig
+++ b/Resources/views/method.html.twig
@@ -228,14 +228,20 @@
Parameters
{% for name, infos in data.parameters %}
{% if not infos.readonly %}
-
+
=
+
-
{% endif %}
{% endfor %}
-
+
{% endif %}
@@ -257,7 +263,7 @@
-
-
+