private static OpenApiResponse GetResponse(string returnDescStr) { if (string.IsNullOrEmpty(returnDescStr) || !returnDescStr.StartsWith('{')) { var resp = new OpenApiResponse { Description = "Success", Content = new Dictionary <string, OpenApiMediaType>() }; resp.Content.Add("application/json", new OpenApiMediaType { Schema = new OpenApiSchema { Type = "object", Default = new OpenApiString(returnDescStr) } }); return(resp); } var returnDesc = JsonConvert.DeserializeObject <JimuServiceReturnDesc>(TypeHelper.ReplaceTypeToJsType(returnDescStr)); var response = new OpenApiResponse { Description = string.IsNullOrEmpty(returnDesc.Comment) ? "Success" : returnDesc.Comment, Content = new Dictionary <string, OpenApiMediaType>() }; var isVoid = returnDesc.ReturnType == "System.Void"; if (isVoid) { return(response); } var isObject = TypeHelper.CheckIsObject(returnDesc.ReturnType); var isArray = TypeHelper.CheckIsArray(returnDesc.ReturnType); var schema = new OpenApiSchema { Type = returnDesc.ReturnType }; if ((isObject || isArray) && returnDesc.Properties != null && returnDesc.Properties.Any()) { schema = new OpenApiSchema { Type = isArray ? "array" : "object", Title = returnDesc.Comment, Description = returnDesc.Comment, Properties = _schemaFactory.GetProperties(returnDesc.Properties) }; } response.Content.Add("application/json", new OpenApiMediaType { Schema = schema }); return(response); }
public SchemaModel GetProperties(JimuServiceParameterDesc para, ISchemaFactory schemaFactory) { var schema = new OpenApiSchema { Type = "array", Title = para.Comment, }; var props = schemaFactory.GetProperties(para.Properties); var dicSchema = new OpenApiSchema(); if (props["value"].Properties != null && props["value"].Properties.Any()) { dicSchema.Properties.Add(props["key"].Type, new OpenApiSchema { Properties = props["value"].Properties }); } else { dicSchema.Properties.Add(props["key"].Type, props["value"]); } schema.Items = dicSchema; return(new SchemaModel(para.Name, schema)); }
public SchemaModel GetProperties(JimuServiceParameterDesc para, ISchemaFactory schemaFactory) { return(new SchemaModel(para.Name, new OpenApiSchema { Type = "object", Title = para.Comment, Properties = schemaFactory.GetProperties(para.Properties) })); }
public SchemaModel GetProperties(JimuServiceParameterDesc para, ISchemaFactory schemaFactory) { var schema = new OpenApiSchema { Type = "array", Title = para.Comment }; if (para.Properties != null && para.Properties.Count == 1 && (para.Properties.First().Properties == null || !para.Properties.First().Properties.Any())) { schema.Items = new OpenApiSchema { Type = para.Properties.First().Type }; } else { schema.Items = new OpenApiSchema { Properties = schemaFactory.GetProperties(para.Properties) }; } return(new SchemaModel(para.Name, schema)); }