예제 #1
0
        /// <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(JsonSchema4 schema, JsonSchema4 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 + "." + _settings.EnumNameGenerator.Generate(index, enumName, schema.Default, actualSchema));
        }
 /// <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());
 }