Path params don't work with OpenAPI version 3.1.0

Issue #406 new
Former user created an issue

Fix: update your swagger-api/swagger-parser dependency to version v2.1.12

https://github.com/swagger-api/swagger-parser/commit/b2a9442509fd95a51dadbdc97871bab7f506e339 is needed to work with OpenAPI 3.1.0.

Comments (4)

  1. John Thompson

    Running into this problem on 3.1.0 with a UUID path parameter. Seems to be tokenizing it for whatever reason. I ran through the debugger and I think I narrowed down the issue.

    In com.atlassian.oai.validator.schema.SchemaValidator

        private static JsonNode readContent(@Nonnull final String value, @Nonnull final Schema schema) throws IOException {
            if ("null".equalsIgnoreCase(value)) {
                return Json.mapper().readTree("null");
            }
            if (schema instanceof DateTimeSchema) {
                return createStringNode(normaliseDateTime(value));
            }
            if ("string".equalsIgnoreCase(schema.getType())) {
                return createStringNode(value);
            }
            if ("number".equalsIgnoreCase(schema.getType()) ||
                    "integer".equalsIgnoreCase(schema.getType())) {
                return createNumericNode(value);
            }
            return Json.mapper().readTree(value);
        }
    

    The above is reading type which is null in 3.1.0, it migrated to an array called typeswith 3.1.0. Thus, logic is falling through to line 15 and failing. Should return `createStringNode(value)`.

    Guessing this is related to how you can now define types in an array. See the following link on how nullables are now handled.

    https://stackoverflow.com/questions/48111459/how-to-define-a-property-that-can-be-string-or-null-in-openapi-swagger

  2. Gaston Gorelik

    I ended up doing the same and reaching the same place with the debugger, there is a work around for this and its to set System.setProperty("bind-type", "true"). As explained here https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---OpenAPI-3.1

    is deserialized into a Schema class with populated types member with a single item array (while type remains null).

    In order to allow for no change support of 3.1 processing by existing clients in specific limited scenarios, users can set system property bind-type=true to have Schema.getType() return the value of the single item of Schema.types in OAS 3.1 specifications with a non-array Schema.type. This is however NOT RECOMMENDED (see this comment).

    See also Foreword above, this choice has been implemented to allow to maintain the same APIs, even if it introduces some "less clean" code.

    Please note that the above is not strictly related to OAS 3.1 / JSON Schema 2020/12, as type supports an array data type also in previous version, but this wasn't supported in Swagger Core versions < 2.2.x.

    So swagger-request-validator (specifically com.atlassian.oai.validator.schema.SchemaValidator) needs to be updated to use Schema.getTypes() instead of Schema.getType().

  3. Log in to comment