Repository navigation
Open-API: Fix compilation errors in generated Java classes due to mismatched return types - #11806
VladimirYushkevich wants to merge 2 commits into
Conversation
…matched return types In this PR: - Defined ActionEnum and ContentEnum as global types in rest-catalog-open-api.yaml. - Updated parent and child classes to reference these global enum types, ensuring compatibility.
| ) | ||
|
|
||
|
|
||
| class ContentFile(BaseModel): |
There was a problem hiding this comment.
nit: can we edit the existing class instead of removing and adding it in the down? That way the diff will be minimal for review.
There was a problem hiding this comment.
this file is autogenerated, I moved ContentEnum and ActionEnum in proper place to minimize diff a bit.
|
|
||
| ActionEnum: | ||
| type: string | ||
| enum: |
There was a problem hiding this comment.
nit: can we keep it as the same order of declaration, like set and reset together for all the operations?
|
|
||
| class DataFile(ContentFile): | ||
| content: Literal['data'] | ||
| content: ContentEnum |
There was a problem hiding this comment.
you mean .py change? I run tests as mentioned here: https://github.com/apache/iceberg/tree/main/open-api#running-compatibility-tests
There was a problem hiding this comment.
No, this file is just here for test purposes and to see what kind of code changes the changes in the yaml produces. With the open-API spec, it can sometimes be hard to see what the impact is.
|
|
||
| class UpgradeFormatVersionUpdate(BaseUpdate): | ||
| action: Literal['upgrade-format-version'] | ||
| action: ActionEnum |
There was a problem hiding this comment.
From a Pydantics' perspective this has a different semantic meaning. Before, we required that the action field for the UpgradeFormatVersionUpdate needs to be upgrade-format-version, now it can be any value from the enum. But, this can also be a limitation of the Pydantic open-api generator. Let me take a deeper look.
There was a problem hiding this comment.
For the Jersey one, it is the other way around, it will generate an ActionEnum per Update:
public enum ActionEnum {
ADD_SPEC(String.valueOf("add-spec"));
private String value;
ActionEnum(String value) {
this.value = value;
}
@JsonValue
public String getValue() {
return value;
}
@Override
public String toString() {
return String.valueOf(value);
}
@JsonCreator
public static ActionEnum fromValue(String value) {
for (ActionEnum b : ActionEnum.values()) {
if (b.value.equals(value)) {
return b;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
}
}There was a problem hiding this comment.
@VladimirYushkevich @ajantha-bhat
I've been playing around with alternative solutions. In Open-API there are many ways to get to the same result. What about #11955? The issue is related to the Enum, and with Open-API 3.1 the const is added looks more appropriate here. LMKWYT
The `const` has been added in Open API 3.1: https://www.speakeasy.com/openapi/schemas/enums#constants-for-single-value-enums This seems to fix the compilation issue reported in apache#11806 as well.
The `const` has been added in Open API 3.1: https://www.speakeasy.com/openapi/schemas/enums#constants-for-single-value-enums This seems to fix the compilation issue reported in apache#11806 as well.
The `const` has been added in Open API 3.1: https://www.speakeasy.com/openapi/schemas/enums#constants-for-single-value-enums This seems to fix the compilation issue reported in apache#11806 as well.
The `const` has been added in Open API 3.1: https://www.speakeasy.com/openapi/schemas/enums#constants-for-single-value-enums This seems to fix the compilation issue reported in #11806 as well.
|
@VladimirYushkevich Can you confirm that updating the Open-API version has fixed the issue? |
@Fokko, I have reviewed the issue I mentioned in description and found that it is no longer present. Thank you for the fix; we can proceed to close this pull request. However, in our production codebase, we are utilizing the Unfortunately I have no time to dig what is the source of failure, just noticed from the stacktrace: looks like |
|
UPD: after adding |
|
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the [email protected] list. Thank you for your contributions. |
|
This pull request has been closed due to lack of activity. This is not a judgement on the merit of the PR in any way. It is just a way of keeping the PR queue manageable. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time. |
Description
This PR addresses a compilation issue in the generated java classes from
rest-catalog-open-api.yamlspecification.Problem
The generated Java classes fail to compile due to incorrect return types for the
getAction()andgetContent()methods. While the parent classes expect these methods to return aString, the child classes return specificActionEnumandContentEnumtypes defined within each child class.Solution
To resolve this,
ActionEnumandContentEnumtypes are now defined globally in the OpenAPI specification. Both the parent and child classes reference these global types, ensuring compatibility and eliminating the compile-time errors.Steps to Reproduce the Issue
Create a
.openapi-generator-ignorefile with the following content:Generate Java classes using the OpenAPI generator Docker image:
Navigate to the generated stub:
Add the missing
Swaggerdependency tobuild.gradle:Run the Gradle build:
Observe the compilation errors, such as: