/// <summary> /// Remove DTO fields that should be ignored. /// </summary> public static void RemoveDtoFieldsToIgnore(CodeGenerationContext context) { var fieldsToIgnore = new Dictionary <string, HashSet <string> >(StringComparer.OrdinalIgnoreCase) { { "TD_MemberProfile", new HashSet <string>(StringComparer.OrdinalIgnoreCase) { "logins" } } }; // Remove fields to ignore foreach (var apiDto in context.GetDtos()) { if (fieldsToIgnore.TryGetValue(apiDto.Name, out var ignoreFields)) { apiDto.Fields.RemoveAll(it => ignoreFields.Contains(it.Field.Name)); } } }
private static void AddRequestBodyTypesToDtos(CodeGenerationContext context, IEnumerable <ApiResource> resources, string parentResourcePath) { foreach (var apiResource in resources) { var resourcePath = (parentResourcePath.Length > 0 ? parentResourcePath + "/" + apiResource.Path.Segments.ToPath() : apiResource.Path.Segments.ToPath()).TrimEnd('/'); foreach (var apiEndpoint in apiResource.Endpoints) { if (apiEndpoint.RequestBody != null && apiEndpoint.RequestBody.Kind == ApiFieldType.Object.ObjectKind.REQUEST_BODY) { // Endpoint path var endpointPath = (resourcePath + "/" + apiEndpoint.Path.Segments.ToPath()).TrimEnd('/'); // Expected class name var typeNameForRequestBody = apiEndpoint.ToCSharpRequestBodyClassName(endpointPath) !; var classIdForRequestBody = typeNameForRequestBody.ToLowerInvariant(); // See if we have seen the anonymous class before (and if not, add it) if (!context.TryGetDto(classIdForRequestBody, out var requestBodyClass)) { requestBodyClass = new ApiDto { Id = classIdForRequestBody, Name = typeNameForRequestBody, Fields = apiEndpoint.RequestBody.Fields.Select(it => new ApiDtoField { Field = it }).ToList() }; context.AddDto(classIdForRequestBody, requestBodyClass); } } } AddRequestBodyTypesToDtos(context, apiResource.NestedResources, resourcePath); } }
private MethodParametersBuilder(CodeGenerationContext context, List <MethodParameter> parameters) { _context = context; _parameters = parameters; }
public MethodParametersBuilder(CodeGenerationContext context) : this(context, new List <MethodParameter>()) { }
private QueryStringParameterConversionGenerator(string targetNameValueCollectionName, CodeGenerationContext context, List <QueryStringParameterConversion> conversions) { TargetNameValueCollectionName = targetNameValueCollectionName; _context = context; _conversions = conversions; }
public QueryStringParameterConversionGenerator(string targetNameValueCollectionName, CodeGenerationContext context) : this(targetNameValueCollectionName, context, new List <QueryStringParameterConversion>()) { }
/// <summary> /// Add resource request body types to DTO collection, so they can be resolved as such. /// </summary> public static void AddRequestBodyTypesToDtos(CodeGenerationContext context) => AddRequestBodyTypesToDtos(context, context.ApiModel.Resources, string.Empty);