Beispiel #1
0
        private (string Key, OpenApiSchema Value) ReadType(Type type)
        {
            var properties = type.GetProperties();
            var schema     = new OpenApiSchema()
            {
                Type = TypeIdentifier.Object
            };

            foreach (var property in properties)
            {
                string name = NameToCamelCase(property);

                if (IsRequired(property))
                {
                    schema.Required.Add(name);
                }

                var(propType, format) = TypeIdentifier.Id(property.PropertyType);

                if (propType == TypeIdentifier.Object)
                {
                    BuildObjectSchema(schema, property, name);
                }
                else if (propType == TypeIdentifier.Array)
                {
                    BuildArraySchema(schema, property, name);
                }
                else
                {
                    BuildPropertySchema(schema, name, propType, format);
                }
            }

            return(TypeIdentifier.Name(type), schema);
        }
Beispiel #2
0
        public ResponseBuilder AddJsonContent <T>()
        {
            var reference = new OpenApiReference();

            var inputType = typeof(T);

            reference.Id = TypeIdentifier.Name(inputType);

            _result.Content.Add("application/json", new OpenApiMediaType()
            {
                Schema = new OpenApiSchema()
                {
                    Reference = reference
                }
            });
            return(this);
        }