Skip to content

Inconsistent content encodings allowed #1711

@kerrykimbrough

Description

@kerrykimbrough

From the OpenAPI spec for MediaType:

encoding: A map between a property name and its encoding information. The key, being the property name, MUST exist in the schema as a property.

It is an error if the encoding map contains a key that is not defined as a property name in the content (object) schema. But this error is not recognized. The following test fails because it doesn't report the encoding for non-existent property "Z" as an error.

@Test
public void testEncodingNotApplicable() {
    String json =
        "{"
        + "  \"openapi\": \"3.0.0\","
        + "  \"info\": {"
        + "    \"title\": \"Encodings\","
        + "    \"version\": \"0.0.0\""
        + "  },"
        + "  \"paths\": {"
        + "    \"/resource\": {"
        + "      \"post\": {"
        + "        \"requestBody\": {"
        + "          \"content\": {"
        + "            \"multipart/form-data\": {"
        + "              \"schema\": {"
        + "                \"type\": \"object\","
        + "                \"properties\": {"
        + "                  \"X\": {"
        + "                    \"type\": \"integer\""
        + "                  },"
        + "                  \"Y\": {"
        + "                    \"type\": \"integer\""
        + "                  }"
        + "                }"
        + "              },"
        + "              \"encoding\": {"
        + "                \"Z\": {"
        + "                  \"contentType\": \"application/json\""
        + "                }"
        + "              }"
        + "            }"
        + "          }"
        + "        },"
        + "        \"responses\": {"
        + "          \"default\": {"
        + "            \"description\": \"None\""
        + "          }"
        + "        }"
        + "      }"
        + "    }"
        + "  }"
        + "}"
        ;
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    SwaggerParseResult result = parser.readContents(json, null, null);
    assertEquals( result.getMessages().size(), 1, "Error messages");
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions