Skip to content

[BUG] Model resolution for global @PathParam ignores Open API 3.1 setting #4878

@OllieKosh

Description

@OllieKosh

Model resolution for global path parameters ignores the setting that the target open api is 3.1, as a consequence openapi 3.1 only features defined with annotations are ignored (i.e SwaggerConfiguration#isOpenAPI31 == true is not respected).

Reproducer

A test that uses @Schema#patternProperties (as an example of 3.1-only property) to show the error:

        SwaggerConfiguration config = new SwaggerConfiguration().openAPI31(Boolean.TRUE);
        Reader reader = new Reader(config);

        OpenAPI openAPI = reader.read(PathParamScopesResource.class);
        String yaml = "openapi: 3.1.0\n" +
                "paths:\n" +
                "  /{globalPathParam}/{localPathParam}:\n" +
                "    get:\n" +
                "      operationId: getMethod\n" +
                "      parameters:\n" +
                "      - name: globalPathParam\n" +
                "        in: path\n" +
                "        required: true\n" +
                "        schema:\n" +
                "          type: string\n" +
                "          patternProperties:\n" +
                "            extraObject: {}\n" +
                "      - name: localPathParam\n" +
                "        in: path\n" +
                "        required: true\n" +
                "        schema:\n" +
                "          type: string\n" +
                "          patternProperties:\n" +
                "            extraObject: {}\n" +
                "      responses:\n" +
                "        default:\n" +
                "          description: default response\n" +
                "          content:\n" +
                "            '*/*': {}\n";
        // fails because "patternProperties" is not added to globalPathParam
        SerializationMatchers.assertEqualsToYaml31(openAPI, yaml);

and example Resource class:

@Path("{globalPathParam}")
public class PathParamScopesResource {

    public PathParamScopesResource(@PathParam("globalPathParam") @Schema(patternProperties=@StringToClassMapItem(key = "extraObject", value = Object.class)) String globalPathParam) {
    }

    @GET
    @Path("{localPathParam}")
    public void getMethod(@PathParam("localPathParam") @Schema(patternProperties=@StringToClassMapItem(key = "extraObject", value = Object.class)) String localPathParam){
    }
}

The test shows the expected result, but actual result is that patternProperties are not represented in the spec for global @PathParam (i.e globalPathParam ), but are correctly represented for endpoint path param (i.e localPathParam).

Proposed solution

ReaderUtils#collectConstructorParameters:84 hardcodes openapi31 to be false, which seems to be at the core of the issue. Propagating the value from swagger configuration will solve this issue.

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