Пример #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);
 }