-
Notifications
You must be signed in to change notification settings - Fork 306
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
PAYARA-3466 Open API 1.1 #3827
PAYARA-3466 Open API 1.1 #3827
Conversation
…h defaults, removed warnings, extracted common base classes for extensible maps, switched to non-deprecated methods
...rofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java
Show resolved
Hide resolved
@@ -98,4 +129,34 @@ public static Object convertExtensionValue(String value) { | |||
return value; | |||
} | |||
|
|||
@Override | |||
public String toString() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: Added this to ease debugging by providing a helpful toString
for the model.
ExampleImpl.merge(example, to.getMediaType(typeName).getExamples(), override); | ||
} | ||
if (!from.example().isEmpty()) { | ||
to.getMediaType(typeName).setExample(from.example()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: example
is a new property in 1.1
|
||
@Override | ||
public Scopes addScope(String name, String item) { | ||
this.put(name, item); | ||
this.put(name, item); // this DOES accept null! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: This seems inconsistent but this add method explicitly allows for null while usually the add methods do not allow for null or should ignore it.
@Override | ||
public SecurityRequirement addScheme(String name, String item) { | ||
this.put(name, Arrays.asList(item)); | ||
this.put(name, item == null ? new ArrayList<>() : Arrays.asList(item)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: null
should become empty list
return this; | ||
} | ||
|
||
@Override | ||
public SecurityRequirement addScheme(String name, List<String> item) { | ||
this.put(name, item); | ||
this.put(name, item == null ? new ArrayList<>() : item); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: null
should become empty list
return variables; | ||
return variables instanceof ServerVariables || variables == null | ||
? (ServerVariables) variables | ||
: new ServerVariablesImpl(variables); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: ServerVariables
got "half-removed". It is deprecated and should be removed in the future. In some places it already was replaced with a Map<String, SeverVariable>
what causes changes here.
public static Boolean mergeProperty(boolean current, boolean offer, boolean override) { | ||
return mergeProperty(Boolean.valueOf(current), Boolean.valueOf(offer), override); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: I added this overloaded variants to avoid boxing/unboxing warnings. The module is almost free of warnings and it would be nice to get there.
try (DataInputStream in = new DataInputStream(stream)) { | ||
// Reading the binary data | ||
in.readFully(buff); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: fixed potential resource leak.
if (element instanceof java.lang.reflect.Parameter) { | ||
visitSchemaParameter(schema, (java.lang.reflect.Parameter) element, context); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: extracted the cases into one method each to make this more readable.
String name = extension.name(); | ||
if (name != null && !name.isEmpty() && value != null | ||
&& !value.isEmpty()) { | ||
Object parsedValue = ExtensibleImpl.convertExtensionValue(value, extension.parseValue()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: here we were missing applying conversion via convertExtensionValue
.
} | ||
} | ||
} | ||
matchedParam = findOperationParameterFor(parameter, (Method) element, context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: extracted the cases to make it more readable. Also the loop in the cases should stop when a match is found. This is simpler done with a return
in a separate method.
.removeIf(x -> ModelUtils.getParameterType(x) != In.valueOf(in.name())); | ||
} | ||
if (matchingMethodParameters.isEmpty()) { | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: This is a fix I added. 1.0 TCK simply had no case that would otherwise fail the next line where we always get the first entry of the list. But some cases do not have a matching parameter.
jenkins test please |
...rofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java
Show resolved
Hide resolved
...rofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java
Outdated
Show resolved
Hide resolved
// Get all parameters with the same name | ||
List<java.lang.reflect.Parameter> matchingMethodParameters = Arrays | ||
.asList(annotated.getParameters()).stream() | ||
.filter(x -> name.equals(ModelUtils.getParameterName(x))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: swapped the equals because ModelUtils.getParameterName(x)
can be null causeing NPE while name
is from an annotation and cannot be null.
...ofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/util/ModelUtils.java
Outdated
Show resolved
Hide resolved
...microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/OpenApiService.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally good, just a couple of comments from me. As an aside, I'm glad someone has shared my pain of maintaining masses of model classes! 😆
...microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/OpenApiService.java
Show resolved
Hide resolved
...ile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleTreeMap.java
Outdated
Show resolved
Hide resolved
...ofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/util/ModelUtils.java
Outdated
Show resolved
Hide resolved
...ofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/util/ModelUtils.java
Show resolved
Hide resolved
...napi/src/main/java/fish/payara/microprofile/openapi/impl/processor/ApplicationProcessor.java
Outdated
Show resolved
Hide resolved
...napi/src/main/java/fish/payara/microprofile/openapi/impl/processor/ApplicationProcessor.java
Show resolved
Hide resolved
jenkins test please |
* {@link ExtensibleTreeMap#extensions} map to the output object unless the value represents a {@link Reference} in | ||
* which case only the {@link Reference#getRef()} is added. | ||
*/ | ||
static class ExtensibleTreeMapSerializer extends JsonSerializer<ExtensibleTreeMap<?,?>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: This fixes two defects in the JSON/YAML serialisation present since 1.0 where properties on Map
extending types would be ignored as they are handled by the map serializer. Thereby extensions would not be added and in case of a reference an empty object was rendered instead of the reference.
jenkins test please |
Summary:
Extensible
hierarchy (added in 1.1)default
methods in the API interfaces@Parameters
(missed both by TCK and us in 1.0)@Extensions
(missed both by TCK and us in 1.0)null
check toaddX
methods (I think 1.1 addec this semantic or 1.0 TCK missed to check)Map
model types for their "copy getter" (see API javadoc)Extensible
Map
s (share impl.)