java type generation added
This commit is contained in:
parent
d46a3410d9
commit
1cd0fe5317
|
|
@ -0,0 +1,23 @@
|
|||
import LeadKit
|
||||
import ObjectMapper
|
||||
|
||||
final class ApiDateFormattingService: DateFormattingService {
|
||||
|
||||
static let shared = ApiDateFormattingService()
|
||||
|
||||
private init() {
|
||||
super.init(formattingArguments: [
|
||||
{% for dateFormat in dateFormats -%}
|
||||
DateFormattingArguments(dateFormat: "{{ dateFormat }}"){% if not (loop.last) %},{%- endif %}
|
||||
{% endfor %}
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
extension ApiDateFormattingService {
|
||||
|
||||
func mappingTransform(for dateFormat: String) -> TransformOf<Date, String> {
|
||||
return mappingTransform(for: DateFormattingArguments(dateFormat: dateFormat))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
{%- set hasParent = parent is not null -%}
|
||||
/**
|
||||
* This code is autogenerated by Touch Instinct tools
|
||||
*/
|
||||
|
|
@ -17,4 +18,11 @@ public class {% include 'blocks/class/classtype.twig' with { type: type } %} ext
|
|||
super();
|
||||
}
|
||||
|
||||
{% if (fields is not empty) %}
|
||||
public {{ type.baseTypeName }}({%- include 'blocks/class/init-parameters-fields.twig' with { fields: allFieldsOrdered } -%}) {
|
||||
super();
|
||||
}
|
||||
{% endif %}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,3 +1 @@
|
|||
{%- import '../../utils.twig' as utils -%}
|
||||
|
||||
{{- type.baseTypeName -}}{%- include 'type-parameters.twig' with { typeParameters: type.typeParameters } -%}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
{%- import '../../utils.twig' as utils -%}
|
||||
|
||||
{%- if fields is not empty -%}
|
||||
{%- for field in fields -%}
|
||||
{{ utils.writeNullCheckAnnotation(field.type.type.baseTypeName) }} final {{ utils.formatValueType(field.type.type, field.nullable, field.optional) }} {{ field.name }} {%- if not (loop.last) %}, {% endif %}
|
||||
{%- endfor -%}
|
||||
{%- endif -%}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
{%- if typeParameters is not empty -%}
|
||||
<
|
||||
{%- for typeParameter in typeParameters %}
|
||||
{{- utils.formatValueType(typeParameter) -}}{%- if not (loop.last) %}, {% endif %}
|
||||
{{- utils.formatSimpleValueType(typeParameter) -}}{%- if not (loop.last) %}, {% endif %}
|
||||
{%- endfor -%}
|
||||
>
|
||||
{%- endif -%}
|
||||
|
|
@ -18,22 +18,51 @@ LoganSquareJsonModel
|
|||
{%- endif -%}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro formatNullable(expr, nullable, optional) %}
|
||||
{{- expr -}}{%- if nullable or optional -%}?{%- endif -%}
|
||||
{% macro writeNullCheckAnnotation(baseTypeName, nullable, optional) %}
|
||||
{%- if optional -%}
|
||||
@NonNull
|
||||
{%- elseif nullable -%}
|
||||
@Nullable
|
||||
{%- elseif not (baseTypeName == "Int" or baseTypeName == "Long" or baseTypeName == "Double" or baseTypeName == "Decimal" or baseTypeName == "Bool") -%}
|
||||
@NonNull
|
||||
{%- endif -%}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro formatValueType(valueType) %}
|
||||
{%- if valueType.baseTypeName == "Array" -%}
|
||||
List<{{ valueType.itemsType.baseTypeName }}>
|
||||
{% macro formatNonOptionalValueType(valueType, tryUsePrimitive) %}
|
||||
{% import _self as self %}
|
||||
{%- if valueType.baseTypeName == "Int" -%}
|
||||
{%- if tryUsePrimitive -%}int{%- else -%}Integer{%- endif -%}
|
||||
{%- elseif valueType.baseTypeName == "Long" -%}
|
||||
{%- if tryUsePrimitive -%}long{%- else -%}Long{%- endif -%}
|
||||
{%- elseif valueType.baseTypeName == "Double" -%}
|
||||
{%- if tryUsePrimitive -%}double{%- else -%}Double{%- endif -%}
|
||||
{%- elseif valueType.baseTypeName == "Decimal" -%}
|
||||
BigDecimal
|
||||
{%- elseif valueType.baseTypeName == "Bool" -%}
|
||||
{%- if tryUsePrimitive -%}bool{%- else -%}Boolean{%- endif -%}
|
||||
{%- elseif valueType.baseTypeName == "Map" -%}
|
||||
Map<{{ valueType.keysType.baseTypeName }}, {{ valueType.valuesType.baseTypeName }}>
|
||||
{%- elseif valueType.baseTypeName == "DateTime" -%}
|
||||
DateTime
|
||||
Map<{{ self.formatNonOptionalValueType(valueType.keysType, false) }}, {{ self.formatNonOptionalValueType(valueType.valuesType, false) }}>
|
||||
{%- elseif valueType.baseTypeName == "Array" -%}
|
||||
List<{{ self.formatNonOptionalValueType(valueType.itemsType, false) }}>
|
||||
{%- else -%}
|
||||
{{ valueType.baseTypeName }}
|
||||
{%- endif -%}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro formatValueType(valueType, nullable, optional) %}
|
||||
{% import _self as self %}
|
||||
{%- if optional -%}
|
||||
JsonOptional<{{ self.formatNonOptionalValueType(valueType, false) }}>
|
||||
{%- else -%}
|
||||
{{ self.formatNonOptionalValueType(valueType, not nullable) }}
|
||||
{%- endif -%}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro formatSimpleValueType(valueType) %}
|
||||
{%- import _self as self -%}
|
||||
{{- self.formatValueType(valueType, true, false) -}}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro escapeIfNeeded(expr) %}
|
||||
{%- if expr == "default" -%}
|
||||
`{{ expr }}`
|
||||
|
|
|
|||
Loading…
Reference in New Issue