Skip to content

Commit

Permalink
Support ~/workspace/quarkus-openapi-generator on RegisterRestClient#c…
Browse files Browse the repository at this point in the history
…onfigKey
  • Loading branch information
mcruzdev committed Dec 26, 2024
1 parent 6553a9e commit 8c3b24d
Show file tree
Hide file tree
Showing 5 changed files with 315 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public final class OpenApiConfigValidator {
private static final Logger LOGGER = LoggerFactory.getLogger(OpenApiConfigValidator.class);

static final Pattern CONFIG_PATTERN = Pattern.compile(
"quarkus\\.openapi-generator\\.codegen\\.(spec.(?<specId>\\w*)\\.)?(?<configName>[A-Za-z0-9_\\-]*)\\.?(?<configMap>.+)?");
"quarkus\\.openapi-generator\\.codegen\\.(spec.(?<specId>[\\w\\-]*)\\.)?(?<configName>[A-Za-z0-9_\\-]*)\\.?(?<configMap>.+)?");

private OpenApiConfigValidator() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import org.openapitools.codegen.DefaultGenerator;
import org.openapitools.codegen.config.GlobalSettings;

import io.smallrye.config.common.utils.StringUtil;

/**
* Wrapper for the OpenAPIGen tool.
* This is the same as calling the Maven plugin or the CLI.
Expand Down Expand Up @@ -356,11 +354,15 @@ private void consolidatePackageNames() {

public void withConfigKey(final String config) {
if (config != null && !config.isBlank()) {
this.configurator.addAdditionalProperty("configKey", StringUtil.replaceNonAlphanumericByUnderscores(config));
this.configurator.addAdditionalProperty("configKey", transformToSafeConfigKey(config));
}
}

public void withAdditionalPropertiesAsAttribute(final Boolean enable) {
this.configurator.addAdditionalProperty("additionalPropertiesAsAttribute", Optional.ofNullable(enable).orElse(FALSE));
}

public static String transformToSafeConfigKey(String input) {
return input.replaceAll("[^a-zA-Z0-9\\-_]", "_");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
---
openapi: 3.0.3
info:
title: greeting-flow API
version: "1.0"
paths:
/:
post:
requestBody:
content:
'*/*':
schema:
$ref: '#/components/schemas/CloudEvent'
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Response'
/hello:
get:
tags:
- Reactive Greeting Resource
operationId: hello
responses:
"200":
description: OK
content:
text/plain:
schema:
type: string
/messaging/topics:
get:
tags:
- Quarkus Topics Information Resource
responses:
"200":
description: OK
components:
schemas:
CloudEvent:
type: object
properties:
specVersion:
$ref: '#/components/schemas/SpecVersion'
id:
type: string
type:
type: string
source:
format: uri
type: string
dataContentType:
type: string
dataSchema:
format: uri
type: string
subject:
type: string
time:
format: date-time
type: string
attributeNames:
uniqueItems: true
type: array
items:
type: string
extensionNames:
uniqueItems: true
type: array
items:
type: string
data:
$ref: '#/components/schemas/CloudEventData'
CloudEventData:
type: object
EntityTag:
type: object
properties:
value:
type: string
weak:
type: boolean
Family:
enum:
- INFORMATIONAL
- SUCCESSFUL
- REDIRECTION
- CLIENT_ERROR
- SERVER_ERROR
- OTHER
type: string
Link:
type: object
properties:
uri:
format: uri
type: string
uriBuilder:
$ref: '#/components/schemas/UriBuilder'
rel:
type: string
rels:
type: array
items:
type: string
title:
type: string
type:
type: string
params:
type: object
additionalProperties:
type: string
Locale:
type: object
properties:
language:
type: string
script:
type: string
country:
type: string
variant:
type: string
extensionKeys:
uniqueItems: true
type: array
items:
format: byte
type: string
unicodeLocaleAttributes:
uniqueItems: true
type: array
items:
type: string
unicodeLocaleKeys:
uniqueItems: true
type: array
items:
type: string
iSO3Language:
type: string
iSO3Country:
type: string
displayLanguage:
type: string
displayScript:
type: string
displayCountry:
type: string
displayVariant:
type: string
displayName:
type: string
MediaType:
type: object
properties:
type:
type: string
subtype:
type: string
parameters:
type: object
additionalProperties:
type: string
wildcardType:
type: boolean
wildcardSubtype:
type: boolean
MultivaluedMapStringObject:
type: object
additionalProperties:
type: array
items:
type: object
MultivaluedMapStringString:
type: object
additionalProperties:
type: array
items:
type: string
NewCookie:
type: object
properties:
name:
type: string
value:
type: string
version:
format: int32
type: integer
path:
type: string
domain:
type: string
comment:
type: string
maxAge:
format: int32
type: integer
expiry:
format: date
type: string
secure:
type: boolean
httpOnly:
type: boolean
Response:
type: object
properties:
status:
format: int32
type: integer
statusInfo:
$ref: '#/components/schemas/StatusType'
entity:
type: object
mediaType:
$ref: '#/components/schemas/MediaType'
language:
$ref: '#/components/schemas/Locale'
length:
format: int32
type: integer
allowedMethods:
uniqueItems: true
type: array
items:
type: string
cookies:
type: object
additionalProperties:
$ref: '#/components/schemas/NewCookie'
entityTag:
$ref: '#/components/schemas/EntityTag'
date:
format: date
type: string
lastModified:
format: date
type: string
location:
format: uri
type: string
links:
uniqueItems: true
type: array
items:
$ref: '#/components/schemas/Link'
metadata:
$ref: '#/components/schemas/MultivaluedMapStringObject'
headers:
$ref: '#/components/schemas/MultivaluedMapStringObject'
stringHeaders:
$ref: '#/components/schemas/MultivaluedMapStringString'
SpecVersion:
enum:
- V03
- V1
type: string
StatusType:
type: object
properties:
statusCode:
format: int32
type: integer
family:
$ref: '#/components/schemas/Family'
reasonPhrase:
type: string
UriBuilder:
type: object
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ quarkus.openapi-generator.codegen.spec.empty_config_key_yaml.config-key=
quarkus.openapi-generator.codegen.spec.empty_config_key_yaml.additional-api-type-annotations=@io.quarkiverse.openapi.generator.configkey.CustomAnnotation
quarkus.rest-client.empty_config_key_yaml.url=http://localhost:8080

quarkus.keycloak.devservices.enabled=false
quarkus.keycloak.devservices.enabled=false

# config-key with `-`
quarkus.openapi-generator.codegen.spec.config_key_with_dash_yaml.config-key=my-api
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.quarkiverse.openapi.generator.configkey;

import static org.assertj.core.api.Assertions.assertThat;

import jakarta.inject.Inject;

import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.junit.jupiter.api.Test;
import org.openapi.quarkus.config_key_with_dash_yaml.api.DefaultApi;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
class QuarkusConfigKeyWithDashOpenApiTest {

@RestClient
@Inject
DefaultApi defaultApi;

@Test
void apiIsBeingGenerated() {
assertThat(defaultApi).isNotNull();
}

@Test
void config_key_should_have_dash() {
assertThat(DefaultApi.class.getAnnotation(RegisterRestClient.class)).isNotNull();
assertThat(DefaultApi.class.getAnnotation(RegisterRestClient.class).configKey()).isEqualTo("my-api");
}
}

0 comments on commit 8c3b24d

Please sign in to comment.