Ejemplo n.º 1
0
        ///// <summary>
        ///// https://open.1688.com/api/apidocdetail.htm?id=cn.alibaba.open:push.query.messageList-1
        ///// https://open.1688.com/api/apidocdetail.htm?id=cn.alibaba.open:push.cursor.messageList-1
        ///// </summary>

        //private NJsonSchema.JsonSchema getCnAlibabaOpenPushMessageListV1(System.Collections.Generic.IDictionary<string, JsonSchema> definitions, string propertieName, string @namespace, string apiname, int version, string type, string description)
        //{
        //    var jsonSchema = getMessageTypeToSchema(definitions, @namespace, apiname, version, type, description);


        //    var pushMessageList = new NJsonSchema.JsonSchema
        //    {
        //        AllowAdditionalProperties = false,
        //        Type = NJsonSchema.JsonObjectType.Object,
        //        Properties = {
        //            {propertieName, jsonSchema.ToJsonSchemaProperty()} ,
        //        }
        //    };

        //    definitions.Add(apiname.ToPascalCase() + "Response", pushMessageList);
        //    return new NJsonSchema.JsonSchema
        //    {
        //        AllowAdditionalProperties = false,
        //        Type = NJsonSchema.JsonObjectType.Object,
        //        Reference = pushMessageList,
        //        //Definitions = { { "PushMessageList", pushMessageList } }
        //    };
        //}

        /// <summary>
        /// https://open.1688.com/api/apidocdetail.htm?id=aliexpress.open:api.getChildrenPostCategoryById-1
        /// </summary>
        /// <returns></returns>
        private NJsonSchema.JsonSchema getAliexpressOpenApiGetChildrenPostCategoryByIdV1(System.Collections.Generic.IDictionary <string, JsonSchema> definitions)
        {
            var jsonSchemaAeopPostCategoryList = new NJsonSchema.JsonSchema
            {
                AllowAdditionalProperties = false,
                Type       = NJsonSchema.JsonObjectType.Object,
                Properties =
                {
                    { "names",  DictionarySchema(typeof(string)).ToJsonSchemaProperty()         },
                    { "level",  NJsonSchema.JsonSchema.FromType <int>().ToJsonSchemaProperty()  },
                    { "id",     NJsonSchema.JsonSchema.FromType <int>().ToJsonSchemaProperty()  },
                    { "isleaf", NJsonSchema.JsonSchema.FromType <bool>().ToJsonSchemaProperty() }
                }
            };


            var jsonSchema = new NJsonSchema.JsonSchema
            {
                AllowAdditionalProperties = false,
                Type       = NJsonSchema.JsonObjectType.Object,
                Properties =
                {
                    { "aeopPostCategoryList", makeArraySchemaType(jsonSchemaAeopPostCategoryList, 1).ToJsonSchemaProperty() },
                    { "success",              NJsonSchema.JsonSchema.FromType <bool>().ToJsonSchemaProperty() }
                }
            };

            definitions.Add("ApiGetChildrenPostCategoryByIdResult", jsonSchema);
            return(new NJsonSchema.JsonSchema
            {
                AllowAdditionalProperties = false,
                Type = NJsonSchema.JsonObjectType.Object,
                Reference = jsonSchema
            });
        }
Ejemplo n.º 2
0
        private NJsonSchema.JsonSchema createJsonSchema(string @namespace, string apiname, int version, ModelInfoResult[] modelInfoResult)
        {
            var jsonSchema = new NJsonSchema.JsonSchema
            {
                AllowAdditionalProperties = false,
                Type = NJsonSchema.JsonObjectType.Object
            };

            createJsonSchema(jsonSchema, @namespace, apiname, version, modelInfoResult);
            return(jsonSchema);
        }
Ejemplo n.º 3
0
        public void Process_FixedNumberOfJsonDefinitions_FixedNumberOfXSDSchemas()
        {
            var jsonSchema = new NJsonSchema.JsonSchema();

            jsonSchema.Definitions.Add("Order", new NJsonSchema.JsonSchema());
            jsonSchema.Definitions.Add("Customer", new NJsonSchema.JsonSchema());
            jsonSchema.Definitions.Add("Vendor", new NJsonSchema.JsonSchema());

            var schemaSet = Processor.Process(jsonSchema);

            Assert.AreEqual(3, schemaSet.Count);
        }
