Exemple #1
0
        protected override OpenApiSchema GenerateDefinitionSchema(ApiModel apiModel, SchemaRepository schemaRepository)
        {
            var apiObject = (ApiObject)apiModel;

            var additionalProperties = (apiObject.AdditionalPropertiesType != null)
                ? Generator.GenerateSchema(apiObject.AdditionalPropertiesType, schemaRepository)
                : null;

            var schema = new OpenApiSchema
            {
                Type       = "object",
                Properties = new Dictionary <string, OpenApiSchema>(),
                Required   = new SortedSet <string>(),
                AdditionalPropertiesAllowed = (additionalProperties != null),
                AdditionalProperties        = additionalProperties
            };

            foreach (var apiProperty in apiObject.ApiProperties)
            {
                // For data annotations, support inline attributes (i.e. applied to member directly) OR attributes applied through a MetadataType
                var propertyAttributes = (apiProperty.MemberInfo is PropertyInfo propertyInfo)
                    ? propertyInfo.GetInlineOrMetadataTypeAttributes()
                    : Enumerable.Empty <object>();

                if (Options.IgnoreObsoleteProperties && propertyAttributes.OfType <ObsoleteAttribute>().Any())
                {
                    continue;
                }

                schema.Properties.Add(apiProperty.ApiName, GeneratePropertySchema(apiProperty, propertyAttributes, schemaRepository));

                if (apiProperty.ApiRequired || propertyAttributes.OfType <RequiredAttribute>().Any())
                {
                    schema.Required.Add(apiProperty.ApiName);
                }
            }

            return(schema);
        }
Exemple #2
0
 protected override OpenApiSchema GenerateDefinitionSchema(ApiModel apiModel, SchemaRepository schemaRepository)
 {
     return(new OpenApiSchema {
         Type = "string"
     });
 }
Exemple #3
0
 protected override bool CanGenerateSchema(ApiModel apiModel, out bool shouldBeReferenced)
 {
     shouldBeReferenced = false;
     return(true);
 }
Exemple #4
0
 protected abstract OpenApiSchema GenerateDefinitionSchema(ApiModel apiModel, SchemaRepository schemaRepository);
Exemple #5
0
 protected abstract bool CanGenerateSchema(ApiModel apiModel, out bool shouldBeReferenced);