Exemplo n.º 1
0
        public static HashSet <string> PropertyImports(PropertyJvaf property, string innerModelPackage)
        {
            HashSet <string> imports = new HashSet <string>();
            var propertyImports      = property.Imports;
            // var propertyImports = property.Imports.Where(import => !import.EqualsIgnoreCase(thisPackage));
            //
            string modelTypeName = property.ModelTypeName;

            if (property.ModelType is SequenceTypeJva)
            {
                var modelType = property.ModelType;
                while (modelType is SequenceTypeJva)
                {
                    SequenceTypeJva sequenceType = (SequenceTypeJva)modelType;
                    modelType = sequenceType.ElementType;
                }
                modelTypeName = modelType.ClassName;
            }
            if (modelTypeName.EndsWith("Inner"))
            {
                imports.Add($"{innerModelPackage}.{modelTypeName}");
            }
            imports.AddRange(propertyImports);
            return(imports);
        }
Exemplo n.º 2
0
        public static IEnumerable <string> PropertyImportsForInterface(PropertyJvaf property, string package)
        {
            foreach (string import in property.Imports)
            {
                if (import.StartsWith(package) && !import.Contains(".implementation."))
                {
                    continue;
                }
                yield return(import);
            }
            //
            string modelTypeName = property.ModelTypeName;

            if (property.ModelType is SequenceTypeJva)
            {
                var modelType = property.ModelType;
                while (modelType is SequenceTypeJva)
                {
                    SequenceTypeJva sequenceType = (SequenceTypeJva)modelType;
                    modelType = sequenceType.ElementType;
                }
                modelTypeName = modelType.ClassName;
            }
            //
            if (modelTypeName.EndsWith("Inner"))
            {
                yield return($"{package}.implementation.{modelTypeName}");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Changes paginated method signatures to return Page type.
        /// </summary>
        /// <param name="serviceClient"></param>
        /// <param name="pageClasses"></param>
        public void NormalizePaginatedMethods(CodeModel serviceClient, IDictionary <KeyValuePair <string, string>, string> pageClasses)
        {
            if (serviceClient == null)
            {
                throw new ArgumentNullException("serviceClient");
            }

            var convertedTypes = new Dictionary <IModelType, IModelType>();

            foreach (MethodJva method in serviceClient.Methods.Where(m => m.Extensions.ContainsKey(AzureExtensions.PageableExtension)))
            {
                string nextLinkString;
                string pageClassName = GetPagingSetting(method.Extensions, pageClasses, out nextLinkString);
                if (string.IsNullOrEmpty(pageClassName))
                {
                    continue;
                }
                if (string.IsNullOrEmpty(nextLinkString))
                {
                    method.Extensions[AzureExtensions.PageableExtension] = null;
                }

                foreach (var responseStatus in method.Responses.Where(r => r.Value.Body is CompositeTypeJva).Select(s => s.Key).ToArray())
                {
                    var compositType = (CompositeTypeJva)method.Responses[responseStatus].Body;
                    var sequenceType = compositType.Properties.Select(p => p.ModelType).FirstOrDefault(t => t is SequenceTypeJva) as SequenceTypeJva;

                    // if the type is a wrapper over page-able response
                    if (sequenceType != null)
                    {
                        IModelType pagedResult;
                        pagedResult = new SequenceTypeJva
                        {
                            ElementType  = sequenceType.ElementType,
                            PageImplType = pageClassName
                        };

                        convertedTypes[method.Responses[responseStatus].Body] = pagedResult;
                        var resp = New <Response>(pagedResult, method.Responses[responseStatus].Headers) as ResponseJva;
                        resp.Parent = method;
                        method.Responses[responseStatus] = resp;
                    }
                }

                if (convertedTypes.ContainsKey(method.ReturnType.Body))
                {
                    var resp = New <Response>(convertedTypes[method.ReturnType.Body], method.ReturnType.Headers) as ResponseJva;
                    resp.Parent       = method;
                    method.ReturnType = resp;
                }
            }

            SwaggerExtensions.RemoveUnreferencedTypes(serviceClient, new HashSet <string>(convertedTypes.Keys.Cast <CompositeTypeJva>().Select(t => t.Name.ToString())));
        }