Ejemplo n.º 4
0
        private NJsonSchema.JsonSchema errorJsonSchemaResponse()
        {
            var typeString = NJsonSchema.JsonSchema.FromType(typeof(string));

            var jsonSchema = new NJsonSchema.JsonSchema {
                AllowAdditionalProperties = false, Description = "返回错误信息"
            };

            jsonSchema.Properties.Add("error_message", typeString.ToJsonSchemaProperty(f => { f.Description = "错误信息"; }));
            jsonSchema.Properties.Add("exception", typeString.ToJsonSchemaProperty(f => f.Description = "异常描述"));
            jsonSchema.Properties.Add("error_code", typeString.ToJsonSchemaProperty());
            jsonSchema.Properties.Add("request_id", typeString.ToJsonSchemaProperty(f => f.Description = "请求标识"));
            return(jsonSchema);
        }
Ejemplo n.º 5
0
        InferDeduceSchema
        (
            string data
        )
        {
            NJsonSchema.JsonSchema schema = await NJsonSchema.JsonSchema.FromJsonAsync(data);

            IEnumerable <NJsonSchema.CodeGeneration.CodeArtifact> types = GenerateTypes(schema);

            return
                (
                schema : schema,
                types : types
                );
        }
Ejemplo n.º 6
0
        private NJsonSchema.JsonSchema createJsonSchema(string type, ddd.MessageDoc[] modelInfoResult)
        {
            var _type = 获取数组维度(type);

            var ddd = getJsonSchemaCache(modelInfoResult, f =>
            {
                var jsonSchema = new NJsonSchema.JsonSchema
                {
                    AllowAdditionalProperties = false,
                    Type = NJsonSchema.JsonObjectType.Object
                };
                createJsonSchemaBy(jsonSchema, modelInfoResult);
                return(jsonSchema);
            });

            return(makeArraySchemaType(ddd, _type.arrLength));
        }
Ejemplo n.º 7
0
        private NJsonSchema.JsonSchema getMessageTypeToSchema(ddd.TopicResult apiDetail)
        {
            var key = apiDetail.TopicId;

            if (keyValuePairstModelInfo.ContainsKey(key))
            {
                var jsonSchema = keyValuePairstModelInfo[key];
                return(new NJsonSchema.JsonSchema {
                    AllowAdditionalProperties = false, AllOf = { jsonSchema }
                });
            }
            else
            {
                var modelInfoResult = apiDetail.MessageDocs;
                var md5key          = string.Join("", modelInfoResult?.Select(f => f.Name + f.Type).ToArray() ?? new string[] { });
                if (keyValuePairstModelInfo.ContainsKey(md5key))
                {
                    var jsonSchema = keyValuePairstModelInfo[md5key];
                    return(new NJsonSchema.JsonSchema {
                        AllowAdditionalProperties = false, AllOf = { jsonSchema }
                    });
                }
                else
                {
                    var jsonSchema = new NJsonSchema.JsonSchema
                    {
                        Id = key,
                        AllowAdditionalProperties = false,
                        Type        = NJsonSchema.JsonObjectType.Object,
                        Description = $"{apiDetail.TopicGroupDisplayName}-{apiDetail.TopicDisplayName}\r\nhttps://open.1688.com/doc/topicDetail.htm?id={apiDetail.TopicId}&topicGroup={apiDetail.TopicGroupName}"
                    };
                    keyValuePairstModelInfo.Add(key, jsonSchema);
                    keyValuePairstModelInfo.Add(md5key, jsonSchema);
                    createJsonSchemaBy(jsonSchema, modelInfoResult);

                    return(jsonSchema);
                }


                //var rr = NJsonSchema.JsonSchema.FromType<string>().ToJsonSchemaProperty();
                //rr.Title = "指当前类型的具体功能";
                //rr.IsReadOnly = true;
                //rr.Default = $"{apiDetail.TopicGroupDisplayName}-{apiDetail.TopicDisplayName}";
                //jsonSchema.Properties.Add("TypeDescription", rr);
            }
        }
