Skip to content

Commit

Permalink
fix generate openapi3.json redundant tags array bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wubin1989 committed May 8, 2021
1 parent e580834 commit ed2b397
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public static Backend convert(Openapi3 openAPI) {
}
PathWrapper wrapper = new PathWrapper();
Path pathEntryValue = pathEntry.getValue();
List<String> tags = pathEntryValue.getTags();
List<String> tags = pathEntryValue.returnTags();
String protoName;
if (CollectionUtils.isNotEmpty(tags) && tags.size() > 1 && StringUtils.isNotBlank(tags.get(1))) {
protoName = StringUtils.capitalize(tags.get(1)) + "Proto";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import cloud.unionj.generator.openapi3.model.ExternalDocs;
import cloud.unionj.generator.openapi3.model.Security;
import cloud.unionj.generator.openapi3.model.servers.Server;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -16,7 +15,6 @@
* cloud.unionj.generator.openapi3.model.paths
* date 2020/12/15
*/
@Data
public class Operation {

private List<String> tags = new ArrayList<>();
Expand All @@ -40,6 +38,9 @@ public class Operation {
// TODO
private List<Server> servers;

public Operation() {
}

public void tags(String tag) {
this.tags.add(tag);
}
Expand All @@ -48,4 +49,182 @@ public void parameters(Parameter parameter) {
this.parameters.add(parameter);
}

public List<String> getTags() {
return this.tags;
}

public String getSummary() {
return this.summary;
}

public String getDescription() {
return this.description;
}

public String getOperationId() {
return this.operationId;
}

public List<Parameter> getParameters() {
return this.parameters;
}

public RequestBody getRequestBody() {
return this.requestBody;
}

public Responses getResponses() {
return this.responses;
}

public boolean isDeprecated() {
return this.deprecated;
}

public ExternalDocs getExternalDocs() {
return this.externalDocs;
}

public Map<String, Callback> getCallbacks() {
return this.callbacks;
}

public List<Security> getSecurity() {
return this.security;
}

public List<Server> getServers() {
return this.servers;
}

public void setTags(List<String> tags) {
this.tags = tags;
}

public void setSummary(String summary) {
this.summary = summary;
}

public void setDescription(String description) {
this.description = description;
}

public void setOperationId(String operationId) {
this.operationId = operationId;
}

public void setParameters(List<Parameter> parameters) {
this.parameters = parameters;
}

public void setRequestBody(RequestBody requestBody) {
this.requestBody = requestBody;
}

public void setResponses(Responses responses) {
this.responses = responses;
}

public void setDeprecated(boolean deprecated) {
this.deprecated = deprecated;
}

public void setExternalDocs(ExternalDocs externalDocs) {
this.externalDocs = externalDocs;
}

public void setCallbacks(Map<String, Callback> callbacks) {
this.callbacks = callbacks;
}

public void setSecurity(List<Security> security) {
this.security = security;
}

public void setServers(List<Server> servers) {
this.servers = servers;
}

public boolean equals(final Object o) {
if (o == this) return true;
if (!(o instanceof Operation)) return false;
final Operation other = (Operation) o;
if (!other.canEqual((Object) this)) return false;
final Object this$tags = this.getTags();
final Object other$tags = other.getTags();
if (this$tags == null ? other$tags != null : !this$tags.equals(other$tags)) return false;
final Object this$summary = this.getSummary();
final Object other$summary = other.getSummary();
if (this$summary == null ? other$summary != null : !this$summary.equals(other$summary)) return false;
final Object this$description = this.getDescription();
final Object other$description = other.getDescription();
if (this$description == null ? other$description != null : !this$description.equals(other$description))
return false;
final Object this$operationId = this.getOperationId();
final Object other$operationId = other.getOperationId();
if (this$operationId == null ? other$operationId != null : !this$operationId.equals(other$operationId))
return false;
final Object this$parameters = this.getParameters();
final Object other$parameters = other.getParameters();
if (this$parameters == null ? other$parameters != null : !this$parameters.equals(other$parameters)) return false;
final Object this$requestBody = this.getRequestBody();
final Object other$requestBody = other.getRequestBody();
if (this$requestBody == null ? other$requestBody != null : !this$requestBody.equals(other$requestBody))
return false;
final Object this$responses = this.getResponses();
final Object other$responses = other.getResponses();
if (this$responses == null ? other$responses != null : !this$responses.equals(other$responses)) return false;
if (this.isDeprecated() != other.isDeprecated()) return false;
final Object this$externalDocs = this.getExternalDocs();
final Object other$externalDocs = other.getExternalDocs();
if (this$externalDocs == null ? other$externalDocs != null : !this$externalDocs.equals(other$externalDocs))
return false;
final Object this$callbacks = this.getCallbacks();
final Object other$callbacks = other.getCallbacks();
if (this$callbacks == null ? other$callbacks != null : !this$callbacks.equals(other$callbacks)) return false;
final Object this$security = this.getSecurity();
final Object other$security = other.getSecurity();
if (this$security == null ? other$security != null : !this$security.equals(other$security)) return false;
final Object this$servers = this.getServers();
final Object other$servers = other.getServers();
if (this$servers == null ? other$servers != null : !this$servers.equals(other$servers)) return false;
return true;
}

protected boolean canEqual(final Object other) {
return other instanceof Operation;
}

public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $tags = this.getTags();
result = result * PRIME + ($tags == null ? 43 : $tags.hashCode());
final Object $summary = this.getSummary();
result = result * PRIME + ($summary == null ? 43 : $summary.hashCode());
final Object $description = this.getDescription();
result = result * PRIME + ($description == null ? 43 : $description.hashCode());
final Object $operationId = this.getOperationId();
result = result * PRIME + ($operationId == null ? 43 : $operationId.hashCode());
final Object $parameters = this.getParameters();
result = result * PRIME + ($parameters == null ? 43 : $parameters.hashCode());
final Object $requestBody = this.getRequestBody();
result = result * PRIME + ($requestBody == null ? 43 : $requestBody.hashCode());
final Object $responses = this.getResponses();
result = result * PRIME + ($responses == null ? 43 : $responses.hashCode());
result = result * PRIME + (this.isDeprecated() ? 79 : 97);
final Object $externalDocs = this.getExternalDocs();
result = result * PRIME + ($externalDocs == null ? 43 : $externalDocs.hashCode());
final Object $callbacks = this.getCallbacks();
result = result * PRIME + ($callbacks == null ? 43 : $callbacks.hashCode());
final Object $security = this.getSecurity();
result = result * PRIME + ($security == null ? 43 : $security.hashCode());
final Object $servers = this.getServers();
result = result * PRIME + ($servers == null ? 43 : $servers.hashCode());
return result;
}

public String toString() {
return "Operation(tags=" + this.getTags() + ", summary=" + this.getSummary() + ", description=" + this.getDescription() + ", operationId=" + this.getOperationId() + ", parameters=" + this.getParameters() + ", requestBody=" + this.getRequestBody() + ", responses=" + this.getResponses() + ", deprecated=" + this.isDeprecated() + ", externalDocs=" + this.getExternalDocs() + ", callbacks=" + this.getCallbacks() + ", security=" + this.getSecurity() + ", servers=" + this.getServers() + ")";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class Path {
// TODO
private List<Parameter> parameters;

public List<String> getTags() {
public List<String> returnTags() {
List<String> result = new ArrayList<>();
if (CollectionUtils.isEmpty(result)) {
if (this.get != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,12 @@ public static BizServer convert(Openapi3 openAPI) {
}
PathItemWrapper wrapper = new PathItemWrapper();
Path pathEntryValue = pathItemEntry.getValue();
List<String> tags = pathEntryValue.getTags();
List<String> tags = pathEntryValue.returnTags();
String serviceName;

/**
* Use second tag as Service class name if it exists, otherwise use first part of the path splitted by back slash.
*/
if (CollectionUtils.isNotEmpty(tags) && tags.size() > 1 && StringUtils.isNotBlank(tags.get(1))) {
serviceName = StringUtils.capitalize(tags.get(1)) + "Service";
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ServiceFolderGeneratorTest {

@Test
public void generate() throws IOException {
try (BufferedInputStream is = new BufferedInputStream(ClassLoader.getSystemResourceAsStream("test.json"))) {
try (BufferedInputStream is = new BufferedInputStream(ClassLoader.getSystemResourceAsStream("test1.json"))) {
BizServer bizServer = ServiceDocParser.parse(is);
ServiceFolderGenerator serviceFolderGenerator = new ServiceFolderGenerator.Builder(bizServer).zip(false).build();
String outputFile = serviceFolderGenerator.generate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ServiceTsGeneratorTest {

@Test
public void generate() throws IOException {
try (BufferedInputStream is = new BufferedInputStream(ClassLoader.getSystemResourceAsStream("petstore3.json"))) {
try (BufferedInputStream is = new BufferedInputStream(ClassLoader.getSystemResourceAsStream("test1.json"))) {
BizServer bizServer = ServiceDocParser.parse(is);
for (BizService bizService : bizServer.getServices()) {
ServiceTsGenerator serviceTsGenerator = new ServiceTsGenerator(bizService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class TypesTsGeneratorTest {

@Test
public void generate() throws IOException {
try (BufferedInputStream is = new BufferedInputStream(ClassLoader.getSystemResourceAsStream("test.json"))) {
try (BufferedInputStream is = new BufferedInputStream(ClassLoader.getSystemResourceAsStream("test1.json"))) {
BizServer bizServer = ServiceDocParser.parse(is);
TypesTsGenerator typesTsGenerator = new TypesTsGenerator(bizServer.getTypes());
String outputFile = typesTsGenerator.generate();
Expand Down

0 comments on commit ed2b397

Please sign in to comment.