Skip to content

Commit

Permalink
refactor: adjust the code
Browse files Browse the repository at this point in the history
  • Loading branch information
mathecruz committed Sep 3, 2023
1 parent 5d196a4 commit 1f6920b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ See the module [type-mapping](integration-tests/type-mapping) for an example of
By default the `@RegisterRestClient` `configKey` property is the sanitized name of the file containing the OpenAPI spec. For example, if the file name is `petstore.json`, the `configKey` will be `petstore_json`:

```java
// code omitted for brevity
/* omitted */
@RegisterRestClient(configKey="petstore_json")
public interface DefaultApi { /* omitted */ }
}
Expand All @@ -754,7 +754,7 @@ quarkus.openapi-generator.codegen.spec.petstore.additional-api-type-annotations=
With it you will have the following result:

```java
// code omitted for brevity
/* omitted */
@RegisterRestClient(configKey="petstore")
@org.test.Foo
public interface DefaultApi { /* omitted */ }
Expand All @@ -771,7 +771,7 @@ quarkus.openapi-generator.codegen.spec.petstore_json.additional-api-type-annotat
The generated code will be:

```java
// code omitted for brevity
/* omitted */
@RegisterRestClient(configKey="custom_config_key")
@org.test.Foo
public interface DefaultApi { /* omitted */ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ public static String getSpecConfigName(ConfigName configName, final Path openApi
}

/**
* Return spec config name by config-key openapi-generator.codegen.spec.%s.config-key-property
* For example, given a configuration open-api.generator.codegen.spec.spec_yaml.config-key=petstore, the returned value is
* `open-api.generator.codegen.spec.petstore.mutiny`.
* Return spec config name by config-key (<b>openapi-generator.codegen.spec.%s.config-key</b>) property.
* For example, given a configuration <code>quarkus.openapi.generator.codegen.spec.spec_yaml.config-key=petstore</code>, the
* returned value is
* <code>openapi.generator.codegen.spec.petstore.mutiny</code>.
*/
public static String getSpecConfigNameByConfigKey(final String configKey, final ConfigName configName) {
String buildTimeSpecPropertyPrefix = String.format(BUILD_TIME_SPEC_PREFIX_FORMAT, configKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

import org.eclipse.microprofile.config.Config;
import org.openapitools.codegen.config.GlobalSettings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.quarkiverse.openapi.generator.deployment.CodegenConfig;
import io.quarkiverse.openapi.generator.deployment.circuitbreaker.CircuitBreakerConfigurationParser;
Expand All @@ -48,10 +46,8 @@ public abstract class OpenApiGeneratorCodeGenBase implements CodeGenProvider {
static final String YML = ".yml";
static final String JSON = ".json";

private static final Logger LOGGER = LoggerFactory.getLogger(OpenApiGeneratorCodeGenBase.class);

private static final String DEFAULT_PACKAGE = "org.openapi.quarkus";
private static final String CONFIG_KEY_NAME = "config-key";
private static final String CONFIG_KEY_PROPERTY = "config-key";

/**
* The input base directory from
Expand Down Expand Up @@ -297,13 +293,13 @@ private static <K, V> Optional<Map<K, V>> getValuesByConfigKey(SmallRyeConfig co

private static Optional<String> getConfigKeyValue(Config config, Path openApiFilePath) {
String configKey = String.format("quarkus.openapi-generator.codegen.spec.%s.%s", getSanitizedFileName(openApiFilePath),
CONFIG_KEY_NAME);
CONFIG_KEY_PROPERTY);
return config.getOptionalValue(configKey, String.class);
}

private static Optional<String> getConfigKeyValue(SmallRyeConfig config, Path openApiFilePath) {
String configKey = String.format("quarkus.openapi-generator.codegen.spec.%s.%s", getSanitizedFileName(openApiFilePath),
CONFIG_KEY_NAME);
CONFIG_KEY_PROPERTY);
return config.getOptionalValue(configKey, String.class);
}
}

0 comments on commit 1f6920b

Please sign in to comment.