Skip to content

Commit

Permalink
Integrate openapi-to-adoc with annotation processor. Fixed typos
Browse files Browse the repository at this point in the history
  • Loading branch information
altro3 committed Oct 1, 2023
1 parent 978cc4e commit a87925d
Show file tree
Hide file tree
Showing 126 changed files with 389 additions and 4,347 deletions.
4 changes: 2 additions & 2 deletions MAINTAINING.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ The consequence of having both approaches in place is that we get multiple depen
`micronaut-build` via our automation, and one or many (one per dependency) created by Renovate. When merging those, it
is better to prefer the `micronaut-build` ones, if possible, for 2 reasons: a) they attempt to upgrade multiple dependencies
in a single PR, which creates less noise in the Git history; b) Once you merge that, Renovate will react and automatically
close its own PRs if the dependecy is up-to-date.
close its own PRs if the dependency is up-to-date.

When an upgrade to a new version arrives, we need to be careful when merging, so that we don't introduce an
unnecessary upgrade burden on our users. Read the
Expand Down Expand Up @@ -162,7 +162,7 @@ First of all, all the repos have an automatic changelog generation mechanism: wh
release notes will contain pull requests merged and issues closed since the last release.

When the module is ready for a new release, check the generated release notes, and make changes if needed (for example,
you can add an introduction paragraph highligting some items included in the release). If the version you are going to
you can add an introduction paragraph highlighting some items included in the release). If the version you are going to
publish is not a new patch version, but a new minor or major, update the release notes text to reflect the new version.
If you are publishing a milestone or release candidate, check the pre-release checkbox.

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package io.micronaut.openapi.adoc;

/**
* Configuration propertis for Openapi-to-adoc converter.
* Configuration properties for Openapi-to-adoc converter.
*
* @since 5.2.0
*/
Expand All @@ -25,29 +25,29 @@ public interface OpenApiToAdocConfigProperty {
/**
* Prefix for custom sub-template names.
*/
String MICRONAUT_OPENAPI_ADOC_TEMPLATE_PREFIX = "micronaut.openapi.adoc.template.";
String MICRONAUT_OPENAPI_ADOC_TEMPLATE_PREFIX = "micronaut.openapi.adoc.templates.";
/**
* Is convertion to Asciidoc enabled.
* Is conversion to Asciidoc enabled.
*/
String MICRONAUT_OPENAPI_ADOC_ENABLED = "micronaut.openapi.adoc.enabled";
/**
* Custom template directory.
*/
String MICRONAUT_OPENAPI_ADOC_TEMPLATES_DIR_PATH = "micronaut.openapi.adoc.template-dir";
String MICRONAUT_OPENAPI_ADOC_TEMPLATES_DIR_PATH = "micronaut.openapi.adoc.template.dir";
/**
* Custom final template filename.
*/
String MICRONAUT_OPENAPI_ADOC_TEMPLATE_FILENAME = "micronaut.openapi.adoc.template-filename";
String MICRONAUT_OPENAPI_ADOC_TEMPLATE_FILENAME = "micronaut.openapi.adoc.template.filename";
/**
* Result adoc file output directory.
*/
String MICRONAUT_OPENAPI_ADOC_OUTPUT_DIR_PATH = "micronaut.openapi.adoc.output-dir";
String MICRONAUT_OPENAPI_ADOC_OUTPUT_DIR_PATH = "micronaut.openapi.adoc.output.dir";
/**
* Result adoc filename.
*/
String MICRONAUT_OPENAPI_ADOC_OUTPUT_FILENAME = "micronaut.openapi.adoc.output-filename";
String MICRONAUT_OPENAPI_ADOC_OUTPUT_FILENAME = "micronaut.openapi.adoc.output.filename";
/**
* OpenAPI file path.
*/
String MICRONAUT_OPENAPI_ADOC_OPENAPI_PATH = "micronaut.openapi.adoc.openapi-path";
String MICRONAUT_OPENAPI_ADOC_OPENAPI_PATH = "micronaut.openapi.adoc.openapi.path";
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Map;

import io.micronaut.openapi.OpenApiUtils;
import io.micronaut.openapi.adoc.md.MdToAdocConverter;
import io.micronaut.openapi.adoc.utils.SwaggerUtils;
import io.swagger.v3.oas.models.OpenAPI;

Expand Down Expand Up @@ -71,7 +72,7 @@ private OpenApiToAdocConverter() {
}

/**
* Convertion from openAPI format to asciidoc format.
* Conversion from openAPI format to asciidoc format.
*
* @throws TemplateException som problems with freemarker templates
* @throws IOException some problems with files
Expand Down Expand Up @@ -101,7 +102,7 @@ public static void convert() throws TemplateException, IOException {
}

/**
* Convertion from openAPI format to asciidoc format.
* Conversion from openAPI format to asciidoc format.
*
* @param openApi openAPI object
* @param props converter config properties
Expand All @@ -112,6 +113,8 @@ public static void convert() throws TemplateException, IOException {
*/
public static void convert(OpenAPI openApi, Map props, Writer writer) throws TemplateException, IOException {

MdToAdocConverter.convert(openApi);

var model = new HashMap<String, Object>();
model.put("info", openApi.getInfo());
model.put("externalDocs", openApi.getExternalDocs());
Expand Down Expand Up @@ -164,7 +167,8 @@ private static Configuration getFreemarkerConfig(String[] customTemplatesDirs) t
if (customTemplatesDirs != null && customTemplatesDirs.length > 0) {
var templateLoaders = new ArrayList<TemplateLoader>();
for (var templateDir : customTemplatesDirs) {
templateDir = templateDir.strip();
templateDir = templateDir.strip()
.replace("\\", "/");
if (templateDir.startsWith(CLASSPATH_SCHEME)) {
templateLoaders.add(new ClassTemplateLoader(OpenApiToAdocConverter.class, templateDir.substring(CLASSPATH_SCHEME.length())));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.pegdown.ast.RootNode;

/**
* Convert-methods from MD fromat to AsciiDoc.
* Convert-methods from MD format to AsciiDoc.
*
* @since 5.2.0
*/
Expand Down Expand Up @@ -133,9 +133,13 @@ public static void convert(OpenAPI openApi) {
processParameters(openApi.getComponents().getParameters().values());
}
processExamples(openApi.getComponents().getExamples());
processRequestBodies(openApi.getComponents().getRequestBodies().values());
if (CollectionUtils.isNotEmpty(openApi.getComponents().getRequestBodies())) {
processRequestBodies(openApi.getComponents().getRequestBodies().values());
}
processHeaders(openApi.getComponents().getHeaders());
processSecuritySchemas(openApi.getComponents().getSecuritySchemes().values());
if (CollectionUtils.isNotEmpty(openApi.getComponents().getSecuritySchemes())) {
processSecuritySchemas(openApi.getComponents().getSecuritySchemes().values());
}
processLinks(openApi.getComponents().getLinks());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<#list paths as pathsStr, path>
<#list path.readOperationsMap() as method, operation>

=== __${method}__ `${pathsStr}` ${operation.getSummary()?trim}
=== __${method}__ `${pathsStr}`<#if operation.getSummary()?has_content> ${operation.getSummary()?trim}</#if>
<#if operation.getDescription()?has_content>
${operation.getDescription()?trim}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ paths:
tags:
- pet
summary: Finds Pets by tags
description: Muliple tags can be provided with comma seperated strings. Use tag1,
description: Multiple tags can be provided with comma seperated strings. Use tag1,
tag2, tag3 for testing.
operationId: findPetsByTags
parameters:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@
*/
package io.micronaut.openapi;

import java.util.Map;

import io.micronaut.core.annotation.Internal;
import io.micronaut.openapi.swagger.core.util.ObjectMapperFactory;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import io.micronaut.core.annotation.Internal;
import io.micronaut.openapi.swagger.core.util.ObjectMapperFactory;

/**
* Convert utilities methods.
Expand All @@ -33,22 +29,20 @@
@Internal
public final class OpenApiUtils {

private static final TypeReference<Map<String, Object>> MAP_TYPE_REFERENCE = new TypeReference<>() {
};
/**
* The JSON mapper.
*/
private static final ObjectMapper JSON_MAPPER = ObjectMapperFactory.createJson()
public static final ObjectMapper JSON_MAPPER = ObjectMapperFactory.createJson()
.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
/**
* The JSON 3.1 mapper.
*/
private static final ObjectMapper JSON_MAPPER_31 = ObjectMapperFactory.createJson31()
public static final ObjectMapper JSON_MAPPER_31 = ObjectMapperFactory.createJson31()
.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
/**
* The JSON mapper for security scheme.
*/
private static final ObjectMapper CONVERT_JSON_MAPPER = ObjectMapperFactory.buildStrictGenericObjectMapper()
public static final ObjectMapper CONVERT_JSON_MAPPER = ObjectMapperFactory.buildStrictGenericObjectMapper()
.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING)
.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS, SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Paths deserialize(JsonParser jp, DeserializationContext ctxt)
for (Iterator<String> it = objectNode.fieldNames(); it.hasNext(); ) {
String childName = it.next();
JsonNode child = objectNode.get(childName);
// if name start with `x-` consider it an extesion
// if name start with `x-` consider it an extension
if (childName.startsWith("x-")) {
extensions.put(childName, mapper.convertValue(child, Object.class));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ components:
schemas:
BookInfo:
title: Book Info # <1>
description: Object containg all the info about a book
description: Object contains all the info about a book
type: object
properties: # <2>
name: {type: string}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ components:
schemas:
BookInfo:
title: Book Info # <1>
description: Object containg all the info about a book
description: Object contains all the info about a book
type: object
properties: # <2>
name: {type: string}
Expand Down

This file was deleted.

Loading

0 comments on commit a87925d

Please sign in to comment.