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

FISH-1530 allow multiple servers and tags with empty url and name #5343

Merged
merged 1 commit into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,16 @@
*/
package fish.payara.microprofile.openapi.impl.model;

import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.createList;
import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.extractAnnotations;
import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.mergeProperty;
import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.readOnlyView;

import fish.payara.microprofile.openapi.api.visitor.ApiContext;
import fish.payara.microprofile.openapi.impl.model.info.InfoImpl;
import fish.payara.microprofile.openapi.impl.model.security.SecurityRequirementImpl;
import fish.payara.microprofile.openapi.impl.model.servers.ServerImpl;
import fish.payara.microprofile.openapi.impl.model.tags.TagImpl;
import fish.payara.microprofile.openapi.impl.model.util.ModelUtils;
import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.createList;
import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.extractAnnotations;
import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.mergeProperty;
import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.readOnlyView;
import java.util.List;
import org.eclipse.microprofile.openapi.models.Components;
import org.eclipse.microprofile.openapi.models.ExternalDocumentation;
Expand Down Expand Up @@ -147,17 +146,14 @@ public OpenAPI addServer(Server server) {

final String serverUrl = server.getUrl();

if (serverUrl == null) {
return this;
}

if (servers == null) {
servers = createList();
}

for (Server existingServer : getServers()) {
// If a server with the same URL is found, merge them
if (serverUrl.equals(existingServer.getUrl())) {
// If a server with the same URL is found, merge them.
// Consider two servers without url as different in order to pass TCK.
if (serverUrl != null && serverUrl.equals(existingServer.getUrl())) {
ModelUtils.merge(server, existingServer, true);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ public int hashCode() {
return hash;
}

/**
* Two tags are equal, if they have the same non-null name.
*
* @param obj the reference tag with which to compare.
* @return {@code true} if this tag has the same non-null name,
* {@code false} otherwise.
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
Expand All @@ -171,7 +178,7 @@ public boolean equals(Object obj) {
return false;
}
final TagImpl other = (TagImpl) obj;
return Objects.equals(this.name, other.name);
return this.name != null && Objects.equals(this.name, other.name);
}

@Override
Expand Down