Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/Spec/Swagger2.php
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,6 @@ public function getDefinitions(): array
'description' => $schema['description'] ?? '',
'required' => $schema['required'] ?? [],
'additionalProperties' => $schema['additionalProperties'] ?? [],
'additionalPropertiesKey' => $schema['x-additional-properties-key'] ?? 'data',
];
if (isset($model['properties'])) {
foreach ($model['properties'] as $name => $def) {
Expand Down Expand Up @@ -681,7 +680,6 @@ public function getRequestModels(): array
'description' => $schema['description'] ?? '',
'required' => $schema['required'] ?? [],
'additionalProperties' => $schema['additionalProperties'] ?? [],
'additionalPropertiesKey' => $schema['x-additional-properties-key'] ?? 'data',
];
if (isset($model['properties'])) {
foreach ($model['properties'] as $name => $def) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ import {{ sdk.namespace | caseDot }}.enums.{{ property.enumName | caseUcfirst }}
/**
* Additional properties
*/
@SerializedName("{{ definition.additionalPropertiesKey | default('data') | escapeDollarSign }}")
val {{ definition.additionalPropertiesKey | default('data') | escapeKeyword | removeDollarSign }}: T
@SerializedName("{{ 'data' | escapeDollarSign }}")
val {{ 'data' | escapeKeyword | removeDollarSign }}: T
{%~ endif %}
) {
fun toMap(): Map<String, Any> = mapOf(
{%~ for property in definition.properties %}
"{{ property.name | escapeDollarSign }}" to {% if property.sub_schema %}{% if property.type == 'array' %}{{property.name | escapeKeyword | removeDollarSign}}{% if not property.required %}?{% endif %}.map { it.toMap() }{% else %}{{property.name | escapeKeyword | removeDollarSign}}{% if not property.required %}?{% endif %}.toMap(){% endif %}{% elseif property.enum %}{{property.name | escapeKeyword | removeDollarSign}}{% if not property.required %}?{% endif %}.value{% else %}{{property.name | escapeKeyword | removeDollarSign}}{% endif %} as Any,
{%~ endfor %}
{%~ if definition.additionalProperties %}
"{{ definition.additionalPropertiesKey | default('data') | escapeDollarSign }}" to {{ definition.additionalPropertiesKey | default('data') | escapeKeyword | removeDollarSign }}!!.jsonCast(to = Map::class.java)
"{{ 'data' | escapeDollarSign }}" to {{ 'data' | escapeKeyword | removeDollarSign }}!!.jsonCast(to = Map::class.java)
{%~ endif %}
)

Expand All @@ -46,14 +46,14 @@ import {{ sdk.namespace | caseDot }}.enums.{{ property.enumName | caseUcfirst }}
{{ property.name | escapeKeyword | removeDollarSign }}: {{ property | propertyType(spec, 'Map<String, Any>') | raw }},
{%~ endfor %}
{%~ if definition.additionalProperties %}
{{ definition.additionalPropertiesKey | default('data') | escapeKeyword | removeDollarSign }}: Map<String, Any>
{{ 'data' | escapeKeyword | removeDollarSign }}: Map<String, Any>
{%~ endif %}
) = {{ definition | modelType(spec, 'Map<String, Any>') | raw }}(
{%~ for property in definition.properties %}
{{ property.name | escapeKeyword | removeDollarSign }},
{%~ endfor %}
{%~ if definition.additionalProperties %}
{{ definition.additionalPropertiesKey | default('data') | escapeKeyword | removeDollarSign }}
{{ 'data' | escapeKeyword | removeDollarSign }}
{%~ endif %}
)
{%~ endif %}
Expand All @@ -69,11 +69,7 @@ import {{ sdk.namespace | caseDot }}.enums.{{ property.enumName | caseUcfirst }}
{{ property.name | escapeKeyword | removeDollarSign }} = {{ property | propertyAssignment(spec) | raw }},
{%~ endfor %}
{%~ if definition.additionalProperties %}
{%~ if definition.properties | length > 0 %}
{{ definition.additionalPropertiesKey | default('data') | escapeKeyword | removeDollarSign }} = map["{{ definition.additionalPropertiesKey | default('data') | escapeDollarSign }}"]?.jsonCast(to = nestedType) ?: emptyMap<String, Any>().jsonCast(to = nestedType)
{%~ else %}
{{ definition.additionalPropertiesKey | default('data') | escapeKeyword | removeDollarSign }} = map["{{ definition.additionalPropertiesKey | default('data') | escapeDollarSign }}"]?.jsonCast(to = nestedType) ?: map.jsonCast(to = nestedType)
{%~ endif %}
{{ 'data' | escapeKeyword | removeDollarSign }} = map["{{ 'data' | escapeDollarSign }}"]?.jsonCast(to = nestedType) ?: map.jsonCast(to = nestedType)
{%~ endif %}
)
}
Expand Down
14 changes: 5 additions & 9 deletions templates/dart/lib/src/models/model.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class {{ definition.name | caseUcfirst | overrideIdentifier }} implements Model

