Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
 protected override OpenApiSchema GenerateDefinitionSchema(ApiModel apiModel, SchemaRepository schemaRepository)
 {
     return(new OpenApiSchema {
         Type = "string"
     });
 }
Ejemplo n.º 3
0
 protected override bool CanGenerateSchema(ApiModel apiModel, out bool shouldBeReferenced)
 {
     shouldBeReferenced = false;
     return(true);
 }
Ejemplo n.º 4
0
 protected abstract OpenApiSchema GenerateDefinitionSchema(ApiModel apiModel, SchemaRepository schemaRepository);
Ejemplo n.º 5
0
 protected abstract bool CanGenerateSchema(ApiModel apiModel, out bool shouldBeReferenced);