-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(api): Springfox to openapi migration
- Loading branch information
1 parent
6990217
commit 0839c7b
Showing
59 changed files
with
831 additions
and
733 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
openrouteservice/src/main/java/org/heigit/ors/api/OpenApiConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* This file is part of Openrouteservice. | ||
* | ||
* Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the | ||
* GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License along with this library; | ||
* if not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.heigit.ors.api; | ||
|
||
import io.swagger.v3.oas.models.OpenAPI; | ||
import io.swagger.v3.oas.models.SpecVersion; | ||
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 io.swagger.v3.oas.models.servers.Server; | ||
import org.heigit.ors.config.AppConfig; | ||
import org.springdoc.core.GroupedOpenApi; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import javax.servlet.ServletContext; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Configuration | ||
public class OpenApiConfiguration { | ||
|
||
private static final String SERVICE_NAME = "Openrouteservice"; | ||
String swaggerDocumentationUrl = AppConfig.getGlobal().getParameter("info", "swagger_documentation_url"); | ||
String swaggerDocumentationAddAutogeneratedUrl = AppConfig.getGlobal().getParameter("info", "swagger_documentation_add_autogenerated_url"); | ||
|
||
@Bean | ||
public OpenAPI customOpenAPI(ServletContext servletContext) { | ||
return new OpenAPI(SpecVersion.V31) | ||
.servers(generateServers(servletContext)) | ||
.info(apiInfo()); | ||
} | ||
|
||
/** | ||
* This gives a properly versioned swagger endpoint at api-docs/v2 for the ors v2 version. | ||
* To introduce, e.g., v3 just use this function and replace v2 with v3. | ||
*/ | ||
@Bean | ||
public GroupedOpenApi orsV2ApiPath() { | ||
String[] paths = {"/v2/**"}; | ||
return GroupedOpenApi.builder().group("v2").pathsToMatch(paths) | ||
.build(); | ||
} | ||
|
||
/** | ||
* This function provides the API v2 at the root api-docs/ path, as this was the old path of service the swagger. | ||
* For proper API versioning see orsV2ApiPath(). | ||
*/ | ||
@Bean | ||
public GroupedOpenApi oldOrsV2ApiPath() { | ||
String[] paths = {"/v2/**"}; | ||
return GroupedOpenApi.builder().group("").pathsToMatch(paths) | ||
.build(); | ||
} | ||
|
||
private List<Server> generateServers(ServletContext servletContext) { | ||
ArrayList<Server> listOfServers = new ArrayList<>(); | ||
if (swaggerDocumentationUrl != null) { | ||
Server customApi = new Server().url(swaggerDocumentationUrl).description("Custom server url"); | ||
listOfServers.add(customApi); | ||
} | ||
if (Boolean.parseBoolean(swaggerDocumentationAddAutogeneratedUrl)) { | ||
Server localhostServer = new Server().url(servletContext.getContextPath()).description("Auto generated server url"); | ||
listOfServers.add(localhostServer); | ||
} | ||
return listOfServers; | ||
} | ||
|
||
private Info apiInfo() { | ||
return new Info() | ||
.title(SERVICE_NAME) | ||
.description("This is the openrouteservice API documentation") | ||
.version("2") | ||
.contact(apiContact()) | ||
.license(apiLicence()); | ||
} | ||
|
||
private License apiLicence() { | ||
return new License() | ||
.name("MIT Licence") | ||
.url("https://opensource.org/licenses/mit-license.php"); | ||
} | ||
|
||
private Contact apiContact() { | ||
return new Contact() | ||
.name(SERVICE_NAME) | ||
.email("enquiry@openrouteservice.heigit.org") | ||
.url("https://github.com/GIScience/openrouteservice"); | ||
} | ||
} | ||
|
110 changes: 0 additions & 110 deletions
110
openrouteservice/src/main/java/org/heigit/ors/api/SwaggerConfig.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.