{% endfor %}
{%~ if definition.additionalProperties %}
final Map<String, dynamic> {{ definition.additionalPropertiesKey | default('data') | escapeKeyword }};
final Map<String, dynamic> {{ 'data' | escapeKeyword }};

{% endif %}
{{ definition.name | caseUcfirst | overrideIdentifier}}({% if definition.properties | length or definition.additionalProperties %}{{ '{' }}{% endif %}
Expand All @@ -18,7 +18,7 @@ class {{ definition.name | caseUcfirst | overrideIdentifier }} implements Model
{% if property.required %}required {% endif %}this.{{ property.name | escapeKeyword }},
{% endfor %}
{% if definition.additionalProperties %}
required this.{{ definition.additionalPropertiesKey | default('data') | escapeKeyword }},
required this.{{ 'data' | escapeKeyword }},
{% endif %}
{% if definition.properties | length or definition.additionalProperties %}{{ '}' }}{% endif %});

Expand Down Expand Up @@ -54,11 +54,7 @@ class {{ definition.name | caseUcfirst | overrideIdentifier }} implements Model
{%- endif -%},
{% endfor %}
{% if definition.additionalProperties %}
{% if definition.properties | length > 0 %}
{{ definition.additionalPropertiesKey | default('data') | escapeKeyword }}: Map<String, dynamic>.from(map["{{ definition.additionalPropertiesKey | default('data') | escapeDollarSign }}"] ?? {}),
{% else %}
{{ definition.additionalPropertiesKey | default('data') | escapeKeyword }}: map["{{ definition.additionalPropertiesKey | default('data') | escapeDollarSign }}"] ?? map,
{% endif %}
{{ 'data' | escapeKeyword }}: map["{{ 'data' | escapeDollarSign }}"] ?? map,
{% endif %}
);
}
Expand All @@ -70,13 +66,13 @@ class {{ definition.name | caseUcfirst | overrideIdentifier }} implements Model
"{{ property.name | escapeDollarSign }}": {{ property | modelToMapValue }},
{% endfor %}
{% if definition.additionalProperties %}
"{{ definition.additionalPropertiesKey | default('data') | escapeDollarSign }}": {{ definition.additionalPropertiesKey | default('data') | escapeKeyword }},
"{{ 'data' | escapeDollarSign }}": {{ 'data' | escapeKeyword }},
{% endif %}
};
}
{% if definition.additionalProperties %}

T convertTo<T>(T Function(Map<String, dynamic>) fromJson) => fromJson({{ definition.additionalPropertiesKey | default('data') | escapeKeyword }});
T convertTo<T>(T Function(Map<String, dynamic>) fromJson) => fromJson({{ 'data' | escapeKeyword }});
{% endif %}
{% for property in definition.properties %}
{% if property.sub_schema %}
Expand Down
2 changes: 1 addition & 1 deletion templates/dart/test/src/models/model_test.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void main() {
{{ property.name | escapeKeyword }}: {% if property.type == 'array' %}[]{% elseif property.type == 'object' and (property.sub_schema == 'prefs' or property.sub_schema == 'preferences') %}Preferences(data: {}){% elseif property.type == 'object' and property.sub_schema %}{{_self.sub_schema(spec.definitions, property)}}{% elseif property.type == 'object' %}{}{% elseif property.enum %}{{ property.enumName | caseUcfirst }}.{{ (property.enumKeys[0] ?? property.enum[0]) | caseEnumKey }}{% elseif property.type == 'string' %}'{{property['x-example'] | escapeDollarSign}}'{% elseif property.type == 'boolean' %}true{% else %}{{property['x-example']}}{% endif %},
{% endfor %}
{% if definition.additionalProperties %}
{{ definition.additionalPropertiesKey | default('data') | escapeKeyword }}: {},
{{ 'data' | escapeKeyword }}: {},
{% endif %}
);

Expand Down
12 changes: 6 additions & 6 deletions templates/dotnet/Package/Models/Model.cs.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace {{ spec.title | caseUcfirst }}.Models

{%~ endfor %}
{%~ if definition.additionalProperties %}
public Dictionary<string, object> {{ definition.additionalPropertiesKey | default('data') | caseUcfirst | escapeKeyword | removeDollarSign }} { get; private set; }
public Dictionary<string, object> {{ 'data' | caseUcfirst | escapeKeyword | removeDollarSign }} { get; private set; }

