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

MicroProfile OpenAPI 4.0 to main #1977

Merged
merged 79 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
46b9216
Speed up testParsingBigStaticYamlFile
Azquelt Mar 26, 2024
1f3821b
Allow setSchemes to be called with null
Azquelt Apr 2, 2024
4bc0a7a
Depend on snapshot API
Azquelt Feb 20, 2024
acf6ab2
Update MP API dependency version for test data
Azquelt Apr 9, 2024
e1d6890
Update the schema model for OpenAPI 3.1
Azquelt Feb 20, 2024
95d99a6
SchemaRegistry: Defensively copy registered ref
Azquelt Apr 5, 2024
2a3b4b8
Update existing tests for schema model changes
Azquelt Feb 23, 2024
47d7aac
Remove deprecated Schema.getType and getNullable
Azquelt Apr 5, 2024
b4b3528
Add support for serializing short and char to JSON
Azquelt Apr 23, 2024
eec5cbd
Create IO objects in IOContext
Azquelt Apr 24, 2024
9933519
Enable serialization of model objects within schemas
Azquelt Apr 25, 2024
75f45cc
Safer Schema collection property operations
Azquelt Apr 30, 2024
69e4f6d
Add Javadoc to JsonIO
Azquelt Apr 30, 2024
a0deb65
Treat schema extensions as "annotating" the model
Azquelt Apr 30, 2024
3d536d7
Treat examples as "annotating" the schema model
Azquelt Apr 30, 2024
21a6193
Merge pull request #1793 from Azquelt/schema-model-3.1
MikeEdgar May 7, 2024
907da67
Scanner tests: Include output in failure message
Azquelt Apr 15, 2024
8d98138
Add tests for subschemas
Azquelt Apr 15, 2024
617b831
Implement new Schema annotation fields
Azquelt Apr 15, 2024
7cdd1cc
Merge pull request #1801 from Azquelt/schema-annotations-3.1
MikeEdgar May 9, 2024
918393e
Add 4.0-SNAPSHOT TCK report (#1833)
MikeEdgar May 9, 2024
763f097
test summary on Info annotation
benjamin-confino Apr 25, 2024
6a43ff0
add summary attribute on Info annotation
benjamin-confino Apr 25, 2024
73183db
Merge pull request #1815 from benjamin-confino/schema-model-3.1-benja…
MikeEdgar May 10, 2024
6da7a4b
update openapi version string 3.0.0 to 3.1.0
benjamin-confino Apr 28, 2024
031927a
update openapi version string 3.0.1 to 3.1.0
benjamin-confino May 8, 2024
da8a8c7
update openapi version string 3.0.2 to 3.1.0
benjamin-confino May 8, 2024
19ff551
update openapi version string 3.0.3 to 3.1.0
benjamin-confino Apr 28, 2024
2da5645
remove unused files
benjamin-confino May 8, 2024
31fc1fa
Merge pull request #1818 from benjamin-confino/update-openapi-version…
MikeEdgar May 14, 2024
072596e
support identifier in licence
benjamin-confino May 9, 2024
33cc40e
test identifier in licence
benjamin-confino May 10, 2024
46c6d3c
Merge pull request #1834 from benjamin-confino/licence-reference
MikeEdgar May 16, 2024
2983bdc
Add webhooks to model API
Azquelt May 9, 2024
a8eb108
Merge pull request #1836 from Azquelt/webhooks
MikeEdgar May 21, 2024
5f13fd5
Allow summary and description alongside $ref (#1841)
Azquelt Jun 5, 2024
e9b7241
Model changes to add PathItem to Components (#1852)
Azquelt Jun 6, 2024
5ebf184
Update tests to expect required requestBody
Azquelt May 30, 2024
b401615
Require requestBody by default
Azquelt May 31, 2024
2e423a5
Required requestBody in Spring and vert.x tests
Azquelt May 31, 2024
8037e64
Required requestBody in testsuite/data tests
Azquelt May 31, 2024
a5376ab
Delete unused test files
Azquelt May 31, 2024
1eb6dc7
Merge pull request #1858 from Azquelt/requestbody-default-required
MikeEdgar Jun 6, 2024
dc7843b
Backport updates from main/release 3.11.0 (#1868)
MikeEdgar Jun 6, 2024
545cc1f
Read PathItem and PathItemOperation annotations (#1869)
Azquelt Jun 10, 2024
515798b
Bump MicroProfile OpenAPI spec to 4.0-RC1, disable older TCKs jobs (#…
MikeEdgar Jun 14, 2024
d78dd9b
Release 4.0.0-alpha1 (#1877)
MikeEdgar Jun 17, 2024
0a2a89a
[maven-release-plugin] prepare release 4.0.0-alpha1
smallrye-ci Jun 17, 2024
76609ed
[maven-release-plugin] prepare for next development iteration
smallrye-ci Jun 17, 2024
6c30188
Backport updates from main (#1884)
MikeEdgar Jun 25, 2024
320ff06
Bump MicroProfile OpenAPI from 4.0-RC1 to 4.0 (#1885)
MikeEdgar Jun 25, 2024
29e7aee
Release 4.0.0-alpha2 (#1886)
MikeEdgar Jun 25, 2024
ee8018c
[maven-release-plugin] prepare release 4.0.0-alpha2
smallrye-ci Jun 25, 2024
7cbdf4a
[maven-release-plugin] prepare for next development iteration
smallrye-ci Jun 25, 2024
6cc9e1d
Allow null map values in ModelIO#toLinkedMap collector (#1908)
MikeEdgar Jul 9, 2024
e144fdb
Backport updates from main 2 (#1909)
MikeEdgar Jul 9, 2024
4fa08ee
Prepare staging repositories for release 4.0-alpha3 (#1910)
MikeEdgar Jul 9, 2024
5112da5
Release 4.0.0-alpha3 (#1911)
MikeEdgar Jul 9, 2024
7e7f665
[maven-release-plugin] prepare release 4.0.0-alpha3
smallrye-ci Jul 9, 2024
b2b3b7c
[maven-release-plugin] prepare for next development iteration
smallrye-ci Jul 9, 2024
973bee7
Backport updates from main 3 (#1915)
MikeEdgar Jul 12, 2024
37ebcfd
Prepare staging repositories for release 4.0-alpha4 (#1916)
MikeEdgar Jul 12, 2024
a0d614a
Release 4.0.0-alpha4 (#1917)
MikeEdgar Jul 12, 2024
a1458b3
[maven-release-plugin] prepare release 4.0.0-alpha4
smallrye-ci Jul 12, 2024
5d670f0
[maven-release-plugin] prepare for next development iteration
smallrye-ci Jul 12, 2024
2e93271
Backport updates from main 4 (#1931)
MikeEdgar Aug 1, 2024
691d17c
Prepare staging repositories for release 4.0-alpha5 (#1932)
MikeEdgar Aug 1, 2024
484e275
Release 4.0.0-alpha5 (#1933)
MikeEdgar Aug 1, 2024
cecd909
[maven-release-plugin] prepare release 4.0.0-alpha5
smallrye-ci Aug 1, 2024
4d9a3ff
[maven-release-plugin] prepare for next development iteration
smallrye-ci Aug 1, 2024
79e5755
Fix VersionTest
Azquelt Jul 11, 2024
afc3245
Support generation of OpenAPI v3.0
Azquelt Jul 10, 2024
9a9c04e
Tests for OpenAPI v3.0 processing
Azquelt Jul 12, 2024
83c78ad
Additional transformations for OpenAPI 3.0 schemas
Azquelt Jul 19, 2024
3ea091a
Add OpenAPI 3.0 tests to ParserAndSerializerTest
Azquelt Jul 19, 2024
68b9b67
Merge pull request #1918 from Azquelt/openapi-3.0-support
MikeEdgar Aug 5, 2024
7b5ca99
Merge remote-tracking branch 'upstream/main' into main-4.0
MikeEdgar Sep 4, 2024
8c0abc3
Fix tests from #1974
MikeEdgar Sep 5, 2024
3e0af1f
Revert changes to .github/project.yml to avoid triggering a release
MikeEdgar Sep 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 6 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,14 @@ jobs:
tck-reporting:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- tck-version: "2.0.1"
- tck-version: "3.0"
- tck-version: "3.1.1"
# Disable older TCK jobs prior to 4.0 GA release
#- tck-version: "2.0.1"
#- tck-version: "3.0"
#- tck-version: "3.1.1"
- tck-version: "4.0"

name: MicroProfile OpenAPI TCK ${{ matrix.tck-version }}
steps:
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ jobs:
strategy:
matrix:
include:
- tck-version: "2.0.1"
- tck-version: "3.0"
- tck-version: "3.1.1"
# Disable older TCK jobs prior to 4.0 GA release
#- tck-version: "2.0.1"
#- tck-version: "3.0"
#- tck-version: "3.1.1"
- tck-version: "4.0"

name: MicroProfile OpenAPI TCK ${{ matrix.tck-version }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-open-api-parent</artifactId>
<version>3.12.1-SNAPSHOT</version>
<version>4.0.0-SNAPSHOT</version>
</parent>

<artifactId>smallrye-open-api-core</artifactId>
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/java/io/smallrye/openapi/api/OpenApiConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ default String getInfoTermsOfService() {
return getConfigValue(SmallRyeOASConfig.INFO_TERMS, String.class, () -> null);
}

default String getInfoSummary() {
return getConfigValue(SmallRyeOASConfig.INFO_SUMMARY, String.class, () -> null);
}

default String getInfoContactEmail() {
return getConfigValue(SmallRyeOASConfig.INFO_CONTACT_EMAIL, String.class, () -> null);
}
Expand All @@ -225,6 +229,10 @@ default String getInfoLicenseName() {
return getConfigValue(SmallRyeOASConfig.INFO_LICENSE_NAME, String.class, () -> null);
}

default String getInfoLicenseIdentifier() {
return getConfigValue(SmallRyeOASConfig.INFO_LICENSE_IDENTIFIER, String.class, () -> null);
}

default String getInfoLicenseUrl() {
return getConfigValue(SmallRyeOASConfig.INFO_LICENSE_URL, String.class, () -> null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ private SmallRyeOASConfig() {
public static final String INFO_TITLE = SMALLRYE_PREFIX + "info.title";
public static final String INFO_VERSION = SMALLRYE_PREFIX + "info.version";
public static final String INFO_DESCRIPTION = SMALLRYE_PREFIX + "info.description";
public static final String INFO_SUMMARY = SMALLRYE_PREFIX + "info.summary";
public static final String INFO_TERMS = SMALLRYE_PREFIX + "info.termsOfService";
public static final String INFO_CONTACT_EMAIL = SMALLRYE_PREFIX + "info.contact.email";
public static final String INFO_CONTACT_NAME = SMALLRYE_PREFIX + "info.contact.name";
public static final String INFO_CONTACT_URL = SMALLRYE_PREFIX + "info.contact.url";
public static final String INFO_LICENSE_NAME = SMALLRYE_PREFIX + "info.license.name";
public static final String INFO_LICENSE_IDENTIFIER = SMALLRYE_PREFIX + "info.license.identifier";
public static final String INFO_LICENSE_URL = SMALLRYE_PREFIX + "info.license.url";
public static final String OPERATION_ID_STRAGEGY = SMALLRYE_PREFIX + "operationIdStrategy";
public static final String DUPLICATE_OPERATION_ID_BEHAVIOR = SMALLRYE_PREFIX + "duplicateOperationIdBehavior";
Expand All @@ -81,7 +83,7 @@ private SmallRyeOASConfig() {
public static final String AUTO_INHERITANCE = SMALLRYE_PREFIX + "auto-inheritance";

public static final class Defaults {
public static final String VERSION = "3.0.3";
public static final String VERSION = "3.1.0";

private Defaults() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public Builder enableStandardFilter(boolean enableStandardFilter) {
* <li>Set a generated value for {@code info.title} if none specified
* <li>Set a generated value for {@code info.version} if none specified
* <li>Set a default value for {@code openapi} (the specification
* version) if none specified. E.g. 3.0.3
* version) if none specified. E.g. 3.1.0
* </ul>
*
* @param defaultRequiredProperties
Expand Down Expand Up @@ -585,7 +585,7 @@ public Schema parseSchema(String jsonSchema) {
.map(parser -> parser.apply(jsonSchema))
.orElseGet(() -> {
V schemaModel = modelIO.jsonIO().fromString(jsonSchema, Format.JSON);
return modelIO.schemas().readValue(schemaModel);
return modelIO.schemaIO().readValue(schemaModel);
});
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Map;

import org.eclipse.microprofile.openapi.models.Components;
import org.eclipse.microprofile.openapi.models.PathItem;
import org.eclipse.microprofile.openapi.models.callbacks.Callback;
import org.eclipse.microprofile.openapi.models.examples.Example;
import org.eclipse.microprofile.openapi.models.headers.Header;
Expand All @@ -30,6 +31,7 @@ public class ComponentsImpl extends ExtensibleImpl<Components> implements Compon
private Map<String, SecurityScheme> securitySchemes;
private Map<String, Link> links;
private Map<String, Callback> callbacks;
private Map<String, PathItem> pathItems;

/**
* @see org.eclipse.microprofile.openapi.models.Components#getSchemas()
Expand Down Expand Up @@ -338,4 +340,25 @@ public void removeCallback(String key) {
ModelUtil.remove(this.callbacks, key);
}

@Override
public Map<String, PathItem> getPathItems() {
return ModelUtil.unmodifiableMap(this.pathItems);
}

@Override
public void setPathItems(Map<String, PathItem> pathItems) {
this.pathItems = ModelUtil.replace(pathItems, LinkedHashMap<String, PathItem>::new);
}

@Override
public Components addPathItem(String name, PathItem pathItem) {
this.pathItems = ModelUtil.add(name, pathItem, this.pathItems, LinkedHashMap<String, PathItem>::new);
return this;
}

@Override
public void removePathItem(String name) {
ModelUtil.remove(this.pathItems, name);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
package io.smallrye.openapi.api.models;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import io.smallrye.openapi.api.util.MergeUtil;
import io.smallrye.openapi.runtime.util.ModelUtil;

/**
* Base implementation for extensible model objects which wrap a map of properties
*/
public abstract class MapBasedModelImpl implements ModelImpl {

protected final LinkedHashMap<String, Object> data = new LinkedHashMap<>();

protected MapBasedModelImpl() {
}

/**
* Merge all properties from another map-based model object into this one
* <p>
* Usually this method will return {@code this}, but it may return {@code other} or a new object.
*
* @param other the other map-based model object
* @return the merged object
*/
public MapBasedModelImpl mergeFrom(MapBasedModelImpl other) {
mergeMap(data, other.data, getNonMergableCollections());
return this;
}

public Map<String, Object> getDataMap() {
return data;
}

private static <T> void mergeMap(Map<String, T> into, Map<String, T> from, Set<String> nonMergableNames) {
for (Entry<String, T> entry : from.entrySet()) {
String name = entry.getKey();
T value = entry.getValue();
T oldValue = into.get(entry.getKey());
if (oldValue == null || oldValue.getClass() != value.getClass()) {
into.put(name, value);
} else {
if (oldValue instanceof Map && !nonMergableNames.contains(name)) {
mergeMap((Map<String, Object>) oldValue, (Map<String, Object>) value, nonMergableNames);
} else if (oldValue instanceof List && !nonMergableNames.contains(name)) {
mergeList((List<Object>) oldValue, (List<Object>) value);
} else if (oldValue instanceof ModelImpl) {
into.put(name, MergeUtil.mergeObjects(oldValue, value));
} else {
into.put(name, value);
}
}
}
}

private static <T> void mergeList(List<T> oldValue, List<T> value) {
Set<T> contents = new HashSet<>(oldValue);
for (T element : value) {
if (!contents.contains(element)) {
oldValue.add(element);
}
}
}

protected <T> void setProperty(String propertyName, T value) {
if (value == null) {
data.remove(propertyName);
} else {
data.put(propertyName, value);
}
}

protected <T> T getProperty(String propertyName, Class<T> type) {
Object result = data.get(propertyName);
if (type.isInstance(result)) {
return type.cast(result);
} else {
return null;
}
}

@SuppressWarnings("unchecked")
protected <T> List<T> getListProperty(String propertyName) {
Object result = data.get(propertyName);
if (result instanceof List) {
return Collections.unmodifiableList((List<T>) result);
} else {
return null;
}
}

protected <T> void setListProperty(String propertyName, List<T> value) {
value = ModelUtil.replace(value, ArrayList::new);
if (value == null) {
data.remove(propertyName);
} else {
data.put(propertyName, value);
}
}

protected <T> void addToListProperty(String propertyName, T value) {
if (value != null) {
Object existing = data.get(propertyName);
List<T> list;
if (existing instanceof List) {
list = (List<T>) existing;
} else {
list = new ArrayList<>();
data.put(propertyName, list);
}
list.add(value);
}
}

protected <T> void removeFromListProperty(String propertyName, T toRemove) {
Object existing = data.get(propertyName);
if (existing instanceof List) {
List<T> list = (List<T>) existing;
ModelUtil.remove(list, toRemove);
}
}

protected <T> void setMapProperty(String propertyName, Map<String, T> value) {
value = ModelUtil.replace(value, HashMap::new);
if (value == null) {
data.remove(propertyName);
} else {
data.put(propertyName, value);
}
}

protected <T> Map<String, T> getMapProperty(String propertyName) {
Object result = data.get(propertyName);
if (result instanceof Map) {
return Collections.unmodifiableMap((Map<String, T>) data.get(propertyName));
} else {
return null;
}
}

protected <T> void addToMapProperty(String propertyName, String key, T value) {
if (value != null) {
Object existing = data.get(propertyName);
Map<String, T> map;
if (existing instanceof Map) {
map = (Map<String, T>) existing;
} else {
map = new HashMap<>();
data.put(propertyName, map);
}
map.put(key, value);
}
}

protected <T> void removeFromMapProperty(String propertyName, String key) {
Object existing = data.get(propertyName);
if (existing instanceof Map) {
Map<String, T> map = (Map<String, T>) existing;
ModelUtil.remove(map, key);
}
}

/**
* Return a list of properties whose values should not be merged even if they're collections
*
* @return a list of properties which should be overwritten rather than merged
*/
protected Set<String> getNonMergableCollections() {
return Collections.emptySet();
}

}
25 changes: 25 additions & 0 deletions core/src/main/java/io/smallrye/openapi/api/models/OpenAPIImpl.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package io.smallrye.openapi.api.models;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.microprofile.openapi.models.Components;
import org.eclipse.microprofile.openapi.models.ExternalDocumentation;
import org.eclipse.microprofile.openapi.models.OpenAPI;
import org.eclipse.microprofile.openapi.models.PathItem;
import org.eclipse.microprofile.openapi.models.Paths;
import org.eclipse.microprofile.openapi.models.info.Info;
import org.eclipse.microprofile.openapi.models.security.SecurityRequirement;
Expand All @@ -26,6 +29,7 @@ public class OpenAPIImpl extends ExtensibleImpl<OpenAPI> implements OpenAPI, Mod
private List<SecurityRequirement> security;
private List<Tag> tags;
private Paths paths;
private Map<String, PathItem> webhooks;
private Components components;

/**
Expand Down Expand Up @@ -226,4 +230,25 @@ public Components getComponents() {
public void setComponents(Components components) {
this.components = components;
}

@Override
public Map<String, PathItem> getWebhooks() {
return ModelUtil.unmodifiableMap(this.webhooks);
}

@Override
public void setWebhooks(Map<String, PathItem> webhooks) {
this.webhooks = ModelUtil.replace(webhooks, LinkedHashMap<String, PathItem>::new);
}

@Override
public OpenAPI addWebhook(String name, PathItem webhook) {
this.webhooks = ModelUtil.add(name, webhook, this.webhooks, LinkedHashMap<String, PathItem>::new);
return this;
}

@Override
public void removeWebhook(String name) {
ModelUtil.remove(this.webhooks, name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.eclipse.microprofile.openapi.models.parameters.Parameter;
import org.eclipse.microprofile.openapi.models.servers.Server;

import io.smallrye.openapi.runtime.io.ReferenceType;
import io.smallrye.openapi.runtime.util.ModelUtil;

/**
Expand Down Expand Up @@ -44,6 +45,9 @@ public String getRef() {
*/
@Override
public void setRef(String ref) {
if (ref != null && !ref.contains("/")) {
ref = ReferenceType.PATH_ITEM.referenceOf(ref);
}
this.ref = ref;
}

Expand Down
Loading