Skip to content

Commit

Permalink
Merge pull request #268 from seart-group/refactoring/openapi
Browse files Browse the repository at this point in the history
  • Loading branch information
dabico authored Dec 30, 2023
2 parents bb3d5bc + dc6306c commit 0344c19
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 25 deletions.
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<licenses>
<license>
<name>MIT License</name>
<url>https://github.com/seart-group/ghs/blob/master/LICENSE</url>
<url>https://raw.githubusercontent.com/seart-group/ghs/master/LICENSE</url>
</license>
</licenses>

Expand All @@ -36,6 +36,7 @@
<id>dabico</id>
<name>Ozren Dabić</name>
<email>ozren.dabic@usi.ch</email>
<url>https://dabico.github.io/</url>
<organization>SEART</organization>
<organizationUrl>https://seart.si.usi.ch/</organizationUrl>
</developer>
Expand All @@ -45,18 +46,21 @@
<contributor>
<name>Emad Aghajani</name>
<email>emad.aghajani@usi.ch</email>
<url>https://emadpres.github.io/</url>
<organization>SEART</organization>
<organizationUrl>https://seart.si.usi.ch/</organizationUrl>
</contributor>
<contributor>
<name>Gabriele Bavota</name>
<email>gabriele.bavota@usi.ch</email>
<url>https://www.inf.usi.ch/faculty/bavota/</url>
<organization>SEART</organization>
<organizationUrl>https://seart.si.usi.ch/</organizationUrl>
</contributor>
<contributor>
<name>Csaba Nagy</name>
<email>csaba.nagy@usi.ch</email>
<url>https://csnagy.github.io/</url>
<organization>REVEAL</organization>
<organizationUrl>https://reveal.si.usi.ch/</organizationUrl>
</contributor>
Expand Down
52 changes: 28 additions & 24 deletions src/main/java/ch/usi/si/seart/config/OpenAPIConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,49 @@
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import lombok.AccessLevel;
import lombok.experimental.FieldDefaults;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.info.BuildProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.ConversionService;

import java.util.Arrays;

@Configuration
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
public class OpenAPIConfig {

String title;
String description;
String version;
License license;
Contact contact;

// TODO: 10.04.23 Update this once they enable support for multiple licenses and/or contacts
@SuppressWarnings("ConstantConditions")
@Autowired
public OpenAPIConfig(BuildProperties buildProperties, ConversionService conversionService) {
this.title = buildProperties.get("name");
this.description = buildProperties.get("description");
this.version = buildProperties.get("version");
License[] licenses = conversionService.convert(buildProperties.get("licenses"), License[].class);
Contact[] contacts = conversionService.convert(buildProperties.get("developers"), Contact[].class);
this.license = (licenses.length > 0) ? licenses[0] : null;
this.contact = (contacts.length > 0) ? contacts[0] : null;
@Bean
public OpenAPI openAPI(Info info) {
return new OpenAPI().info(info);
}

@Bean
public OpenAPI openAPI() {
Info info = new Info()
Info info(BuildProperties buildProperties, Contact contact, License license) {
String title = buildProperties.get("name");
String description = buildProperties.get("description");
String version = buildProperties.get("version");
return new Info()
.title(title)
.description(description)
.version(version)
.contact(contact)
.license(license);
return new OpenAPI().info(info);
}

@Bean
@SuppressWarnings("ConstantConditions")
Contact contact(BuildProperties buildProperties, ConversionService conversionService) {
Contact[] contacts = conversionService.convert(buildProperties.get("developers"), Contact[].class);
return Arrays.stream(contacts)
.findFirst()
.orElse(new Contact());
}

@Bean
@SuppressWarnings("ConstantConditions")
License license(BuildProperties buildProperties, ConversionService conversionService) {
License[] licenses = conversionService.convert(buildProperties.get("licenses"), License[].class);
return Arrays.stream(licenses)
.findFirst()
.orElse(new License());
}
}
15 changes: 15 additions & 0 deletions src/main/java/ch/usi/si/seart/dto/SearchParameterDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Range;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -112,58 +113,72 @@ public Map<String, Object> toParameterMap() {
return parameters;
}

@Schema(hidden = true)
public Range<Long> getCommits() {
return Ranges.closed(commitsMin, commitsMax);
}

@Schema(hidden = true)
public Range<Long> getContributors() {
return Ranges.closed(contributorsMin, contributorsMax);
}

@Schema(hidden = true)
public Range<Long> getIssues() {
return Ranges.closed(issuesMin, issuesMax);
}

@Schema(hidden = true)
public Range<Long> getPulls() {
return Ranges.closed(pullsMin, pullsMax);
}

@Schema(hidden = true)
public Range<Long> getBranches() {
return Ranges.closed(branchesMin, branchesMax);
}

@Schema(hidden = true)
public Range<Long> getReleases() {
return Ranges.closed(releasesMin, releasesMax);
}

@Schema(hidden = true)
public Range<Long> getStars() {
return Ranges.closed(starsMin, starsMax);
}

@Schema(hidden = true)
public Range<Long> getWatchers() {
return Ranges.closed(watchersMin, watchersMax);
}

@Schema(hidden = true)
public Range<Long> getForks() {
return Ranges.closed(forksMin, forksMax);
}

@Schema(hidden = true)
public Range<Date> getCreated() {
return Ranges.closed(createdMin, createdMax);
}

@Schema(hidden = true)
public Range<Date> getCommitted() {
return Ranges.closed(committedMin, committedMax);
}

@Schema(hidden = true)
public Range<Long> getCodeLines() {
return Ranges.closed(codeLinesMin, codeLinesMax);
}

@Schema(hidden = true)
public Range<Long> getCommentLines() {
return Ranges.closed(commentLinesMin, commentLinesMax);
}

@Schema(hidden = true)
public Range<Long> getNonBlankLines() {
return Ranges.closed(nonBlankLinesMin, nonBlankLinesMax);
}
Expand Down

0 comments on commit 0344c19

Please sign in to comment.