{%~ endif %}
public {{ definition.name | caseUcfirst | overrideIdentifier }}(
Expand All @@ -26,15 +26,15 @@ namespace {{ spec.title | caseUcfirst }}.Models

{%~ endfor %}
{%~ if definition.additionalProperties %}
Dictionary<string, object> {{ definition.additionalPropertiesKey | default('data') | caseCamel | escapeKeyword | removeDollarSign }}
Dictionary<string, object> {{ 'data' | caseCamel | escapeKeyword | removeDollarSign }}
{%~ endif %}
)
{
{%~ for property in definition.properties %}
{{ property_name(definition, property) | overrideProperty(definition.name) }} = {{ property.name | caseCamel | escapeKeyword }};
{%~ endfor %}
{%~ if definition.additionalProperties %}
{{ definition.additionalPropertiesKey | default('data') | caseUcfirst | escapeKeyword | removeDollarSign }} = {{ definition.additionalPropertiesKey | default('data') | caseCamel | escapeKeyword | removeDollarSign }};
{{ 'data' | caseUcfirst | escapeKeyword | removeDollarSign }} = {{ 'data' | caseCamel | escapeKeyword | removeDollarSign }};
{%~ endif %}
}

Expand Down Expand Up @@ -81,7 +81,7 @@ namespace {{ spec.title | caseUcfirst }}.Models
{%~ endif %}
{%~ endfor %}
{%- if definition.additionalProperties %}
{{ definition.additionalPropertiesKey | default('data') | caseCamel | escapeKeyword | removeDollarSign }}: map.TryGetValue("{{ definition.additionalPropertiesKey | default('data') }}", out var additionalPropsValue)
{{ 'data' | caseCamel | escapeKeyword | removeDollarSign }}: map.TryGetValue("{{ 'data' }}", out var additionalPropsValue)
? (Dictionary<string, object>)additionalPropsValue
: map
{%- endif ~%}
Expand All @@ -94,13 +94,13 @@ namespace {{ spec.title | caseUcfirst }}.Models

{%~ endfor %}
{%~ if definition.additionalProperties %}
{ "{{ definition.additionalPropertiesKey | default('data') }}", {{ definition.additionalPropertiesKey | default('data') | caseUcfirst | escapeKeyword | removeDollarSign }} }
{ "{{ 'data' }}", {{ 'data' | caseUcfirst | escapeKeyword | removeDollarSign }} }
{%~ endif %}
};
{%~ if definition.additionalProperties %}

