Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
OllieKosh opened this issue Apr 22, 2025 · 1 comment
Closed

Comments

@OllieKosh
Copy link
Contributor

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.

@frantuma
Copy link
Member

frantuma commented May 6, 2025

Thanks for reporting this and for the PR! fixed in #4884

@frantuma frantuma closed this as completed May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants