microsoft / OpenAPI.NET

The OpenAPI.NET SDK contains a useful object model for OpenAPI documents in .NET along with common serializers to extract raw OpenAPI JSON and YAML documents from the model.
MIT License
1.38k stars 231 forks source link

Some property missing from V2 Parameter deserializer (e.g. multipleOf) #194

Open PerthCharern opened 6 years ago

nth-commit commented 4 years ago

Here's an exhaustive list of the unsupported properties:

Reference: https://swagger.io/specification/v2/#parameterObject

kylehild commented 4 years ago

Are there any plans to support these properties?

nth-commit commented 4 years ago

Are there any plans to support these properties?

@kylehild I can't speak on behalf of the maintainers, and I don't know if it's an option for you - but it was easy for us to migrate to V3 and worth the effort.

dipidoo commented 4 years ago

minItems and maxItems are not properly working for parameter deserializing. They work only if under the items node, which is not proper OASv2. Serializing works fine.

            var testString = @"
{
  ""swagger"": ""2.0"",
  ""parameters"": {
    ""param0"": {
      ""type"": ""array"",
      ""items"": {
        ""type"": ""integer""
      },
      ""maxItems"": 4,
      ""minItems"": 4
    }
  }
}
".Trim();
            var testDoc = new OpenApiStringReader().Read(testString.ToString(), out var diag);
            Console.Out.WriteLine(testDoc.Components.Parameters["param0"].Schema.MaxItems);    // Expected: 4 Actual: null
            Console.Out.WriteLine(testDoc.Components.Parameters["param0"].Schema.MinItems);    // Expected: 4 Actual: null
            testString = @"
{
  ""swagger"": ""2.0"",
  ""parameters"": {
    ""param0"": {
      ""type"": ""array"",
      ""items"": {
        ""type"": ""integer"",
        ""maxItems"": 4,
        ""minItems"": 4
      }
    }
  }
}
".Trim();
            testDoc = new OpenApiStringReader().Read(testString.ToString(), out diag);
            Console.Out.WriteLine(testDoc.Components.Parameters["param0"].Schema.Items.MaxItems);    // Expected: 4 Actual: 4 but not proper OASv2
            Console.Out.WriteLine(testDoc.Components.Parameters["param0"].Schema.Items.MinItems);    // Expected: 4 Actual: 4 but not proper OASv2
            testDoc = new OpenApiDocument
            {
                Components = new OpenApiComponents
                {
                    Parameters =
                    {
                        ["param0"] = new OpenApiParameter
                        {
                            Schema = new OpenApiSchema
                            {
                                Type = "array",
                                Items = new OpenApiSchema
                                {
                                    Type = "integer"
                                },
                                MaxItems = 4,
                                MinItems = 4,
                            }
                        }
                    }
                }
            };
            Console.Out.WriteLine(JObject.Parse(testDoc.SerializeAsJson(OpenApiSpecVersion.OpenApi2_0))["parameters"]["param0"]["maxItems"]);    // Expected: 4 Actual: 4
            Console.Out.WriteLine(JObject.Parse(testDoc.SerializeAsJson(OpenApiSpecVersion.OpenApi2_0))["parameters"]["param0"]["minItems"]);    // Expected: 4 Actual: 4
        }