Exemplo n.º 1
0
        private static IOpenApiAny ToOpenApiAny(Type type, object instance)
        {
            var arrayResult = ToOpenApiArray(type, instance);

            if (arrayResult != null)
            {
                return(arrayResult);
            }
            var result = new OpenApiObject();

            foreach (var property in type.GetRuntimeProperties())
            {
                var value = property.GetValue(instance);

                if (value != null)
                {
                    var openValue = GetStructValue(property.PropertyType, value);
                    var key       = char.ToLower(property.Name[0]) + property.Name.Substring(1);

                    if (openValue != null)
                    {
                        if (result.ContainsKey(key))
                        {
                            result[key] = openValue;
                        }
                        else
                        {
                            result.Add(key, openValue);
                        }
                        continue;
                    }

                    var array = default(OpenApiArray);
                    if ((array = ToOpenApiArray(property.PropertyType, value)) != null)
                    {
                        if (result.ContainsKey(key))
                        {
                            result[key] = array;
                        }
                        else
                        {
                            result.Add(key, array);
                        }
                        continue;
                    }
                    var openObject = ToOpenApiAny(property.PropertyType, value);
                    if (result.ContainsKey(key))
                    {
                        result[key] = openObject;
                    }
                    else
                    {
                        result.Add(key, openObject);
                    }
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        private void PatchFieldTexts(OpenApiObject templateOptions, PropertyInfo propertyInfo, Type declaringType,
                                     FormlyFieldAttribute fieldAttr)
        {
            if (!templateOptions.ContainsKey("label"))
            {
                var label = fieldAttr?.GetDisplayName(propertyInfo) ??
                            TypeHelpers.GetDisplayNameOrDefault(propertyInfo);
                templateOptions["label"] = Oas(label);
            }

            if (!templateOptions.ContainsKey("description"))
            {
                var desc = TypeHelpers.GetDescription(propertyInfo);
                if (!string.IsNullOrEmpty(desc))
                {
                    templateOptions["description"] = Oas(desc);
                }
            }
        }
Exemplo n.º 3
0
        private void RewriteJrpcAttributesExamples(OpenApiSchema schema, SchemaRepository schemaRepository, string method = "method_name")
        {
            var jrpcAttributesExample =
                new OpenApiObject()
            {
                { "id", new OpenApiString(Guid.NewGuid().ToString()) },
                { "jsonrpc", new OpenApiString("2.0") },
                { "method", new OpenApiString(method) },
            };

            foreach (var prop in schemaRepository.Schemas[schema.Reference.Id].Properties)
            {
                if (jrpcAttributesExample.ContainsKey(prop.Key))
                {
                    prop.Value.Example = jrpcAttributesExample[prop.Key];
                }
            }
        }