private void ApplyParameterMetadata(
            OpenApiSchema schema,
            SchemaRepository schemaRepository,
            DataContract dataContract,
            Type type,
            ParameterInfo parameterInfo)
        {
            if (schema.Reference == null)
            {
                schema.Nullable = type.IsReferenceOrNullableType();

                if (parameterInfo.HasDefaultValue)
                {
                    var enumValues = dataContract.EnumValues;

                    var defaultValue = (enumValues != null && enumValues.TryGetValue(parameterInfo.DefaultValue, out object convertedEnumValue))
                        ? convertedEnumValue
                        : parameterInfo.DefaultValue;

                    schema.Default = OpenApiAnyFactory.CreateFor(schema, defaultValue, schemaRepository);
                }

                schema.ApplyCustomAttributes(parameterInfo.GetCustomAttributes());
            }
        }
        private void ApplyMemberMetadata(
            OpenApiSchema schema,
            SchemaRepository schemaRepository,
            DataContract dataContract,
            Type type,
            MemberInfo memberInfo)
        {
            if (schema.Reference == null)
            {
                schema.Nullable = type.IsReferenceOrNullableType();

                var customAttributes      = memberInfo.GetInlineAndMetadataAttributes();
                var defaultValueAttribute = customAttributes.OfType <DefaultValueAttribute>().FirstOrDefault();

                if (defaultValueAttribute != null)
                {
                    var enumValues = dataContract.EnumValues;

                    var defaultValue = (enumValues != null && enumValues.TryGetValue(defaultValueAttribute.Value, out object convertedEnumValue))
                        ? convertedEnumValue
                        : defaultValueAttribute.Value;

                    schema.Default = OpenApiAnyFactory.CreateFor(schema, defaultValue, schemaRepository);
                }

                schema.ApplyCustomAttributes(customAttributes);
            }
        }
Esempio n. 3
0
        private void ApplyMemberMetadata(OpenApiSchema schema, Type type, MemberInfo memberInfo)
        {
            if (schema.Reference != null && _generatorOptions.UseAllOfToExtendReferenceSchemas)
            {
                schema.AllOf = new[] { new OpenApiSchema {
                                           Reference = schema.Reference
                                       } };
                schema.Reference = null;
            }

            if (schema.Reference == null)
            {
                schema.Nullable = type.IsReferenceOrNullableType();

                schema.ApplyCustomAttributes(memberInfo.GetInlineOrMetadataTypeAttributes());
            }
        }
        private void ApplyParameterMetadata(OpenApiSchema schema, Type type, ParameterInfo parameterInfo)
        {
            if (schema.Reference != null && _generatorOptions.UseAllOfToExtendReferenceSchemas)
            {
                schema.AllOf = new[] { new OpenApiSchema {
                                           Reference = schema.Reference
                                       } };
                schema.Reference = null;
            }

            if (schema.Reference == null)
            {
                schema.Nullable = type.IsReferenceOrNullableType();

                schema.ApplyCustomAttributes(parameterInfo.GetCustomAttributes());

                if (parameterInfo.HasDefaultValue)
                {
                    schema.Default = OpenApiAnyFactory.CreateFor(schema, parameterInfo.DefaultValue);
                }
            }
        }
        private void ApplyMemberMetadata(OpenApiSchema schema, Type type, MemberInfo memberInfo)
        {
            if (schema.Reference != null && _generatorOptions.UseAllOfToExtendReferenceSchemas)
            {
                schema.AllOf = new[] { new OpenApiSchema {
                                           Reference = schema.Reference
                                       } };
                schema.Reference = null;
            }

            if (schema.Reference == null)
            {
                schema.Nullable = type.IsReferenceOrNullableType();

                schema.ApplyCustomAttributes(memberInfo.GetInlineOrMetadataTypeAttributes());

                if (memberInfo is PropertyInfo propertyInfo)
                {
                    schema.ReadOnly  = (propertyInfo.IsPubliclyReadable() && !propertyInfo.IsPubliclyWritable());
                    schema.WriteOnly = (!propertyInfo.IsPubliclyReadable() && propertyInfo.IsPubliclyWritable());
                }
            }
        }