Skip to content

Commit

Permalink
Merge pull request payara#5343 from aubi/FISH-1530
Browse files Browse the repository at this point in the history
FISH-1530 allow multiple servers and tags with empty url and name
  • Loading branch information
aubi authored and JamesHillyard committed Oct 8, 2021
1 parent 3d3f047 commit e0030da
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
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

0 comments on commit e0030da

Please sign in to comment.