sdaschner / jaxrs-analyzer

Creates REST documentation for JAX-RS projects
Apache License 2.0
319 stars 101 forks source link

Problem when nesting JsonObjectBuilder #147

Closed hindsholm closed 6 years ago

hindsholm commented 6 years ago

I am generating HAL-style links using JsonObjectBuilder, but the generated Swagger is not as expected.

This method:

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public JsonObject get() {
        return Json.createObjectBuilder()
            .add("_links", Json.createObjectBuilder()
                .add("self", Json.createObjectBuilder()
                    .add("href", "http://example.com/self")))
            .build();
    }

produces this Swagger:

...
                "responses": {
                    "200": {
                        "description": "OK",
                        "headers": {
                        },
                        "schema": {
                            "$ref": "#/definitions/JsonObject"
                        }
                    }
                }
...
    "definitions": {
        "JsonObject": {
            "properties": {
                "_links": {
                    "$ref": "#/definitions/JsonObject_2"
                }
            }
        },
        "JsonObject_2": {
            "properties": {
                "self": {
                    "$ref": "#/definitions/JsonObject_2"
                }
            }
        }
    }

Please not that the 'href' property is missing in the Swagger spec and instead 'self' points back to itself. I really like the whole idea behind JAXRS-Analyzer, so I hope this issue can be fixed!

hindsholm commented 6 years ago

Fixed by #148.