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

Formatting of annotations and annotation attributes has room for improvements #366

Open
lfvjimisola opened this issue Feb 23, 2023 · 2 comments

Comments

@lfvjimisola
Copy link

The formatting of annotations and annotation attributes makes the code more difficult to read in my opinion.
Example below.

Relates #78

post-apply:

package com.example.api;

import io.swagger.v3.oas.annotations.ExternalDocumentation;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Contact;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.info.License;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.servers.Server;
import io.swagger.v3.oas.annotations.servers.ServerVariable;
import io.swagger.v3.oas.annotations.tags.Tag;

@OpenAPIDefinition(
		info = @Info(title = "the title", version = "0.0", description = "My API",
				license = @License(name = "Apache 2.0", url = "http://foo.bar"),
				contact = @Contact(url = "http://gigantic-server.com", name = "Fred",
						email = "[email protected]")),
		tags = { @Tag(name = "Tag 1", description = "desc 1",
				externalDocs = @ExternalDocumentation(description = "docs desc")),
				@Tag(name = "Tag 2", description = "desc 2",
						externalDocs = @ExternalDocumentation(description = "docs desc 2")),
				@Tag(name = "Tag 3") },
		externalDocs = @ExternalDocumentation(description = "definition docs desc"),
		security = { @SecurityRequirement(name = "req 1", scopes = { "a", "b" }),
				@SecurityRequirement(name = "req 2", scopes = { "b", "c" }) },
		servers = { @Server(description = "server 1", url = "http://foo",
				variables = {
						@ServerVariable(name = "var1", description = "var 1", defaultValue = "1",
								allowableValues = { "1", "2" }),
						@ServerVariable(name = "var2", description = "var 2", defaultValue = "1",
								allowableValues = { "1", "2" }) }) })
public class OpenAPI {

}

My opinion is that something like this is more readable as the indent is lineup and not like stair:

package com.example.api;

import io.swagger.v3.oas.annotations.ExternalDocumentation;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Contact;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.info.License;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.servers.Server;
import io.swagger.v3.oas.annotations.servers.ServerVariable;
import io.swagger.v3.oas.annotations.tags.Tag;

@OpenAPIDefinition(
    info = @Info(
            title = "the title",
            version = "0.0",
            description = "My API",
            license = @License(name = "Apache 2.0", url = "http://foo.bar"),
            contact = @Contact(url = "http://gigantic-server.com", name = "Fred", email = "[email protected]")
    ),
    tags = {
            @Tag(name = "Tag 1", description = "desc 1", externalDocs = @ExternalDocumentation(description = "docs desc")),
            @Tag(name = "Tag 2", description = "desc 2", externalDocs = @ExternalDocumentation(description = "docs desc 2")),
            @Tag(name = "Tag 3")
    },
    externalDocs = @ExternalDocumentation(description = "definition docs desc"),
    security = {
            @SecurityRequirement(name = "req 1", scopes = {"a", "b"}),
            @SecurityRequirement(name = "req 2", scopes = {"b", "c"})
    },
    servers = {
            @Server(
                    description = "server 1",
                    url = "http://foo",
                    variables = {
                            @ServerVariable(name = "var1", description = "var 1", defaultValue = "1", allowableValues = {"1", "2"}),
                            @ServerVariable(name = "var2", description = "var 2", defaultValue = "1", allowableValues = {"1", "2"})
                    })
    }
)
public class OpenAPI {
    
}
@philwebb
Copy link
Contributor

I agree that the bottom version is easier to read, but I'm not sure that we want to go back to non-wrapped lines. Perhaps there's some other Eclipse formatter options we can tweak?

@jimisola
Copy link

What type of formatting are you thinking of if we go back to non-wrapped lines?

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

No branches or pull requests

3 participants