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

Correct handling of new properties added for OpenAPI 3.1 #30513

Open
wants to merge 3 commits into
base: integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions dev/cnf/dependabot/check_this_in_if_it_changes/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>jandex</artifactId>
<version>3.2.0</version>
<version>3.2.3</version>
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
Expand Down Expand Up @@ -1244,7 +1244,7 @@
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-open-api-core</artifactId>
<version>4.0.2</version>
<version>4.0.6</version>
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
Expand All @@ -1254,12 +1254,12 @@
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-open-api-jaxrs</artifactId>
<version>4.0.2</version>
<version>4.0.6</version>
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-open-api-model</artifactId>
<version>4.0.2</version>
<version>4.0.6</version>
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
Expand Down
8 changes: 4 additions & 4 deletions dev/cnf/oss_dependencies.maven
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ io.smallrye.reactive:mutiny:2.5.6
io.smallrye.reactive:smallrye-reactive-converter-api:3.0.1
io.smallrye.reactive:smallrye-reactive-messaging-api:4.16.0
io.smallrye.reactive:smallrye-reactive-messaging-provider:4.16.0
io.smallrye:jandex:3.2.0
io.smallrye:jandex:3.2.3
io.smallrye:smallrye-graphql-api:1.0.26
io.smallrye:smallrye-graphql-cdi:1.0.26
io.smallrye:smallrye-graphql-client-api:1.0.26
Expand All @@ -244,10 +244,10 @@ io.smallrye:smallrye-graphql-servlet:1.0.26
io.smallrye:smallrye-graphql:1.0.26
io.smallrye:smallrye-metrics:5.1.0
io.smallrye:smallrye-open-api-core:3.1.1
io.smallrye:smallrye-open-api-core:4.0.2
io.smallrye:smallrye-open-api-core:4.0.6
io.smallrye:smallrye-open-api-jaxrs:3.1.1
io.smallrye:smallrye-open-api-jaxrs:4.0.2
io.smallrye:smallrye-open-api-model:4.0.2
io.smallrye:smallrye-open-api-jaxrs:4.0.6
io.smallrye:smallrye-open-api-model:4.0.6
io.zipkin.reporter2:zipkin-reporter:2.16.4
io.zipkin.reporter2:zipkin-reporter:3.3.0
io.zipkin.reporter2:zipkin-sender-okhttp3:2.16.4
Expand Down
6 changes: 3 additions & 3 deletions dev/io.openliberty.io.smallrye.jandex3/bnd.bnd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#*******************************************************************************
# Copyright (c) 2017, 2024 IBM Corporation and others.
# Copyright (c) 2017, 2025 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
# which accompanies this distribution, and is available at
Expand All @@ -12,10 +12,10 @@
#*******************************************************************************

-include=\
jar:${fileuri;${repo;io.smallrye:jandex;3.2.0;EXACT}}!/META-INF/MANIFEST.MF,\
jar:${fileuri;${repo;io.smallrye:jandex;3.2.3;EXACT}}!/META-INF/MANIFEST.MF,\
bnd.overrides

instrument.disabled: true

-buildpath:\
io.smallrye:jandex;version=3.2.0;strategy=exact
io.smallrye:jandex;version=3.2.3;strategy=exact
2 changes: 1 addition & 1 deletion dev/io.openliberty.io.smallrye.jandex3/bnd.overrides
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Bundle-Name: jandex 3
Bundle-SymbolicName: io.openliberty.io.smallrye.jandex3

