Skip to content

Commit

Permalink
Merge pull request #1150 from altro3/merg-4.10-3
Browse files Browse the repository at this point in the history
Merge 4.10 Part 3
  • Loading branch information
graemerocher authored Aug 5, 2023
2 parents 9c739b1 + ac5e5ab commit 022ca67
Show file tree
Hide file tree
Showing 46 changed files with 1,824 additions and 1,355 deletions.
2 changes: 2 additions & 0 deletions openapi/openapi-placeholders.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
micronaut.openapi.expand.api.version=2.2.2
micronaut.openapi.expand.another.placeholder.value=monkey
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Class<OpenAPIManagement> annotationType() {
}

@Override
public List<AnnotationValue<?>> map(AnnotationValue<OpenAPIManagement> annotation, VisitorContext visitorContext) {
public List<AnnotationValue<?>> map(AnnotationValue<OpenAPIManagement> annotation, VisitorContext context) {
return Collections.singletonList(
AnnotationValue.builder(OpenAPIInclude.class)
.values(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Class<OpenAPISecurity> annotationType() {
}

@Override
public List<AnnotationValue<?>> map(AnnotationValue<OpenAPISecurity> annotation, VisitorContext visitorContext) {
public List<AnnotationValue<?>> map(AnnotationValue<OpenAPISecurity> annotation, VisitorContext context) {
return Collections.singletonList(
AnnotationValue.builder(OpenAPIInclude.class)
.values(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ abstract class AbstractRetentionPolicyAnnotationTransformer<T extends Annotation
}

@Override
public List<AnnotationValue<?>> transform(AnnotationValue<T> annotation, VisitorContext visitorContext) {
public List<AnnotationValue<?>> transform(AnnotationValue<T> annotation, VisitorContext context) {
return Collections.singletonList(
AnnotationValue.builder(annotation, RetentionPolicy.SOURCE).build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@

import io.micronaut.core.util.StringUtils;
import io.micronaut.inject.visitor.VisitorContext;
import io.micronaut.openapi.visitor.OpenApiApplicationVisitor;
import io.micronaut.openapi.visitor.ConfigUtils;
import io.micronaut.openapi.visitor.Pair;
import io.micronaut.openapi.visitor.Utils;
import io.micronaut.openapi.visitor.group.GroupProperties;
import io.micronaut.openapi.visitor.group.OpenApiInfo;

import static io.micronaut.openapi.visitor.OpenApiApplicationVisitor.getGroupProperties;
import static io.micronaut.openapi.visitor.OpenApiConfigProperty.MICRONAUT_OPENAPI_CONTEXT_SERVER_PATH;
import static io.micronaut.openapi.visitor.OpenApiConfigProperty.MICRONAUT_SERVER_CONTEXT_PATH;
import static io.micronaut.openapi.visitor.ConfigUtils.getGroupProperties;

/**
* Abstract View Config.
Expand Down Expand Up @@ -109,7 +111,7 @@ protected void addAttribute(Map.Entry<String, String> entry) {
*/
protected String toHtmlAttributes() {
return options.entrySet().stream().map(e -> e.getKey() + "=\"" + e.getValue() + '"')
.collect(Collectors.joining(" "));
.collect(Collectors.joining(" "));
}

protected String getFinalUrlPrefix(OpenApiViewConfig.RendererType rendererType, VisitorContext context) {
Expand All @@ -118,7 +120,7 @@ protected String getFinalUrlPrefix(OpenApiViewConfig.RendererType rendererType,
}

// process micronaut.openapi.server.context.path
String serverContextPath = OpenApiApplicationVisitor.getConfigurationProperty(OpenApiApplicationVisitor.MICRONAUT_OPENAPI_CONTEXT_SERVER_PATH, context);
String serverContextPath = ConfigUtils.getConfigProperty(MICRONAUT_OPENAPI_CONTEXT_SERVER_PATH, context);
if (serverContextPath == null) {
serverContextPath = StringUtils.EMPTY_STRING;
}
Expand All @@ -128,7 +130,7 @@ protected String getFinalUrlPrefix(OpenApiViewConfig.RendererType rendererType,
}

// process micronaut.server.context-path
String contextPath = OpenApiApplicationVisitor.getConfigurationProperty(OpenApiApplicationVisitor.MICRONAUT_SERVER_CONTEXT_PATH, context);
String contextPath = ConfigUtils.getConfigProperty(MICRONAUT_SERVER_CONTEXT_PATH, context);
if (contextPath == null) {
contextPath = StringUtils.EMPTY_STRING;
}
Expand Down Expand Up @@ -215,7 +217,7 @@ static <T extends AbstractViewConfig> T fromProperties(T cfg, Map<String, Object
}

cfg.specUrl = specUrl.replace(Utils.PLACEHOLDER_PREFIX + "filename" + Utils.PLACEHOLDER_POSTFIX,
filenameFromContext != null ? filenameFromContext : "");
filenameFromContext != null ? filenameFromContext : "");
}
}

Expand All @@ -237,7 +239,7 @@ static <T extends AbstractViewConfig> T fromProperties(T cfg, Map<String, Object

cfg.options.putAll(defaultOptions);
properties.entrySet().stream().filter(entry -> entry.getKey().startsWith(cfg.prefix))
.forEach(cfg::addAttribute);
.forEach(cfg::addAttribute);
return cfg;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@
import io.micronaut.core.util.CollectionUtils;
import io.micronaut.core.util.StringUtils;
import io.micronaut.inject.visitor.VisitorContext;
import io.micronaut.openapi.visitor.OpenApiApplicationVisitor;
import io.micronaut.openapi.visitor.Pair;
import io.micronaut.openapi.visitor.Utils;
import io.micronaut.openapi.visitor.group.OpenApiInfo;

import static io.micronaut.openapi.visitor.OpenApiApplicationVisitor.MICRONAUT_SERVER_CONTEXT_PATH;
import static io.micronaut.openapi.visitor.OpenApiConfigProperty.MICRONAUT_SERVER_CONTEXT_PATH;
import static io.micronaut.openapi.visitor.ConfigUtils.getConfigProperty;
import static io.micronaut.openapi.visitor.ConfigUtils.getProjectPath;
import static io.micronaut.openapi.visitor.FileUtils.resolve;

/**
* OpenApi view configuration for Swagger-ui, ReDoc and RapiDoc.
Expand Down Expand Up @@ -166,38 +167,38 @@ public boolean isEnabled() {
* Generates the views given this configuration.
*
* @param outputDir The destination directory of the generated views.
* @param visitorContext The visitor context
* @param context The visitor context
*
* @throws IOException When the generation fails.
*/
public void render(Path outputDir, VisitorContext visitorContext) throws IOException {
public void render(Path outputDir, VisitorContext context) throws IOException {
if (redocConfig != null) {
Path redocDir = outputDir.resolve(REDOC);
render(redocConfig, redocDir, TEMPLATES + SLASH + TEMPLATES_REDOC + SLASH + TEMPLATE_INDEX_HTML, visitorContext);
copyResources(redocConfig, redocDir, TEMPLATES_REDOC, redocConfig.getResources(), visitorContext);
render(redocConfig, redocDir, TEMPLATES + SLASH + TEMPLATES_REDOC + SLASH + TEMPLATE_INDEX_HTML, context);
copyResources(redocConfig, redocDir, TEMPLATES_REDOC, redocConfig.getResources(), context);
if (redocConfig.rapiPDFConfig.enabled) {
copyResources(redocConfig.rapiPDFConfig, redocDir, TEMPLATES_RAPIPDF, redocConfig.rapiPDFConfig.getResources(), visitorContext);
copyResources(redocConfig.rapiPDFConfig, redocDir, TEMPLATES_RAPIPDF, redocConfig.rapiPDFConfig.getResources(), context);
}
}
if (rapidocConfig != null) {
Path rapidocDir = outputDir.resolve(RAPIDOC);
render(rapidocConfig, rapidocDir, TEMPLATES + SLASH + TEMPLATES_RAPIDOC + SLASH + TEMPLATE_INDEX_HTML, visitorContext);
copyResources(rapidocConfig, rapidocDir, TEMPLATES_RAPIDOC, rapidocConfig.getResources(), visitorContext);
render(rapidocConfig, rapidocDir, TEMPLATES + SLASH + TEMPLATES_RAPIDOC + SLASH + TEMPLATE_INDEX_HTML, context);
copyResources(rapidocConfig, rapidocDir, TEMPLATES_RAPIDOC, rapidocConfig.getResources(), context);
if (rapidocConfig.rapiPDFConfig.enabled) {
copyResources(rapidocConfig.rapiPDFConfig, rapidocDir, TEMPLATES_RAPIPDF, rapidocConfig.rapiPDFConfig.getResources(), visitorContext);
copyResources(rapidocConfig.rapiPDFConfig, rapidocDir, TEMPLATES_RAPIPDF, rapidocConfig.rapiPDFConfig.getResources(), context);
}
}
if (swaggerUIConfig != null) {
Path swaggerUiDir = outputDir.resolve(SWAGGER_UI);
render(swaggerUIConfig, swaggerUiDir, TEMPLATES + SLASH + TEMPLATES_SWAGGER_UI + SLASH + TEMPLATE_INDEX_HTML, visitorContext);
render(swaggerUIConfig, swaggerUiDir, TEMPLATES + SLASH + TEMPLATES_SWAGGER_UI + SLASH + TEMPLATE_INDEX_HTML, context);
if (SwaggerUIConfig.hasOauth2Option(swaggerUIConfig.options)) {
render(swaggerUIConfig, swaggerUiDir, TEMPLATES + SLASH + TEMPLATES_SWAGGER_UI + SLASH + TEMPLATE_OAUTH_2_REDIRECT_HTML, visitorContext);
render(swaggerUIConfig, swaggerUiDir, TEMPLATES + SLASH + TEMPLATES_SWAGGER_UI + SLASH + TEMPLATE_OAUTH_2_REDIRECT_HTML, context);
}
copyResources(swaggerUIConfig, swaggerUiDir, TEMPLATES_SWAGGER_UI, swaggerUIConfig.getResources(), visitorContext);
copyResources(swaggerUIConfig, swaggerUiDir, TEMPLATES_SWAGGER_UI, swaggerUIConfig.getResources(), context);
if (swaggerUIConfig.rapiPDFConfig.enabled) {
copyResources(swaggerUIConfig.rapiPDFConfig, swaggerUiDir, TEMPLATES_RAPIPDF, swaggerUIConfig.rapiPDFConfig.getResources(), visitorContext);
copyResources(swaggerUIConfig.rapiPDFConfig, swaggerUiDir, TEMPLATES_RAPIPDF, swaggerUIConfig.rapiPDFConfig.getResources(), context);
}
copySwaggerUiTheme(swaggerUIConfig, swaggerUiDir, TEMPLATES_SWAGGER_UI, visitorContext);
copySwaggerUiTheme(swaggerUIConfig, swaggerUiDir, TEMPLATES_SWAGGER_UI, context);
}
}

Expand Down Expand Up @@ -285,7 +286,7 @@ private String readTemplateFromClasspath(String templateName) throws IOException

private String readTemplateFromCustomPath(String customPathStr, VisitorContext context) throws IOException {
String projectDir = StringUtils.EMPTY_STRING;
Path projectPath = Utils.getProjectPath(context);
Path projectPath = getProjectPath(context);
if (projectPath != null) {
projectDir = projectPath.toString().replaceAll("\\\\", "/");
}
Expand Down Expand Up @@ -316,7 +317,7 @@ private String readTemplateFromCustomPath(String customPathStr, VisitorContext c
}
}

Path templatePath = OpenApiApplicationVisitor.resolve(context, Paths.get(customPathStr));
Path templatePath = resolve(context, Paths.get(customPathStr));
if (!Files.isReadable(templatePath)) {
throw new IOException("Can't read file " + customPathStr);
}
Expand Down Expand Up @@ -410,7 +411,7 @@ public String getSpecURL(AbstractViewConfig cfg, VisitorContext context) {

String specUrl = StringUtils.prependUri(serverContextPath, StringUtils.prependUri(mappingPath, specFile));
if (StringUtils.isEmpty(serverContextPath)) {
String contextPath = OpenApiApplicationVisitor.getConfigurationProperty(MICRONAUT_SERVER_CONTEXT_PATH, context);
String contextPath = getConfigProperty(MICRONAUT_SERVER_CONTEXT_PATH, context);
if (contextPath == null) {
contextPath = StringUtils.EMPTY_STRING;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,13 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;

import static io.micronaut.openapi.visitor.ConfigUtils.getGroupsPropertiesMap;
import static io.micronaut.openapi.visitor.ConfigUtils.getRouterVersioningProperties;
import static io.micronaut.openapi.visitor.ConfigUtils.getSecurityProperties;
import static io.micronaut.openapi.visitor.ConfigUtils.isJsonViewEnabled;
import static io.micronaut.openapi.visitor.ConfigUtils.isOpenApiEnabled;
import static io.micronaut.openapi.visitor.ElementUtils.isFileUpload;
import static io.micronaut.openapi.visitor.ElementUtils.isNullable;
import static io.micronaut.openapi.visitor.OpenApiApplicationVisitor.getGroupsPropertiesMap;
import static io.micronaut.openapi.visitor.OpenApiApplicationVisitor.getSecurityProperties;
import static io.micronaut.openapi.visitor.OpenApiApplicationVisitor.isJsonViewEnabled;
import static io.micronaut.openapi.visitor.OpenApiApplicationVisitor.isOpenApiEnabled;
import static io.micronaut.openapi.visitor.SchemaUtils.COMPONENTS_CALLBACKS_PREFIX;
import static io.micronaut.openapi.visitor.SchemaUtils.COMPONENTS_SCHEMAS_PREFIX;
import static io.micronaut.openapi.visitor.SchemaUtils.TYPE_OBJECT;
Expand Down Expand Up @@ -1824,7 +1825,7 @@ private void processMicronautVersionAndGroup(io.swagger.v3.oas.models.Operation
}
}

RouterVersioningProperties versioningProperties = OpenApiApplicationVisitor.getRouterVersioningProperties(context);
RouterVersioningProperties versioningProperties = getRouterVersioningProperties(context);
boolean isVersioningEnabled = versioningProperties.isEnabled() && versioningProperties.isRouterVersiningEnabled()
&& (versioningProperties.isHeaderEnabled() || versioningProperties.isParameterEnabled());

Expand Down
Loading

0 comments on commit 022ca67

Please sign in to comment.