Skip to content
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

List example objects should produce a true list in OpenAPI spec #1565

Open
jjathman opened this issue May 8, 2024 · 0 comments · May be fixed by #1567
Open

List example objects should produce a true list in OpenAPI spec #1565

jjathman opened this issue May 8, 2024 · 0 comments · May be fixed by #1567

Comments

@jjathman
Copy link

jjathman commented May 8, 2024

Expected Behavior

If I provide an example string on a List/array object which is a JSON representation of a list, then the output of that in the Yaml OpenAPI spec should be a list. Very similar logic to the special logic of an example which is a JSON map.

Actual Behaviour

The JSON array string is simply output into the yaml file as a string.

Steps To Reproduce

Create a Java class with this type of structure:

    @Schema(description = "Street lines of the address", example = "[\"123 Main St\", \"Suite 517\"])
    List<String> lines;

the Yaml output will look like this:

      properties:
        lines:
          type: array
          description: Street lines of the address
          example: "[\"123 Main St\", \"Suite 517\"]"
          items:
            type: string

When ideally it would be this:

      properties:
        lines:
          type: array
          description: Street lines of the address
          example:
          - 123 Main St
          - Suite 517
          items:
            type: string

I think another special case within this code could solve the issue:

        String schemaExample = (String) annValues.get("example");
        if (StringUtils.isNotEmpty(schemaExample)) {
            try {
                schemaToBind.setExample(OpenApiUtils.getConvertJsonMapper().readValue(schemaExample, Map.class));
               // NEW CODE HERE:  Try to read the value as a list and set the example accordingly
            } catch (JsonProcessingException e) {
                schemaToBind.setExample(schemaExample);
            }
        }

What makes this difficult is Swagger seems to handle it just fine without this change, however not all tools are as forgiving.

Environment Information

Micronaut OpenApi version 6.5.1

Example Application

No response

Version

4.3.8

@altro3 altro3 linked a pull request May 10, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant