Exemplo n.º 1
0
        private Schema CreateObjectSchema(JsonObjectContract jsonContract)
        {
            var properties = jsonContract.Properties
                             .Where(p => !p.Ignored)
                             .Where(p => !(_options.IgnoreObsoleteProperties && p.IsObsolete()))
                             .ToDictionary(
                prop => prop.PropertyName,
                prop => CreateSchema(prop.PropertyType, true).AssignValidationProperties(prop)
                );

            var required = jsonContract.Properties.Where(prop => prop.IsRequired())
                           .Select(propInfo => propInfo.PropertyName)
                           .ToList();

            var schema = new Schema
            {
                Required   = required.Any() ? required : null, // required can be null but not empty
                Properties = properties,
                Type       = "object"
            };

            var filterContext = new ModelFilterContext(
                jsonContract.UnderlyingType,
                jsonContract,
                this);

            foreach (var filter in _options.ModelFilters)
            {
                filter.Apply(schema, filterContext);
            }

            return(schema);
        }
Exemplo n.º 2
0
 public void Apply(Schema model, ModelFilterContext context)
 {
     model.Default = new
     {
         Id = "myCartId"
     };
 }
Exemplo n.º 3
0
        private Schema CreateObjectSchema(JsonObjectContract jsonContract)
        {
            var properties = jsonContract.Properties
                             .Where(p => !p.Ignored)
                             .Where(p => !(_ignoreObsoleteProperties && p.IsObsolete()))
                             .Where(p => !p.IsSwaggerIgnore())
                             .ToDictionary(
                prop => prop.PropertyName,
                prop => CreateInlineSchema(prop.PropertyType).WithValidationProperties(prop)
                );

            var required = jsonContract.Properties.Where(prop => prop.IsRequired())
                           .Select(propInfo => propInfo.PropertyName)
                           .ToList();

            var requiredConditionally = jsonContract.Properties.Where(prop => prop.IsRequiredConditionally())
                                        .Select(propInfo => propInfo.PropertyName)
                                        .ToList();

            var schema = new Schema
            {
                required = required.Any() ? required : null,                                        // required can be null but not empty
                requiredConditionally = requiredConditionally.Any() ? requiredConditionally : null, // required can be null but not empty
                properties            = properties,
                type = "object"
            };

            foreach (var filter in _schemaFilters)
            {
                filter.Apply(schema, this, jsonContract.UnderlyingType);
            }

            // NOTE: In next major version, _modelFilters will completely replace _schemaFilters
            var modelFilterContext = new ModelFilterContext(jsonContract.UnderlyingType, jsonContract, this);

            foreach (var filter in _modelFilters)
            {
                filter.Apply(schema, modelFilterContext);
            }

            return(schema);
        }
Exemplo n.º 4
0
 private Schema FilterSchema(Schema schema, JsonContract jsonContract)
 {
     if (schema.type == "object" || this._applyFiltersToAllSchemas)
     {
         JsonObjectContract jsonObjectContract = jsonContract as JsonObjectContract;
         if (jsonObjectContract != null)
         {
             ModelFilterContext context = new ModelFilterContext(((JsonContract)jsonObjectContract).get_UnderlyingType(), jsonObjectContract, this);
             foreach (IModelFilter modelFilter in this._modelFilters)
             {
                 modelFilter.Apply(schema, context);
             }
         }
         foreach (ISchemaFilter schemaFilter in this._schemaFilters)
         {
             schemaFilter.Apply(schema, this, jsonContract.get_UnderlyingType());
         }
     }
     return(schema);
 }
Exemplo n.º 5
0
        public void Apply(Schema model, ModelFilterContext context)
        {
            var typeNode = _navigator.SelectSingleNode(
                String.Format(TypeExpression, context.SystemType.XmlLookupName()));

            if (typeNode != null)
            {
                var summaryNode = this.GetSummaryNode(typeNode);
                if (summaryNode != null)
                    model.description = summaryNode.ExtractContent();
            }

            foreach (var entry in model.properties)
            {
                var jsonProperty = context.JsonObjectContract.Properties[entry.Key];
                if (jsonProperty == null) continue;

                ApplyPropertyComments(entry.Value, jsonProperty.PropertyInfo());
            }
        }
