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

Line feeds in example object value are ignored, text is truncated #1895

Closed
cristalp opened this issue Jul 3, 2024 · 8 comments · Fixed by #1904
Closed

Line feeds in example object value are ignored, text is truncated #1895

cristalp opened this issue Jul 3, 2024 · 8 comments · Fixed by #1904
Labels
bug Something isn't working

Comments

@cristalp
Copy link
Contributor

cristalp commented Jul 3, 2024

I'm switching to Eclipse MicroProfile annotations from Swagger annotations and from another Maven plugin to the Smallrye Maven plugin.

I found that line feeds are ignored in @ExampleObject values. This is what I annotate:

@Content(examples = { @ExampleObject(name = "The user IDS", value = "1046\n1049\n1051") })

With the old toolchain, I get the following in openapi.json :

            "content" : {
              "text/plain" : {
                "example" : "1046\n1049\n1051"
              }
            }

(I didn't specify any name back then.)

Rendered in SwaggerUI it looks like this:

1046
1049
1051

With the Smallrye Maven plugin, this is what I get:

            "content" : {
              "text/plain" : {
                "examples" : {
                  "The user IDS" : {
                    "value" : 1046
                  }
                }
              }

Of course, SwaggerUI shows it like this:

1046

So any text after the first line feed is thrown away. As far as I remember, any OpenAPI text is considered Markdown, so shouldn't that work?

And is there any relation to the old rendering as one example and Smallrye correctly creating examples ?

@MikeEdgar
Copy link
Member

Just out of curiosity, if you add a space in the example before the 1046, does it pass through all three lines? I think it believes the value is a number and the Jackson parser may be throwing out the second and third lines.

@MikeEdgar
Copy link
Member

Actually, space won't work - it's trimmed. Try adding a + prefix to test it.

@cristalp
Copy link
Contributor Author

cristalp commented Jul 3, 2024

Well, using "1046 \n 1049 \n1051"shows the same behavior.

However, I have another endpoint which returns JSON, and the example value was not valid JSON. This was shown during build (cool!) and thus I could fix it. That example also contains line feeds, and it's rendered with line feeds in the openapi.json. But I don't know whether that's because of my line feeds or whether the plugin parses it and pretty prints it anyway.

What exactly do you mean with the + prefix?

@cristalp
Copy link
Contributor Author

cristalp commented Jul 3, 2024

I also wonder: Since this is text/plain, why would it be parsed by the Jackson parser?

@cristalp
Copy link
Contributor Author

cristalp commented Jul 3, 2024

Ok, so I set it to "1046+\n1049+\n1051", and this is what's rendered:

"value" : "1046+\n1049+\n1051"

And in Swagger UI:

1046+
1049+
1051

@MikeEdgar
Copy link
Member

Thanks, adding the + just breaks the conversion of the value to a number. This definitely seems like a bug.

@cristalp
Copy link
Contributor Author

cristalp commented Jul 3, 2024

Yes, I also think so. Since no media type is given, the String should just be copied through to openapi.json .

@cristalp
Copy link
Contributor Author

cristalp commented Jul 5, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants