use of cz.habarta.typescript.generator.TsParameter in project typescript-generator by vojtechhabarta.
the class ModelCompiler method createRestClients.
private void createRestClients(TsModel tsModel, SymbolTable symbolTable, List<RestApplicationModel> restApplications, Symbol responseSymbol, TsType.GenericVariableType optionsGenericVariable, TsType optionsType) {
final Symbol httpClientSymbol = symbolTable.getSyntheticSymbol("HttpClient");
final List<TsType.GenericVariableType> typeParameters = Utils.listFromNullable(optionsGenericVariable);
// HttpClient interface
final TsType.GenericVariableType returnGenericVariable = new TsType.GenericVariableType("R");
tsModel.getBeans().add(new TsBeanModel(null, TsBeanCategory.ServicePrerequisite, false, httpClientSymbol, typeParameters, null, null, null, null, null, Arrays.asList(new TsMethodModel("request", TsModifierFlags.None, Arrays.asList(returnGenericVariable), Arrays.asList(new TsParameterModel("requestConfig", new TsType.ObjectType(new TsProperty("method", TsType.String), new TsProperty("url", TsType.String), new TsProperty("queryParams", new TsType.OptionalType(TsType.Any)), new TsProperty("data", new TsType.OptionalType(TsType.Any)), new TsProperty("copyFn", new TsType.OptionalType(new TsType.FunctionType(Arrays.asList(new TsParameter("data", returnGenericVariable)), returnGenericVariable))), optionsType != null ? new TsProperty("options", new TsType.OptionalType(optionsType)) : null))), new TsType.GenericReferenceType(responseSymbol, returnGenericVariable), null, null)), null));
// application client classes
final TsType.ReferenceType httpClientType = optionsGenericVariable != null ? new TsType.GenericReferenceType(httpClientSymbol, optionsGenericVariable) : new TsType.ReferenceType(httpClientSymbol);
final TsConstructorModel constructor = new TsConstructorModel(TsModifierFlags.None, Arrays.asList(new TsParameterModel(TsAccessibilityModifier.Protected, "httpClient", httpClientType)), Collections.<TsStatement>emptyList(), null);
final boolean bothInterfacesAndClients = settings.generateJaxrsApplicationInterface || settings.generateSpringApplicationInterface;
final String groupingSuffix = bothInterfacesAndClients ? null : "Client";
final Map<Symbol, List<TsMethodModel>> groupedMethods = processRestMethods(tsModel, restApplications, symbolTable, groupingSuffix, responseSymbol, optionsType, true);
for (Map.Entry<Symbol, List<TsMethodModel>> entry : groupedMethods.entrySet()) {
final Symbol symbol = bothInterfacesAndClients ? symbolTable.addSuffixToSymbol(entry.getKey(), "Client") : entry.getKey();
final TsType interfaceType = bothInterfacesAndClients ? new TsType.ReferenceType(entry.getKey()) : null;
final TsBeanModel clientModel = new TsBeanModel(null, TsBeanCategory.Service, true, symbol, typeParameters, null, null, Utils.listFromNullable(interfaceType), null, constructor, entry.getValue(), null);
tsModel.getBeans().add(clientModel);
}
// helper
tsModel.getHelpers().add(TsHelper.loadFromResource("/helpers/uriEncoding.ts"));
}
use of cz.habarta.typescript.generator.TsParameter in project typescript-generator by vojtechhabarta.
the class JsonDeserializationExtension method createDeserializationGenericFunctionConstructor.
private static TsMethodModel createDeserializationGenericFunctionConstructor(SymbolTable symbolTable, TsModel tsModel, TsBeanModel bean) {
final Symbol beanIdentifier = symbolTable.getSymbol(bean.getOrigin());
List<TsType.GenericVariableType> typeParameters = getTypeParameters(bean.getOrigin());
final TsType.ReferenceType dataType = new TsType.GenericReferenceType(beanIdentifier, typeParameters);
final List<TsParameterModel> constructorFnOfParameters = getConstructorFnOfParameters(typeParameters);
final List<TsExpression> arguments = new ArrayList<>();
arguments.add(new TsIdentifierReference("data"));
for (TsParameterModel constructorFnOfParameter : constructorFnOfParameters) {
arguments.add(new TsIdentifierReference(constructorFnOfParameter.name));
}
final List<TsStatement> body = new ArrayList<>();
body.add(new TsReturnStatement(new TsArrowFunction(Arrays.asList(new TsParameter("data", null)), new TsCallExpression(new TsMemberExpression(new TsTypeReferenceExpression(new TsType.ReferenceType(beanIdentifier)), "fromData"), null, arguments))));
return new TsMethodModel("fromDataFn", TsModifierFlags.None.setStatic(), typeParameters, constructorFnOfParameters, new TsType.FunctionType(Arrays.asList(new TsParameter("data", dataType)), dataType), body, null);
}
use of cz.habarta.typescript.generator.TsParameter in project typescript-generator by vojtechhabarta.
the class Emitter method formatParameterList.
public static String formatParameterList(List<TsParameter> parameters) {
final List<String> params = new ArrayList<>();
for (TsParameter parameter : parameters) {
params.add(formatParameterNameAndType(parameter));
}
final boolean parentheses = parameters.size() != 1 || parameters.get(0).tsType != null;
return joinParameters(params, parentheses);
}
Aggregations