Exemplo n.º 6
0
        public void Apply(Schema model, ModelFilterContext context)
        {
            var commentId = XmlCommentsIdHelper.GetCommentIdForType(context.SystemType);
            var typeNode = _navigator.SelectSingleNode(string.Format(MemberXPath, commentId));

            if (typeNode != null)
            {
                var summaryNode = typeNode.SelectSingleNode(SummaryTag);
                if (summaryNode != null)
                    model.description = summaryNode.ExtractContent();
            }

            foreach (var entry in model.properties)
            {
                var jsonProperty = context.JsonObjectContract.Properties[entry.Key];
                if (jsonProperty == null) continue;

                ApplyPropertyComments(entry.Value, jsonProperty.PropertyInfo());
            }
        }
Exemplo n.º 7
0
        private Schema FilterSchema(Schema schema, JsonContract jsonContract)
        {
            if (schema.type == "object" || _applyFiltersToAllSchemas)
            {
                var jsonObjectContract = jsonContract as JsonObjectContract;
                if (jsonObjectContract != null)
                {
                    // NOTE: In next major version, _modelFilters will completely replace _schemaFilters
                    var modelFilterContext = new ModelFilterContext(jsonObjectContract.UnderlyingType, jsonObjectContract, this);
                    foreach (var filter in _modelFilters)
                    {
                        filter.Apply(schema, modelFilterContext);
                    }
                }

                foreach (var filter in _schemaFilters)
                {
                    filter.Apply(schema, this, jsonContract.UnderlyingType);
                }
            }

            return(schema);
        }
Exemplo n.º 8
0
        private Schema CreateObjectSchema(JsonObjectContract jsonContract)
        {
            var properties = jsonContract.Properties
                .Where(p => !p.Ignored)
                .Where(p => !(_ignoreObsoleteProperties && p.IsObsolete()))
                .ToDictionary(
                    prop => prop.PropertyName,
                    prop => CreateInlineSchema(prop.PropertyType).WithValidationProperties(prop)
                );

            var required = jsonContract.Properties.Where(prop => prop.IsRequired())
                .Select(propInfo => propInfo.PropertyName)
                .ToList();

            var schema = new Schema
            {
                required = required.Any() ? required : null, // required can be null but not empty
                properties = properties,
                type = "object"
            };

            foreach (var filter in _schemaFilters)
            {
                filter.Apply(schema, this, jsonContract.UnderlyingType);
            }

            // NOTE: In next major version, _modelFilters will completely replace _schemaFilters
            var modelFilterContext = new ModelFilterContext(jsonContract.UnderlyingType, jsonContract, this);
            foreach (var filter in _modelFilters)
            {
                filter.Apply(schema, modelFilterContext);
            }

            return schema;
        }
Exemplo n.º 9
0
 /// <summary>
 /// Called when generating the schema
 /// </summary>
 public void Apply(Schema model, ModelFilterContext context)
 {
     foreach (var dtProp in model.Properties.Where(x => x.Value.Format == "date-time"))
         dtProp.Value.Format = "date";
 }
Exemplo n.º 10
0
 public void Apply(Schema model, ModelFilterContext context)
 {
     model.Extensions.Add("X-property1", "value");
 }
Exemplo n.º 11
0
        private Schema CreateObjectSchema(JsonObjectContract jsonContract)
        {
            var properties = jsonContract.Properties
                .Where(p => !p.Ignored)
                .Where(p => !(_options.IgnoreObsoleteProperties && p.IsObsolete()))
                .ToDictionary(
                    prop => prop.PropertyName,
                    prop => CreateSchema(prop.PropertyType, true).AssignValidationProperties(prop)
                );

            var required = jsonContract.Properties.Where(prop => prop.IsRequired())
                .Select(propInfo => propInfo.PropertyName)
                .ToList();

            var schema = new Schema
            {
                Required = required.Any() ? required : null, // required can be null but not empty
                Properties = properties,
                Type = "object"
            };

            var filterContext = new ModelFilterContext(
                jsonContract.UnderlyingType,
                jsonContract,
                this);

            foreach (var filter in _options.ModelFilters)
            {
                filter.Apply(schema, filterContext);
            }

            return schema;
        }