Include-Resource:\
@${repo;io.smallrye:jandex;3.2.0;EXACT}!/!META-INF/*
@${repo;io.smallrye:jandex;3.2.3;EXACT}!/!META-INF/*
7 changes: 4 additions & 3 deletions dev/io.openliberty.io.smallrye.openapi4.core/bnd.bnd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#*******************************************************************************
# Copyright (c) 2024 IBM Corporation and others.
# Copyright (c) 2024, 2025 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
# which accompanies this distribution, and is available at
Expand Down Expand Up @@ -31,11 +31,12 @@ Import-Package: \
Export-Package: \
io.smallrye.openapi.api.*;version=4.0,\
io.smallrye.openapi.internal.models.*;version=4.0,\
io.smallrye.openapi.internal.support.*;version=4.0,\
io.smallrye.openapi.runtime.*;version=4.0,\
io.smallrye.openapi.spi.*;version=4.0,\
io.smallrye.openapi.spi.*;version=4.0

-buildpath: \
io.smallrye:smallrye-open-api-core;version=4.0.2,\
io.smallrye:smallrye-open-api-core;version=4.0.6,\
io.openliberty.io.smallrye.openapi4.model;version=latest,\
io.openliberty.jakarta.validation.3.0;version=latest,\
io.openliberty.org.eclipse.microprofile.openapi.4.0;version=latest,\
Expand Down
6 changes: 3 additions & 3 deletions dev/io.openliberty.io.smallrye.openapi4.jaxrs/bnd.bnd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#*******************************************************************************
# Copyright (c) 2024 IBM Corporation and others.
# Copyright (c) 2024, 2025 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
# which accompanies this distribution, and is available at
Expand All @@ -23,7 +23,7 @@ javac.target: 11
Require-Capability: osgi.ee; filter:="(&(osgi.ee=JavaSE)(version=11))"

Include-Resource: \
@${repo;io.smallrye:smallrye-open-api-jaxrs;4.0.2}!/META-INF/services/*
@${repo;io.smallrye:smallrye-open-api-jaxrs;4.0.6}!/META-INF/services/*

Service-Component: \
io.smallrye.openapi.runtime.scanner.spi.AnnotationScanner; \
Expand All @@ -40,7 +40,7 @@ Export-Package: \
io.smallrye.openapi.jaxrs;version=4.0;thread-context=true

-buildpath: \
io.smallrye:smallrye-open-api-jaxrs;version=4.0.2,\
io.smallrye:smallrye-open-api-jaxrs;version=4.0.6,\
io.openliberty.io.smallrye.openapi4.core;version=latest,\
io.openliberty.jakarta.validation.3.0;version=latest,\
io.openliberty.org.eclipse.microprofile.openapi.4.0;version=latest,\
Expand Down
4 changes: 2 additions & 2 deletions dev/io.openliberty.io.smallrye.openapi4.model/bnd.bnd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#*******************************************************************************
# Copyright (c) 2024 IBM Corporation and others.
# Copyright (c) 2024, 2025 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
# which accompanies this distribution, and is available at
Expand Down Expand Up @@ -27,7 +27,7 @@ Export-Package: \
io.smallrye.openapi.model.*;version=4.0

-buildpath: \
io.smallrye:smallrye-open-api-model;version=4.0.2,\
io.smallrye:smallrye-open-api-model;version=4.0.6,\
io.openliberty.org.eclipse.microprofile.openapi.4.0;version=latest,\
io.openliberty.io.smallrye.jandex3;version=latest,\
com.ibm.ws.org.jboss.logging;version=latest
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2024 IBM Corporation and others.
* Copyright (c) 2021, 2025 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -51,6 +51,8 @@
import io.openliberty.microprofile.openapi20.internal.services.ModelGenerator;
import io.openliberty.microprofile.openapi20.internal.services.ModuleSelectionConfig;
import io.openliberty.microprofile.openapi20.internal.services.OpenAPIProvider;
import io.openliberty.microprofile.openapi20.internal.services.OpenAPIVersionConfig;
import io.openliberty.microprofile.openapi20.internal.services.OpenAPIVersionUsageChecker;
import io.openliberty.microprofile.openapi20.internal.utils.Constants;
import io.openliberty.microprofile.openapi20.internal.utils.IndexUtils;
import io.openliberty.microprofile.openapi20.internal.utils.LoggingUtils;
Expand Down Expand Up @@ -89,6 +91,12 @@ public class ApplicationProcessor {
@Reference
private ValidationComponent validationComponent;

@Reference
private volatile List<OpenAPIVersionUsageChecker> versionUsageCheckers;

@Reference
private OpenAPIVersionConfig versionConfig;
Azquelt marked this conversation as resolved.
Show resolved Hide resolved

/**
* The processApplication method processes applications that are added to the OpenLiberty instance.
*
Expand Down Expand Up @@ -257,7 +265,14 @@ private OpenAPIProvider processWebModule(final Container appContainer, final Web
}

if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
Tr.debug(tc, "Generating OpenAPI model");
Tr.debug(this, tc, "Scanning for annotations invalid for the current OpenAPI version");
}

Index finalIndex = index;
versionUsageCheckers.forEach(checker -> checker.checkAnnotations(finalIndex, versionConfig.getVersion()));

if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
Tr.debug(this, tc, "Generating OpenAPI model");
}

openAPIModel = generateModel(config, appContainer, appClassloader, index);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/*******************************************************************************
* Copyright (c) 2024, 2025 IBM Corporation and others.
Copy link
Member

Choose a reason for hiding this comment

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

Given this is a new file should it have 2024?

Copy link
Member Author

Choose a reason for hiding this comment

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

It would, but it's not new, it was extracted from OpenAPIVersionConfigImpl.

Copy link
Member Author

Choose a reason for hiding this comment

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

It used to be internal to that class, but I needed to use it in the new OpenAPIVersionUsageChecker so I moved it into its own class.

* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package io.openliberty.microprofile.openapi20.internal;

import java.util.Objects;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.microprofile.openapi.models.OpenAPI;

import com.ibm.ws.ffdc.annotation.FFDCIgnore;

/**
* A parsed OpenAPI spec version. May represent a two-digit (e.g. 3.0) or three-digit (e.g. 3.0.3) version.
* <p>
* Both {@code equals} and {@code compareTo} treat {@code 3.0} as less than {@code 3.0.0}.
*/
public class OpenAPIVersion implements Comparable<OpenAPIVersion> {
/** Matches a.b or a.b.c where a, b and c are integers. After matching, a, b and c are in groups 1-3. */
private static final Pattern VERSION_PATTERN = Pattern.compile("([0-9]+)\\.([0-9]+)(?:\\.([0-9]+))?");

private int major, minor, patch;
private String versionString;

/**
* Attempt to parse a string into an OpenAPI version
*
* @param versionString the string to parse
* @return an {@code OpenAPIVersion} if the string represents a valid version, otherwise an empty {@code Optional}
*/
@FFDCIgnore(NumberFormatException.class)
public static Optional<OpenAPIVersion> parse(String versionString) {
if (versionString == null) {
return Optional.empty();
}

versionString = versionString.trim();

Matcher matcher = VERSION_PATTERN.matcher(versionString);
if (!matcher.matches()) {
return Optional.empty();
}

String major = matcher.group(1);
String minor = matcher.group(2);
String patch = matcher.group(3);

try {
return Optional.of(new OpenAPIVersion(Integer.parseInt(major),
Integer.parseInt(minor),
patch == null ? -1 : Integer.parseInt(patch)));
} catch (NumberFormatException e) {
// We've already checked each component is an integer, but it could be too large for an int
return Optional.empty();
}
}

public OpenAPIVersion(int major, int minor) {
this(major, minor, -1);
}

public OpenAPIVersion(int major, int minor, int patch) {
this.major = major;
this.minor = minor;
this.patch = patch;
versionString = major + "." + minor + (patch == -1 ? "" : "." + patch);
}

/**
* Gets the major version number.
*
* @return the major version
*/
public int getMajor() {
return major;
}

/**
* Gets the minor version number.
*
* @return the minor version
*/
public int getMinor() {
return minor;
}

/**
* Gets the patch version number.
*
* @return the patch version number, or {@code -1} for a two-digit version
*/
public int getPatch() {
return patch;
}

/**
* Returns the string form of this OpenAPI version, suitable for passing to {@link OpenAPI#setOpenapi(String)}
*/
@Override
public String toString() {
return versionString;
}

@Override
public int hashCode() {
return Objects.hash(major, minor, patch);
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
OpenAPIVersion other = (OpenAPIVersion) obj;
return major == other.major && minor == other.minor && patch == other.patch;
}

@Override
public int compareTo(OpenAPIVersion o) {
int compare = 0;
compare = Integer.compare(major, o.major);
if (compare == 0) {
compare = Integer.compare(minor, o.minor);
}
if (compare == 0) {
// Note patch == -1 for a two-digit version
// Therefore 3.0 < 3.0.0
// Having an ordering here is necessary to be consistent with equals
compare = Integer.compare(patch, o.patch);
}
return compare;
}
}
Loading