示例#1
0
            public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
            {
                if (reader.TokenType == JsonToken.Null)
                {
                    return(null);
                }

                var operations = new OpenApiPathItem();

                while (reader.Read() && reader.TokenType == JsonToken.PropertyName)
                {
                    var propertyName = reader.Value.ToString();
                    reader.Read();

                    if (propertyName == "parameters")
                    {
                        operations.Parameters = (Collection <OpenApiParameter>)serializer.Deserialize(reader, typeof(Collection <OpenApiParameter>));
                    }
                    else if (propertyName == "servers")
                    {
                        operations.Servers = (Collection <OpenApiServer>)serializer.Deserialize(reader, typeof(Collection <OpenApiServer>));
                    }
                    else
                    {
                        var value = (OpenApiOperation)serializer.Deserialize(reader, typeof(OpenApiOperation));
                        operations.Add(propertyName, value);
                    }
                }
                return(operations);
            }
示例#2
0
            public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
            {
                if (reader.TokenType == JsonToken.Null)
                {
                    return(null);
                }

                var operations = new OpenApiPathItem();

                while (reader.Read() && reader.TokenType == JsonToken.PropertyName)
                {
                    var propertyName = reader.Value.ToString();
                    reader.Read();

                    if (propertyName == "summary")
                    {
                        operations.Summary = (string)serializer.Deserialize(reader, typeof(string));
                    }
                    else if (propertyName == "description")
                    {
                        operations.Description = (string)serializer.Deserialize(reader, typeof(string));
                    }
                    else if (propertyName == "parameters")
                    {
                        operations.Parameters = (Collection <OpenApiParameter>)serializer.Deserialize(reader, typeof(Collection <OpenApiParameter>));
                    }
                    else if (propertyName == "servers")
                    {
                        operations.Servers = (Collection <OpenApiServer>)serializer.Deserialize(reader, typeof(Collection <OpenApiServer>));
                    }
                    else
                    {
                        try
                        {
                            var value = (OpenApiOperation)serializer.Deserialize(reader, typeof(OpenApiOperation));
                            operations.Add(propertyName, value);
                        }
                        catch
                        {
                            if (operations.ExtensionData == null)
                            {
                                operations.ExtensionData = new Dictionary <string, object>();
                            }

                            operations.ExtensionData[propertyName] = serializer.Deserialize(reader);
                        }
                    }
                }
                return(operations);
            }