Ejemplo n.º 8
0
        private NJsonSchema.JsonSchema makeArraySchemaType(NJsonSchema.JsonSchema jsonSchema, int arrLength)
        {
            if (jsonSchema != null)
            {
                for (int i = 0; i < arrLength; i++)
                {
                    jsonSchema = new NJsonSchema.JsonSchema {
                        Type = NJsonSchema.JsonObjectType.Array, Item = jsonSchema
                    };
                }

                return(jsonSchema);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 9
0
 private void createJsonSchemaBy(NJsonSchema.JsonSchema jsonSchema, ddd.MessageDoc[] modelInfoResult)
 {
     if (modelInfoResult == null || modelInfoResult.Length == 0)
     {
     }
     else
     {
         foreach (var item in modelInfoResult)
         {
             if (string.IsNullOrWhiteSpace(item.Name))
             {
             }
             else/* if(!jsonSchema.Properties.ContainsKey(item.Name))*/
             {
                 jsonSchema.Properties.Add(item.Name, getJsonSchemaProperty(item.Name, item.Type, item.Required, item.Children, item.Desc?.过滤特殊字符()));
             }
         }
     }
 }
Ejemplo n.º 10
0
 private void createJsonSchema(NJsonSchema.JsonSchema jsonSchema, string @namespace, string apiname, int version, ModelInfoResult[] modelInfoResult)
 {
     if (modelInfoResult == null || modelInfoResult.Length == 0)
     {
     }
     else
     {
         foreach (var item in modelInfoResult)
         {
             if (string.IsNullOrWhiteSpace(item.Name))
             {
             }
             else/* if(!jsonSchema.Properties.ContainsKey(item.Name))*/
             {
                 jsonSchema.Properties.Add(item.Name, getJsonSchemaProperty(jsonSchema.Definitions, @namespace, apiname, version, item.Name, item.Type, item.DefaultValue, false, item.Description?.过滤特殊字符()));
             }
         }
     }
 }
Ejemplo n.º 11
0
        public static XmlSchemaSet Process(NJsonSchema.JsonSchema jsonSchema)
        {
            var schemaSet = new XmlSchemaSet();

            foreach (var definitionKey in jsonSchema.Definitions.Keys)
            {
                var definition = jsonSchema.Definitions[definitionKey];
                var schema     = new XmlSchema()
                {
                    Id = definitionKey,
                };

                schema.Items.Add(GenerateComplexObject(definitionKey, definition.Properties));
                schemaSet.Add(schema);
            }

            schemaSet.Compile();
            return(schemaSet);
        }
Ejemplo n.º 12
0
        private NJsonSchema.JsonSchema getSchemaResponse(System.Collections.Generic.IDictionary <string, JsonSchema> definitions, DetailResult apiDetail, ModelInfoResult item)
        {
            var ss = getSchema(definitions, apiDetail.Namespace, apiDetail.Name, apiDetail.Version, item.Name, item.Type, item.Description);

            var 排除OceanApiId = new[] {
                "cn.alibaba.open:system.time.get-1"
            };
            var 包含OceanApiId = new[] {
                "cn.alibaba.open:push.query.messageList-1",
                "cn.alibaba.open:push.cursor.messageList-1",
                "com.alibaba.product.push:alibaba.cross.syncProductListPushed-1"
            };

            if (!排除OceanApiId.Contains(apiDetail.OceanApiId) && (ss.Reference == null || 包含OceanApiId.Contains(apiDetail.OceanApiId)))
            {
                var ssssss = new NJsonSchema.JsonSchema
                {
                    AllowAdditionalProperties = false,
                    Description = item.Description,
                    Properties  =
                    {
                        { item.Name?.类名过滤特殊字符(), ss.ToJsonSchemaProperty() }
                    }
                };

                var key = string.Join("", ssssss.Properties.Select(f => f.Key + f.Value.Type + f.Value.Title));
                if (keyValuePairstModelInfo.ContainsKey(key))
                {
                    return(keyValuePairstModelInfo[key]);
                }
                else
                {
                    keyValuePairstModelInfo.Add(key, ssssss);
                    return(ssssss);
                }
            }
            else
            {
                return(ss);
            }
        }
Ejemplo n.º 13
0
 /// <summary>Determines whether the given schema is the parent schema of this schema (i.e. super/base class).</summary>
 /// <param name="schema">The possible subtype schema.</param>
 /// <returns>true or false</returns>
 public bool Inherits(JsonSchema schema)
 {
     schema = schema.ActualSchema;
     return(InheritedSchema?.ActualSchema == schema || InheritedSchema?.Inherits(schema) == true);
 }
Ejemplo n.º 14
0
        private async Task <OpenApiDocument> 创建(bool isFull)
        {
            var document = new OpenApiDocument();

            Task <eeeeeeeee11>[] publicApiDetails;
            if (isFull)
            {
                var publicAllApis = await AlibabaDataCache.GetAllTopics();

                publicApiDetails = publicAllApis.Result.Select(async f => new eeeeeeeee11 {
                    ApiInfo = f, ApiDetail = await AlibabaDataCache.GetTopic(f.TopicId)
                }).ToArray();
            }
            else
            {
                var apiCategorys = await AlibabaDataCache.GetTopicGroups();

                var aa = apiCategorys.Result.Select(async f => await AlibabaDataCache.GetTopicsByGroupAndOwner(f.Id));
                publicApiDetails = aa.SelectMany(f => f.Result.Result.Select(async ff => new eeeeeeeee11
                {
                    ApiInfo   = ff,
                    ApiDetail = await AlibabaDataCache.GetTopic(ff.TopicId)
                })).ToArray();
            }


            for (int i = 0; i < publicApiDetails.Length; i++)
            {
                var publicApi = publicApiDetails[i].Result;
                Console.WriteLine((i + 1) + "." + publicApi.ApiInfo.TopicGroupDisplayName + ":" + publicApi.ApiInfo.TopicDisplayName);

                var apiDetail = publicApi.ApiDetail.Result;

                document.Definitions.Add(apiDetail.TopicId, getMessageTypeToSchema(apiDetail));
            }

            var rr = NJsonSchema.JsonSchema.FromType <string>().ToJsonSchemaProperty();

            rr.Title      = "TypeDescription的json";
            rr.IsReadOnly = true;
            rr.Default    = Newtonsoft.Json.JsonConvert.SerializeObject(publicApiDetails.ToDictionary(f => f.Result.ApiInfo.TopicId, f => f.Result.ApiInfo.TopicGroupDisplayName + "-" + f.Result.ApiInfo.TopicDisplayName));
            //var rr1 = NJsonSchema.JsonSchema.FromType<string>().ToJsonSchemaProperty();
            //rr1.Title = "TypeDescription的json";
            //rr1.IsReadOnly = true;
            //rr1.Default = Newtonsoft.Json.JsonConvert.SerializeObject(document.Definitions.ToDictionary(f => f.Key, f => f.Value.Id));

            var TypeDescriptionEnum = new NJsonSchema.JsonSchema {
                Type = JsonObjectType.String, Description = "消息类型"
            };

            document.Definitions.Add("TypeDescription", TypeDescriptionEnum);
            foreach (var item in publicApiDetails)
            {
                TypeDescriptionEnum.Enumeration.Add(item.Result.ApiInfo.TopicId);
                TypeDescriptionEnum.EnumerationNames.Add(item.Result.ApiInfo.TopicId);
            }

            var TypeDescriptionJson = new NJsonSchema.JsonSchema {
                Type = JsonObjectType.Object, AllowAdditionalProperties = false
            };

            document.Definitions.Add("TypeDescriptionJson", TypeDescriptionJson);
            TypeDescriptionJson.Properties.Add("JsonDescription", rr);
            //TypeDescriptionJson.Properties.Add("JsonClass", rr1);
            return(document);
        }
 public MarketPlaceHeadersHandler(MarketPlaceHttpHeaders marketPlaceHttpHeaders, HttpMessageHandler innerHandler = null)
 {
     _schema = JsonSchema4.FromType <MarketPlaceError>();
     _marketPlaceHttpHeaders = marketPlaceHttpHeaders;
     InnerHandler            = innerHandler ?? new HttpClientHandler();
 }
Ejemplo n.º 16
0
        private NJsonSchema.JsonSchema getMessageTypeToSchema(System.Collections.Generic.IDictionary <string, JsonSchema> definitions, string @namespace, string apiname, int version, string type, string description)
        {
            if (type?.StartsWith("message:") != true)
            {
                return(null);
            }
            var typeName = type.Replace("message:", "");

            var _type = 获取数组维度(typeName);

            var key = @namespace + apiname + _type.type;

            if (keyValuePairstModelInfo.ContainsKey(key))
            {
                return(makeArraySchemaType(new NJsonSchema.JsonSchema {
                    AllowAdditionalProperties = false, Reference = keyValuePairstModelInfo[key]
                }, _type.arrLength));
            }
            else
            {
                var modelInfo       = AlibabaDataCache.GetModelInfoByCacheAsync(@namespace, apiname, version, _type.type).GetAwaiter().GetResult();
                var modelInfoResult = modelInfo.Result;

                var md5key = modelInfoResult == null ? null : string.Join("", modelInfoResult?.Select(f => f.Name + f.Type));
                if (!string.IsNullOrWhiteSpace(md5key) && keyValuePairstModelInfo.ContainsKey(md5key))
                {
                    return(makeArraySchemaType(new NJsonSchema.JsonSchema {
                        AllowAdditionalProperties = false, Reference = keyValuePairstModelInfo[md5key]
                    }, _type.arrLength));
                }
                else
                {
                    var jsonSchema = new NJsonSchema.JsonSchema
                    {
                        AllowAdditionalProperties = false,
                        Type = NJsonSchema.JsonObjectType.Object
                    };
                    keyValuePairstModelInfo.Add(key, jsonSchema);
                    if (!string.IsNullOrWhiteSpace(md5key))
                    {
                        keyValuePairstModelInfo.Add(md5key, jsonSchema);
                    }
                    createJsonSchema(jsonSchema, @namespace, apiname, version, modelInfoResult);
                    jsonSchema.Description = (string.IsNullOrWhiteSpace(description) ? "" : description + "\r\n") + $"{modelInfo.ErrMsg}\r\n namespace:{@namespace},apiname:{apiname},version:{version},typeName:{_type.type}";

                    if (definitions != null)
                    {
                        var _typeName = _type.type?.ToPascalCase();
                        if (!definitions.ContainsKey(_typeName))
                        {
                            definitions.Add(_typeName, jsonSchema);
                        }
                        else
                        {
                            definitions.Add((@namespace + "." + apiname)?.ToPascalCase() + _typeName, jsonSchema);
                            //var dfsdfsd = document.Definitions[_typeName];
                        }
                    }


                    return(makeArraySchemaType(new NJsonSchema.JsonSchema {
                        AllowAdditionalProperties = false, Reference = jsonSchema
                    }, _type.arrLength));
                }
            }
        }
Ejemplo n.º 17
0
 /// <summary>Resolves a file reference.</summary>
 /// <param name="filePath">The file path.</param>
 /// <param name="cancellationToken">The cancellation token</param>
 /// <returns>The resolved JSON Schema.</returns>
 /// <exception cref="NotSupportedException">The System.IO.File API is not available on this platform.</exception>
 public virtual async Task <IJsonReference> ResolveFileReferenceAsync(string filePath, CancellationToken cancellationToken = default)
 {
     return(await JsonSchema.FromFileAsync(filePath, schema => this, cancellationToken).ConfigureAwait(false));
 }
Ejemplo n.º 18
0
 /// <summary>Resolves an URL reference.</summary>
 /// <param name="url">The URL.</param>
 /// <param name="cancellationToken">The cancellation token</param>
 /// <exception cref="NotSupportedException">The HttpClient.GetAsync API is not available on this platform.</exception>
 public virtual async Task <IJsonReference> ResolveUrlReferenceAsync(string url, CancellationToken cancellationToken = default)
 {
     return(await JsonSchema.FromUrlAsync(url, schema => this, cancellationToken).ConfigureAwait(false));
 }