io.swagger.swaggerhub.plugin.services.DefinitionFileFormat Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swaggerhub-maven-plugin
Show all versions of swaggerhub-maven-plugin
A maven plugin for downloading and uploading Swagger/OAS definitions from/to SwaggerHub as
part of a build process.
package io.swagger.swaggerhub.plugin.services;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.util.Json;
import io.swagger.util.Yaml;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
/**
* Accepted file formats for API definition upload
*/
public enum DefinitionFileFormat {
JSON(Json.mapper(), Arrays.asList("json"), "json", "JSON (Unresolved)"),
YAML(Yaml.mapper(), Arrays.asList("yaml", "yml"), "yaml", "YAML (Unresolved)");
private final String fileFormat;
private ObjectMapper mapper;
private List supportedFileExtensions;
private String languageTarget;
DefinitionFileFormat(ObjectMapper mapper, List supportedFileExtensions, String fileFormat, String languageTarget) {
this.mapper = mapper;
this.supportedFileExtensions = supportedFileExtensions;
this.fileFormat = fileFormat;
this.languageTarget = languageTarget;
}
public ObjectMapper getMapper() {
return mapper;
}
public String getFileFormat() {
return fileFormat;
}
public List getSupportedFileExtensions() {
return supportedFileExtensions;
}
public String getLanguageTarget() {
return languageTarget;
}
public static Optional getByFileExtensionType(String value){
return EnumSet.allOf(DefinitionFileFormat.class).stream()
.filter(isFileExtensionSupportedForFileFormat(value))
.findFirst();
}
private static Predicate isFileExtensionSupportedForFileFormat(String fileExtension) {
return definitionFileFormat -> definitionFileFormat.getSupportedFileExtensions().contains(fileExtension);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy