示例#1
0
        public void Register(ModelSpec modelSpec)
        {
            if (modelSpec.Id == null || modelSpec.Type != "object")
                throw new InvalidOperationException("Registrar expects complex models only - must have non-null Id and Type = \"object\"");

            _registeredSpecs[modelSpec.Id] = modelSpec;
        }
示例#2
0
        public void Register(ModelSpec modelSpec)
        {
            if (modelSpec.Id == null || modelSpec.Type != "object")
            {
                throw new InvalidOperationException("Registrar expects complex models only - must have non-null Id and Type = \"object\"");
            }

            _registeredSpecs[modelSpec.Id] = modelSpec;
        }
示例#3
0
        private ModelSpec CreateComplexSpec(Type type)
        {
            var modelSpec = new ModelSpec
            {
                Id = GetUniqueTypeIdentifier(type),
                Type = "object",
                Properties = new Dictionary<string, ModelSpec>()
            };

            foreach (var propInfo in type.GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                var propModelSpec = FindOrCreateFor(propInfo.PropertyType);

                if (propModelSpec.Type == "object")
                    propModelSpec = new ModelSpec { Ref = propModelSpec.Id };

                modelSpec.Properties.Add(propInfo.Name, propModelSpec);
            }

            return modelSpec;
        }
示例#4
0
        private ModelSpec CreateContainerSpec(Type containedType)
        {
            var containedModelSpec = FindOrCreateFor(containedType);
            var modelSpec = new ModelSpec
            {
                Type = "array",
                Items = containedModelSpec
            };

            if (containedModelSpec.Type == "object")
                modelSpec.Items = new ModelSpec { Ref = containedModelSpec.Id };

            return modelSpec;
        }
 private void ModelProperty(ModelSpec model, string name, Action<ModelSpec> applyAssertions)
 {
     var modelPropertySpec = model.Properties[name];
     applyAssertions(modelPropertySpec);
 }
示例#6
0
 public SwaggerSpecConfig MapType <T>(ModelSpec modelSpec)
 {
     CustomTypeMappings[typeof(T)] = modelSpec;
     return(this);
 }
 private void AssertModelProperty(ModelSpec modelSpec, string propertyName, Action<ModelPropertySpec> applyAssertions)
 {
     var propertySpec = modelSpec.properties[propertyName];
     applyAssertions(propertySpec);
 }