public T ConvertTo<T>(Func<Dictionary<string, object>, T> fromJson) =>
fromJson.Invoke({{ definition.additionalPropertiesKey | default('data') | caseUcfirst | escapeKeyword | removeDollarSign }});
fromJson.Invoke({{ 'data' | caseUcfirst | escapeKeyword | removeDollarSign }});
{%~ endif %}
{%~ for property in definition.properties %}
{%~ if property.sub_schema %}
Expand Down
16 changes: 6 additions & 10 deletions templates/kotlin/src/main/kotlin/io/appwrite/models/Model.kt.twig
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ import {{ sdk.namespace | caseDot }}.enums.{{ property.enumName | caseUcfirst }}
/**
* Additional properties
*/
@SerializedName("{{ definition.additionalPropertiesKey | default('data') | escapeDollarSign }}")
val {{ definition.additionalPropertiesKey | default('data') | escapeKeyword | removeDollarSign }}: T
@SerializedName("{{ 'data' | escapeDollarSign }}")
val {{ 'data' | escapeKeyword | removeDollarSign }}: T
{%~ endif %}
) {
fun toMap(): Map<String, Any> = mapOf(
{%~ for property in definition.properties %}
"{{ property.name | escapeDollarSign }}" to {% if property.sub_schema %}{% if property.type == 'array' %}{{property.name | escapeKeyword | removeDollarSign}}{% if not property.required %}?{% endif %}.map { it.toMap() }{% else %}{{property.name | escapeKeyword | removeDollarSign}}{% if not property.required %}?{% endif %}.toMap(){% endif %}{% elseif property.enum %}{{property.name | escapeKeyword | removeDollarSign}}{% if not property.required %}?{% endif %}.value{% else %}{{property.name | escapeKeyword | removeDollarSign}}{% endif %} as Any,
{%~ endfor %}
{%~ if definition.additionalProperties %}
"{{ definition.additionalPropertiesKey | default('data') | escapeDollarSign }}" to {{ definition.additionalPropertiesKey | default('data') | escapeKeyword | removeDollarSign }}!!.jsonCast(to = Map::class.java)
"{{ 'data' | escapeDollarSign }}" to {{ 'data' | escapeKeyword | removeDollarSign }}!!.jsonCast(to = Map::class.java)
{%~ endif %}
)

Expand All @@ -46,14 +46,14 @@ import {{ sdk.namespace | caseDot }}.enums.{{ property.enumName | caseUcfirst }}
{{ property.name | escapeKeyword | removeDollarSign }}: {{ property | propertyType(spec, 'Map<String, Any>') | raw }},
{%~ endfor %}
{%~ if definition.additionalProperties %}
{{ definition.additionalPropertiesKey | default('data') | escapeKeyword | removeDollarSign }}: Map<String, Any>
{{ 'data' | escapeKeyword | removeDollarSign }}: Map<String, Any>
{%~ endif %}
) = {{ definition | modelType(spec, 'Map<String, Any>') | raw }}(
{%~ for property in definition.properties %}
{{ property.name | escapeKeyword | removeDollarSign }},
{%~ endfor %}
{%~ if definition.additionalProperties %}
{{ definition.additionalPropertiesKey | default('data') | escapeKeyword | removeDollarSign }}
{{ 'data' | escapeKeyword | removeDollarSign }}
{%~ endif %}
)
{%~ endif %}
Expand All @@ -69,11 +69,7 @@ import {{ sdk.namespace | caseDot }}.enums.{{ property.enumName | caseUcfirst }}
{{ property.name | escapeKeyword | removeDollarSign }} = {{ property | propertyAssignment(spec) | raw }},
{%~ endfor %}
{%~ if definition.additionalProperties %}
{%~ if definition.properties | length > 0 %}
{{ definition.additionalPropertiesKey | default('data') | escapeKeyword | removeDollarSign }} = map["{{ definition.additionalPropertiesKey | default('data') | escapeDollarSign }}"]?.jsonCast(to = nestedType) ?: emptyMap<String, Any>().jsonCast(to = nestedType)
{%~ else %}
{{ definition.additionalPropertiesKey | default('data') | escapeKeyword | removeDollarSign }} = map["{{ definition.additionalPropertiesKey | default('data') | escapeDollarSign }}"]?.jsonCast(to = nestedType) ?: map.jsonCast(to = nestedType)
{%~ endif %}
{{ 'data' | escapeKeyword | removeDollarSign }} = map["{{ 'data' | escapeDollarSign }}"]?.jsonCast(to = nestedType) ?: map.jsonCast(to = nestedType)
{%~ endif %}
)
}
Expand Down
8 changes: 4 additions & 4 deletions templates/php/src/Models/Model.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ readonly class {{ definition.name | caseUcfirst | overrideIdentifier }}
* @param {{ paramDocType | raw }}|null ${{ property.name | caseCamel }} {{ property.description | unescape | lower | raw }}
{% endfor %}
{% if definition.additionalProperties %}
* @param array<string, mixed> ${{ definition.additionalPropertiesKey | default('data') | caseCamel | removeDollarSign }} Additional properties.
* @param array<string, mixed> ${{ 'data' | caseCamel | removeDollarSign }} Additional properties.
{% endif %}
*/
public function __construct(
Expand All @@ -63,7 +63,7 @@ readonly class {{ definition.name | caseUcfirst | overrideIdentifier }}
public ?{{ property | typeName }} ${{ property.name | caseCamel }} = null{{ (not loop.last or definition.additionalProperties) ? ',' : '' }}
{% endfor %}
{% if definition.additionalProperties %}
public array ${{ definition.additionalPropertiesKey | default('data') | caseCamel | removeDollarSign }} = []
public array ${{ 'data' | caseCamel | removeDollarSign }} = []
{% endif %}
) {
}
Expand Down Expand Up @@ -140,7 +140,7 @@ readonly class {{ definition.name | caseUcfirst | overrideIdentifier }}
{% endif %}
{% endfor %}
{% if definition.additionalProperties %}
{{ definition.additionalPropertiesKey | default('data') | caseCamel | removeDollarSign }}: $additionalProperties
{{ 'data' | caseCamel | removeDollarSign }}: $additionalProperties
{% endif %}
);
{% endif %}
Expand All @@ -161,7 +161,7 @@ readonly class {{ definition.name | caseUcfirst | overrideIdentifier }}
];
{% if definition.additionalProperties %}

foreach (static::serializeAdditionalProperties($this->{{ definition.additionalPropertiesKey | default('data') | caseCamel | removeDollarSign }}) as $field => $value) {
foreach (static::serializeAdditionalProperties($this->{{ 'data' | caseCamel | removeDollarSign }}) as $field => $value) {
$result[$field] = $value;
}
{% endif %}
Expand Down
Loading
Loading