public virtual void GenerateModelDefinition(TSBuilder builder)
        {
            builder.DocumentationComment(comment =>
            {
                comment.Summary(Summary);
                comment.Description(Documentation);
            });
            ISet <string> addedPropertyNames = new HashSet <string>();

            builder.ExportInterface(Name, BaseModelType?.Name?.ToString(), tsInterface =>
            {
                foreach (Property property in Properties.Where(p => !p.IsConstant))
                {
                    if (!addedPropertyNames.Contains(property.Name))
                    {
                        addedPropertyNames.Add(property.Name);

                        tsInterface.DocumentationComment(comment =>
                        {
                            comment.Summary(property.Summary);
                            comment.Description(property.Documentation);
                        });
                        string propertyType = property.ModelType.TSType(inModelsModule: true);
                        tsInterface.Property(property.Name, propertyType, isRequired: property.IsRequired, isReadonly: property.IsReadOnly);
                    }
                }

                if (AdditionalProperties != null)
                {
                    tsInterface.DocumentationComment(AdditionalPropertiesDocumentation());
                    tsInterface.Indexer("additionalPropertyName", AdditionalPropertiesTSType());
                }
            });
        }
        public override void GenerateModelDefinition(TSBuilder builder)
        {
            builder.DocumentationComment(comment =>
            {
                comment.Summary(Summary);
                comment.Description(Documentation);
            });

            IModelType arrayType;
            Property   arrayProperty = Properties.FirstOrDefault(p => p.ModelType is SequenceTypeJs);

            if (arrayProperty == null)
            {
                throw new Exception($"The Pageable model {Name} does not contain a single property that is an Array.");
            }
            else
            {
                arrayType = ((SequenceTypeJs)arrayProperty.ModelType).ElementType;
            }

            builder.ExportInterface(Name, $"Array<{ClientModelExtensions.TSType(arrayType, true)}>", tsInterface =>
            {
                Property nextLinkProperty = Properties.Where(p => p.Name.ToLowerInvariant().Contains("nextlink")).FirstOrDefault();
                if (nextLinkProperty != null)
                {
                    tsInterface.DocumentationComment(comment =>
                    {
                        comment.Summary(nextLinkProperty.Summary);
                        comment.Description(nextLinkProperty.Documentation);
                    });
                    string propertyType = nextLinkProperty.ModelType.TSType(inModelsModule: true);
                    tsInterface.Property(nextLinkProperty.Name, propertyType, isRequired: nextLinkProperty.IsRequired, isReadonly: nextLinkProperty.IsReadOnly);
                }
            });
        }
示例#3
0
        public override string Generate()
        {
            TSBuilder builder = new TSBuilder();

            builder.DocumentationComment(comment =>
            {
                comment.Interface();
                string description = Documentation;
                if (string.IsNullOrEmpty(description))
                {
                    description = $"An interface representing the {Name}.";
                }
                comment.Description(description);
                comment.Summary(Summary);
                comment.Extends($"Array{ConstructTSItemTypeName()}");
            });
            builder.ExportInterface(Name, $"Array{ConstructTSItemTypeName()}", tsInterface =>
            {
                foreach (Property property in InterfaceProperties)
                {
                    if (!(property.Name.ToLowerInvariant() == "value" || property.Name.ToLowerInvariant() == "values"))
                    {
                        tsInterface.DocumentationComment(property.Documentation);
                        string propertyType = property.IsPolymorphicDiscriminator ? $"\"{SerializedName}\"" : property.ModelType.TSType(true);
                        bool isReadonly     = property.IsReadOnly;
                        bool isOptional     = !property.IsRequired && (!(CodeModel?.HeaderTypes.Contains(this) == true) || CodeModelTS.Settings.OptionalResponseHeaders);
                        tsInterface.Property(property.Name, propertyType, optional: isOptional, isReadonly: isReadonly);
                    }
                }
            });

            return(builder.ToString());
        }
        public virtual string Generate()
        {
            TSBuilder builder = new TSBuilder();

            if (ImmediatePolymorphicSubtypes.Any())
            {
                builder.DocumentationComment($"Contains the possible cases for {Name}.");
                List <string> unionTypeValues = new List <string>()
                {
                    Name
                };
                unionTypeValues.AddRange(ImmediatePolymorphicSubtypes.Select(m => m.UnionTypeName));
                builder.ExportUnionType($"{Name}Union", unionTypeValues);
                builder.Line();
            }

            builder.DocumentationComment(comment =>
            {
                string description = Documentation;
                if (string.IsNullOrEmpty(description))
                {
                    description = $"An interface representing {Name}.";
                }
                comment.Description(description);
                comment.Summary(Summary);
            });
            string baseTypeName = null;

            if (BaseModelType != null && !BaseIsPolymorphic)
            {
                baseTypeName = BaseModelType.Name;
                if (baseTypeName == "RequestOptionsBase")
                {
                    // baseTypeName = $"coreHttp.{baseTypeName}";
                    baseTypeName = null;
                }
            }
            builder.ExportInterface(Name, baseTypeName, tsInterface =>
            {
                ISet <string> addedPropertyNames = new HashSet <string>();

                foreach (Property property in InterfaceProperties)
                {
                    string propertyName = property.Name;
                    if (!addedPropertyNames.Contains(propertyName))
                    {
                        addedPropertyNames.Add(propertyName);

                        string propertyDescription = $"{property.Summary.EnsureEndsWith(".")} {property.Documentation}".Trim();
                        if (!property.DefaultValue.IsNullOrEmpty())
                        {
                            propertyDescription = $"{propertyDescription.EnsureEndsWith(".")} Default value: {property.DefaultValue}.".Trim();
                        }
                        tsInterface.DocumentationComment(propertyDescription);

                        string propertyType = property.IsPolymorphicDiscriminator ? $"\"{SerializedName}\"" : property.ModelType.TSType(true);
                        bool isReadonly     = property.IsReadOnly;
                        bool isOptional     = !property.IsRequired && (!(CodeModel?.HeaderTypes.Contains(this) == true) || CodeModelTS.Settings.OptionalResponseHeaders);
                        bool isNullable     = property.IsXNullable ?? false;
                        tsInterface.Property(property.Name, propertyType, optional: isOptional, isReadonly: isReadonly, isNullable: isNullable);
                    }
                }

                if (AdditionalProperties != null)
                {
                    tsInterface.DocumentationComment(AdditionalPropertiesDocumentation());
                    tsInterface.Property("[property: string]", AdditionalPropertiesTSType());
                }
            });

            return(builder.ToString());
        }