Ejemplo n.º 1
0
        private Schema CreateInlineSchema(Type type)
        {
            if (this._customSchemaMappings.ContainsKey(type))
            {
                return(this._customSchemaMappings[type]());
            }
            JsonContract jsonContract = this._contractResolver.ResolveContract(type);

            if (jsonContract is JsonPrimitiveContract)
            {
                return(this.CreatePrimitiveSchema((JsonPrimitiveContract)jsonContract));
            }
            JsonDictionaryContract jsonDictionaryContract = jsonContract as JsonDictionaryContract;

            if (jsonDictionaryContract != null)
            {
                if (!jsonDictionaryContract.IsSelfReferencing())
                {
                    return(this.CreateDictionarySchema(jsonDictionaryContract));
                }
                return(this.CreateRefSchema(type));
            }
            else
            {
                JsonArrayContract jsonArrayContract = jsonContract as JsonArrayContract;
                if (jsonArrayContract != null)
                {
                    if (!jsonArrayContract.IsSelfReferencing())
                    {
                        return(this.CreateArraySchema(jsonArrayContract));
                    }
                    return(this.CreateRefSchema(type));
                }
                else
                {
                    JsonObjectContract jsonObjectContract = jsonContract as JsonObjectContract;
                    if (jsonObjectContract != null && jsonObjectContract.IsInferrable())
                    {
                        return(this.CreateRefSchema(type));
                    }
                    return(this.CreateRefSchema(typeof(object)));
                }
            }
        }
Ejemplo n.º 2
0
        private Schema CreateInlineSchema(Type type)
        {
            JsonContract jsonContract = this._contractResolver.ResolveContract(type);

            if (this._customSchemaMappings.ContainsKey(type))
            {
                return(this.FilterSchema(this._customSchemaMappings[type](), jsonContract));
            }
            if (jsonContract is JsonPrimitiveContract)
            {
                return(this.FilterSchema(this.CreatePrimitiveSchema((JsonPrimitiveContract)jsonContract), jsonContract));
            }
            JsonDictionaryContract dictionaryContract = jsonContract as JsonDictionaryContract;

            if (dictionaryContract != null)
            {
                if (!dictionaryContract.IsSelfReferencing())
                {
                    return(this.FilterSchema(this.CreateDictionarySchema(dictionaryContract), jsonContract));
                }
                return(this.CreateRefSchema(type));
            }
            JsonArrayContract arrayContract = jsonContract as JsonArrayContract;

            if (arrayContract != null)
            {
                if (!arrayContract.IsSelfReferencing())
                {
                    return(this.FilterSchema(this.CreateArraySchema(arrayContract), jsonContract));
                }
                return(this.CreateRefSchema(type));
            }
            JsonObjectContract objectContract = jsonContract as JsonObjectContract;

            if (objectContract != null && !objectContract.IsAmbiguous())
            {
                return(this.CreateRefSchema(type));
            }
            return(this.FilterSchema(new Schema()
            {
                type = "object"
            }, jsonContract));
        }