/// <summary>Gets the enum default value.</summary>
        /// <param name="schema">The schema.</param>
        /// <param name="actualSchema">The actual schema.</param>
        /// <param name="typeNameHint">The type name hint.</param>
        /// <param name="typeResolver">The type resolver.</param>
        /// <returns>The enum default value.</returns>
        protected virtual string GetEnumDefaultValue(JsonSchema schema, JsonSchema actualSchema, string typeNameHint, TypeResolverBase typeResolver)
        {
            var typeName = typeResolver.Resolve(actualSchema, false, typeNameHint);

            var index    = actualSchema.Enumeration.ToList().IndexOf(schema.Default);
            var enumName = index >= 0 && actualSchema.EnumerationNames?.Count > index
                ? actualSchema.EnumerationNames.ElementAt(index)
                : schema.Default.ToString();

            return(typeName.Trim('?') + "." + _settings.EnumNameGenerator.Generate(index, enumName, schema.Default, actualSchema));
        }
Exemple #2
0
 /// <summary>Generates the type from the schema and all types from the resolver.</summary>
 /// <param name="schema">The schema</param>
 /// <param name="typeNameHint">The type name hint.</param>
 /// <returns>The code.</returns>
 public IEnumerable <CodeArtifact> GenerateTypes(JsonSchema schema, string typeNameHint)
 {
     _resolver.Resolve(schema, false, typeNameHint); // register root type
     return(GenerateTypes());
 }
 /// <summary>Generates the type from the schema and all types from the resolver.</summary>
 /// <param name="schema">The schema</param>
 /// <param name="typeNameHint">The type name hint.</param>
 /// <returns>The code.</returns>
 public CodeArtifactCollection GenerateTypes(JsonSchema4 schema, string typeNameHint)
 {
     _resolver.Resolve(schema, false, typeNameHint); // register root type
     return(GenerateTypes());
 }