Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress Pattern annotation on property of type byte array #19346

Merged
merged 3 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions bin/configs/java-helidon-server-mp_3_format_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
generatorName: java-helidon-server
library: mp
outputDir: samples/server/others/java-helidon-server/v3/mp-format-test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we add the new sample folders to the github workflow so that these will be tested moving forward?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good catch. I'll push another commit right away.

inputSpec: modules/openapi-generator/src/test/resources/3_0/helidon/format-test.yaml
templateDir: modules/openapi-generator/src/main/resources/java-helidon/server
additionalProperties:
helidonVersion: 3.2.7
artifactId: format-helidon-server-mp
hideGenerationTimestamp: "true"
fullProject: "true"
10 changes: 10 additions & 0 deletions bin/configs/java-helidon-server-mp_4_format_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
generatorName: java-helidon-server
library: mp
outputDir: samples/server/others/java-helidon-server/v4/mp-format-test
inputSpec: modules/openapi-generator/src/test/resources/3_0/helidon/format-test.yaml
templateDir: modules/openapi-generator/src/main/resources/java-helidon/server
additionalProperties:
helidonVersion: 4.0.11
artifactId: format-helidon-server-mp
hideGenerationTimestamp: "true"
fullProject: "true"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{#pattern}} @Pattern(regexp="{{{.}}}"){{/pattern}}{{!
{{#pattern}}{{^isByteArray}} @Pattern(regexp="{{{.}}}"){{/isByteArray}}{{/pattern}}{{!
minLength && maxLength set
}}{{#minLength}}{{#maxLength}} @Size(min={{minLength}},max={{maxLength}}){{/maxLength}}{{/minLength}}{{!
minLength set, maxLength not
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
openapi: 3.0.0
servers:
- url: 'http://petstore.helidon.io:8080/format'
info:
description: >-
This spec is mainly for testing Petstore server and contains fake endpoints,
models. Please do not use this for any other purpose. For this sample, you can use the api key
`special-key` to test the authorization filters. Special characters: "
\
version: 1.0.0
title: OpenAPI Petstore
license:
name: Apache-2.0
url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
tags:
- name: format
description: Format tester
paths:
/format:
get:
operationId: simple
responses:
"200":
content: {}
description: success
tags:
- format

components:
schemas:
format_test:
properties:
byte:
format: byte
pattern: "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$"
type: string
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
README.md
pom.xml
src/main/java/org/openapitools/server/JavaTimeFormatter.java
src/main/java/org/openapitools/server/RFC3339DateFormat.java
src/main/java/org/openapitools/server/RestApplication.java
src/main/java/org/openapitools/server/api/FormatService.java
src/main/java/org/openapitools/server/api/FormatServiceImpl.java
src/main/java/org/openapitools/server/model/FormatTest.java
src/main/java/org/openapitools/server/package-info.java
src/main/resources/META-INF/beans.xml
src/main/resources/META-INF/microprofile-config.properties
src/main/resources/META-INF/openapi.yml
src/main/resources/logging.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.8.0-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Helidon Server with OpenAPI

## Build and run

With JDK11+
```bash
mvn package
java -jar target/format-helidon-server-mp.jar
```

## Exercise the application

```
curl -X GET http://petstore.helidon.io:8080/format

```

## Try health and metrics

```
curl -s -X GET http://petstore.helidon.io:8080/format/health
{"outcome":"UP",...
. . .

# Prometheus Format
curl -s -X GET http://petstore.helidon.io:8080/format/metrics
# TYPE base:gc_g1_young_generation_count gauge
. . .

# JSON Format
curl -H 'Accept: application/json' -X GET http://petstore.helidon.io:8080/format/metrics
{"base":...
. . .
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.openapitools</groupId>
<parent>
<groupId>io.helidon.applications</groupId>
<artifactId>helidon-mp</artifactId>
<version>3.2.7</version>
<relativePath/>
</parent>
<artifactId>format-helidon-server-mp</artifactId>
<name>format-helidon-server-mp</name>
<description>This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. For this sample, you can use the api key &#x60;special-key&#x60; to test the authorization filters. Special characters: \&quot; \\</description>
<version>1.0.0</version>
<packaging>jar</packaging>

<properties>
<version.jackson.databind.nullable>0.2.6</version.jackson.databind.nullable>
</properties>

<dependencies>
<dependency>
<groupId>io.helidon.microprofile.bundles</groupId>
<artifactId>helidon-microprofile-core</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.cdi</groupId>
<artifactId>helidon-microprofile-cdi</artifactId>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
<version>${version.jackson.databind.nullable}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.tests</groupId>
<artifactId>helidon-microprofile-tests-junit5</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-libs</id>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jboss.jandex</groupId>
<artifactId>jandex-maven-plugin</artifactId>
<executions>
<execution>
<id>make-index</id>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* OpenAPI Petstore
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. For this sample, you can use the api key `special-key` to test the authorization filters. Special characters: \" \\
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

package org.openapitools.server;

import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

/**
* Class that add parsing/formatting support for Java 8+ {@code OffsetDateTime} class.
* It's generated for java clients when {@code AbstractJavaCodegen#dateLibrary} specified as {@code java8}.
*/
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaHelidonServerCodegen", comments = "Generator version: 7.8.0-SNAPSHOT")
public class JavaTimeFormatter {

private DateTimeFormatter offsetDateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;

/**
* Get the date format used to parse/format {@code OffsetDateTime} parameters.
* @return DateTimeFormatter
*/
public DateTimeFormatter getOffsetDateTimeFormatter() {
return offsetDateTimeFormatter;
}

/**
* Set the date format used to parse/format {@code OffsetDateTime} parameters.
* @param offsetDateTimeFormatter {@code DateTimeFormatter}
*/
public void setOffsetDateTimeFormatter(DateTimeFormatter offsetDateTimeFormatter) {
this.offsetDateTimeFormatter = offsetDateTimeFormatter;
}

/**
* Parse the given string into {@code OffsetDateTime} object.
* @param str String
* @return {@code OffsetDateTime}
*/
public OffsetDateTime parseOffsetDateTime(String str) {
try {
return OffsetDateTime.parse(str, offsetDateTimeFormatter);
} catch (DateTimeParseException e) {
throw new RuntimeException(e);
}
}
/**
* Format the given {@code OffsetDateTime} object into string.
* @param offsetDateTime {@code OffsetDateTime}
* @return {@code OffsetDateTime} in string format
*/
public String formatOffsetDateTime(OffsetDateTime offsetDateTime) {
return offsetDateTimeFormatter.format(offsetDateTime);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* OpenAPI Petstore
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. For this sample, you can use the api key `special-key` to test the authorization filters. Special characters: \" \\
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

package org.openapitools.server;

import com.fasterxml.jackson.databind.util.StdDateFormat;

import java.text.DateFormat;
import java.text.FieldPosition;
import java.text.ParsePosition;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;

public class RFC3339DateFormat extends DateFormat {
private static final long serialVersionUID = 1L;
private static final TimeZone TIMEZONE_Z = TimeZone.getTimeZone("UTC");

private final StdDateFormat fmt = new StdDateFormat()
.withTimeZone(TIMEZONE_Z)
.withColonInTimeZone(true);

public RFC3339DateFormat() {
this.calendar = new GregorianCalendar();
}

@Override
public Date parse(String source, ParsePosition pos) {
return fmt.parse(source, pos);
}

@Override
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
return fmt.format(date, toAppendTo, fieldPosition);
}

@Override
public Object clone() {
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.openapitools.server;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;

@ApplicationScoped
@ApplicationPath("/format")
public class RestApplication extends Application {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* OpenAPI Petstore
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. For this sample, you can use the api key `special-key` to test the authorization filters. Special characters: \" \\
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

package org.openapitools.server.api;


import jakarta.ws.rs.*;

import java.io.InputStream;
import java.util.Map;
import java.util.List;
import jakarta.validation.constraints.*;
import jakarta.validation.Valid;

@Path("/format")
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaHelidonServerCodegen", comments = "Generator version: 7.8.0-SNAPSHOT")
public interface FormatService {

@GET
void simple();
}
Loading
Loading