javalin / javalin-openapi

Annotation processor for compile-time OpenAPI & JsonSchema, with out-of-the-box support for Javalin 5.x, Swagger & ReDoc
https://github.com/javalin/javalin-openapi/wiki
Apache License 2.0
45 stars 17 forks source link

Support for Redoc logo #194

Closed sbahloul closed 1 year ago

sbahloul commented 1 year ago

Describe the feature Aș part of the effort to improve and beautify the documentation with OpenAPI through redoc via Javalin, it would be nice to support the addition of the logo: https://redocly.com/docs/api-reference-docs/specification-extensions/x-logo/

Additional context It used to be possible to extend the class OpenAPIInfo to add a logo as followed, but now the class OpenAPIInfo is final. Would it be possible to either add this feature or allow to extend OpenAPIInfo ?

public class OpenAPIInfoPlusLogo extends Info {

    @JsonProperty("x-logo") @Getter @Setter
    private OpenAPILogo logo;

    public OpenAPIInfoPlusLogo logo(OpenAPILogo logo) {
        this.logo = logo;
        return this;
    }
}
@Getter @Setter
public class OpenAPILogo {

    @JsonProperty
    private String url;

    @JsonProperty
    private String backgroundColor;

    @JsonProperty
    private String altText;
}

NOTE: you are doing a fantastic job, really appreciated ! Kudos to all the Javalin team and contributors

dzikoysk commented 1 year ago

As long as it's not supported directly, because it'd add non standard to OpenApi properties to the scheme, you can still achieve it with document processor:

https://github.com/javalin/javalin-openapi/blob/843ad96f0e2ec311de02212e4f1a238ee914e50f/examples/javalin-maven-java/src/main/java/io/javalin/openapi/plugin/test/JavalinTest.java#L139-L142

Let me know if it works for you :)

sbahloul commented 10 months ago

For those who might be interested:

    options.withDefinitionConfiguration((s, config) -> {
       /* the rest of the configuration .... */
      config.withDefinitionProcessor(content -> { // you can add whatever you want to this document using your favourite json api
        ObjectNode logo = new ObjectNode(JsonNodeFactory.instance);
        logo.putIfAbsent("url", new TextNode("https://redocly.github.io/redoc/example-logo.png"));
        logo.putIfAbsent("backgroundColor", new TextNode("#FFFFFF"));
        logo.putIfAbsent("altText", new TextNode("Example logo"));
        ((ObjectNode)content.findValue("info")).putIfAbsent("x-logo", logo);
        return content.toPrettyString();
      });