/// <summary>
        /// Returns the TypeScript string to define the specified property, including its type and whether it's optional or not
        /// </summary>
        /// <param name="property">Model property to query</param>
        /// <param name="inModelsModule">Pass true if generating the code for the models module, thus model types don't need a "models." prefix</param>
        /// <returns>TypeScript property definition</returns>
        public string PropertyTS(Core.Model.Property property, bool inModelsModule)
        {
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            var propertyName = property.Name;

            if (property.IsPolymorphicDiscriminator)
            {
                return($"{propertyName}: \"{SerializedName}\"");
            }

            string typeString = property.ModelType.TSType(inModelsModule);

            if (property.IsReadOnly)
            {
                propertyName = "readonly " + propertyName;
            }

            bool isHeaders  = CodeModel?.HeaderTypes.Contains(this) == true;
            bool isOptional = !property.IsRequired && (!isHeaders || CodeModelTS.Settings.OptionalResponseHeaders);

            if (isOptional)
            {
                return(propertyName + "?: " + typeString);
            }
            else
            {
                return(propertyName + ": " + typeString);
            }
        }
        /// <summary>
        /// Returns the TypeScript string to define the specified property, including its type and whether it's optional or not
        /// </summary>
        /// <param name="property">Model property to query</param>
        /// <param name="inModelsModule">Pass true if generating the code for the models module, thus model types don't need a "models." prefix</param>
        /// <returns>TypeScript property definition</returns>
        public string PropertyTS(Core.Model.Property property, bool inModelsModule)
        {
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            var propertyName = property.Name;

            if (property.IsPolymorphicDiscriminator)
            {
                return($"{propertyName}: \"{SerializedName}\"");
            }

            string typeString = property.ModelType.TSType(inModelsModule);

            if (property.IsReadOnly)
            {
                propertyName = "readonly " + propertyName;
            }
            if (!property.IsRequired)
            {
                return(propertyName + "?: " + typeString);
            }
            else
            {
                return(propertyName + ": " + typeString);
            }
        }
Example #3
0
 public bool ContainsDurationProperty()
 {
     Core.Model.Property prop = Properties.FirstOrDefault(p =>
                                                          (p.ModelType is PrimaryTypeJs && (p.ModelType as PrimaryTypeJs).KnownPrimaryType == KnownPrimaryType.TimeSpan) ||
                                                          (p.ModelType is Core.Model.SequenceType && (p.ModelType as Core.Model.SequenceType).ElementType.IsPrimaryType(KnownPrimaryType.TimeSpan)) ||
                                                          (p.ModelType is Core.Model.DictionaryType && (p.ModelType as Core.Model.DictionaryType).ValueType.IsPrimaryType(KnownPrimaryType.TimeSpan)));
     return(prop != null);
 }
        /// <summary>
        /// Provides the property name in the correct jsdoc notation depending on
        /// whether it is required or optional
        /// </summary>
        /// <param name="property">Parameter to be documented</param>
        /// <returns>Parameter name in the correct jsdoc notation</returns>
        public static string GetPropertyDocumentationName(Core.Model.Property property)
        {
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            return(property.IsRequired ? (string)property.Name : $"[{property.Name}]");
        }
        /// <summary>
        /// Provides the property documentation string along with default value if any.
        /// </summary>
        /// <param name="property">Parameter to be documented</param>
        /// <returns>Parameter documentation string along with default value if any
        /// in correct jsdoc notation</returns>
        public static string GetPropertyDocumentationString(Core.Model.Property property)
        {
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            return(property.DefaultValue.IsNullOrEmpty() ?
                   $"{property.Summary.EnsureEndsWith(".")} {property.Documentation}".Trim() :
                   $"{property.Summary.EnsureEndsWith(".")} {property.Documentation.EnsureEndsWith(".")} Default value: {property.DefaultValue} .".Trim());
        }
Example #6
0
        /// <summary>
        /// Returns the TypeScript string to define the specified property, including its type and whether it's optional or not
        /// </summary>
        /// <param name="property">Model property to query</param>
        /// <param name="inModelsModule">Pass true if generating the code for the models module, thus model types don't need a "models." prefix</param>
        /// <returns>TypeScript property definition</returns>
        public static string PropertyTS(Core.Model.Property property, bool inModelsModule)
        {
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            string typeString = property.ModelType.TSType(inModelsModule);

            if (!property.IsRequired)
            {
                return(property.Name + "?: " + typeString);
            }
            else
            {
                return(property.Name + ": " + typeString);
            }
        }
        public static string GetPropertyDocumentationType(Core.Model.Property property)
        {
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }
            string typeName = "object";

            if (property.ModelType is PrimaryTypeTS)
            {
                typeName = property.ModelType.Name;
            }
            else if (property.ModelType is Core.Model.SequenceType)
            {
                typeName = "array";
            }
            else if (property.ModelType is EnumType)
            {
                typeName = "string";
            }

            return(typeName.ToLowerInvariant());
        }