stoicflame / enunciate-openapi

OpenAPI3 module for Enunciate
Apache License 2.0
10 stars 10 forks source link

java.lang.IllegalStateException: Failed to convert JSON to YAML: when using @documentationExample #36

Open jdimeo opened 3 years ago

jdimeo commented 3 years ago

It appears that whenever you use a @documentationExample, it gets written to the YAML improperly and causes a parse error. I tried with single quotes and double quotes neither fixed it.

For example, this bean:

public class ScoreResult {
    /**
     * The score code.
     * @documentationExample SCRCD
     */
    @Getter(onMethod_ = @Size(max = 32))
    private String scoreCode;
    ...

throws this error:

[ERROR] Failed to execute goal com.webcohesion.enunciate:enunciate-maven-plugin:2.12.1:docs (default) on project scoring-api-server: Error invoking Enunciate.: java.lang.IllegalStateException: Failed to convert JSON to YAML:
[ERROR] SCRCD: Unrecognized token 'SCRCD': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
[ERROR]  at [Source: (byte[])"SCRCD"; line: 1, column: 6]
jdimeo commented 3 years ago

I've temporarily fixed this on our fork: https://github.com/ElderResearch/enunciate-openapi/commit/8a61d008b094f93c3def81a68fd5435cde90a22c

However, I'm not opening a PR because I think this makes the wrong assumptions. Currently, it was expecting every example to be valid JSON. Now, I'm expecting it to never be JSON/an object, but rather a scalar value (like I have in my example above). This makes the most sense for field-level examples, but could break class-level examples.

Why is it using the ObjectTypeRenderer? do we need to annotate our method somehow to clue it in to the fact that it's a scalar value? perhaps this is a documentation and/or better stack trace issue rather than a bug.