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

Improve inheritance support #150

Closed
VladDrakul1986 opened this issue Jan 30, 2023 · 5 comments
Closed

Improve inheritance support #150

VladDrakul1986 opened this issue Jan 30, 2023 · 5 comments
Labels
question Further information is requested

Comments

@VladDrakul1986
Copy link

Hi i found an issue linked to #147 and probably to #87
here the example base on the previous one

public class MyBaseRequest {
private String name;
private String description;
private NestedID myBaseList;
// getter for all
...

private class NestedID{
private UUID id;
//getter 
}
}
public class MyRequestClass extends MyBaseRequest implements Serializable{
private String someAdditonalField;
private NestedID secondList;
...
// getter for all
...
private class NestedID{
private UUID id;
//getter 
}
}
requestBody = @OpenApiRequestBody(...
               @OpenApiContent(from = MyRequestClass.class, type = ContentType.JSON)),

actual json example:

{
"someAdditonalField": "string",
"name": "string",
"description": "string"
"secondList": {
   "id": "string"
}
}

expected json example:

{
"someAdditonalField": "string",
"name": "string",
"description": "string"
"secondList": {
   "id": "string"
}
"myBaseList": {
   "id": "string"
}
}
@dzikoysk
Copy link
Member

private open class BaseType {
    val baseProperty: String = "Test"
    val baseNested: BaseType.NestedClass = NestedClass()

    private inner class NestedClass {
        val nestedProperty: String = "Test"
    }
}

private class FinalClass : BaseType(), Serializable {
    val finalProperty: String = "Test"
    val finalNested: FinalClass.NestedClass = NestedClass()

    private inner class NestedClass {
        val nestedProperty: String = "Test"
    }
}

@OpenApi(
    path = "content-types",
    versions = ["should_generate_reference_with_inherited_properties"],
    responses = [OpenApiResponse(status = "200", content = [OpenApiContent(from = FinalClass::class, type = ContentType.JSON)])]
)

Results in:

{
  "openapi": "3.0.3",
  "info": {
    "title": "",
    "version": ""
  },
  "paths": {
    "/content-types": {
      "get": {
        "tags": [],
        "parameters": [],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FinalClass"
                }
              }
            }
          }
        },
        "deprecated": false,
        "security": []
      }
    }
  },
  "components": {
    "schemas": {
      "NestedClass": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "nestedProperty": {
            "type": "string"
          }
        },
        "required": [
          "nestedProperty"
        ]
      },
      "FinalClass": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "baseProperty": {
            "type": "string"
          },
          "baseNested": {
            "$ref": "#/components/schemas/NestedClass"
          },
          "finalProperty": {
            "type": "string"
          },
          "finalNested": {
            "$ref": "#/components/schemas/NestedClass"
          }
        },
        "required": [
          "baseProperty",
          "baseNested",
          "finalProperty",
          "finalNested"
        ]
      }
    }
  }
}

And it looks like a valid scheme for the given snippet, expect the fact that we're using simple names for classes, so NestedClass scheme is overridden, but that's kinda not my point here. Could you share your full example so I can reproduce this?

@VladDrakul1986
Copy link
Author

you are right when i remove everything which is not needed for an minimal example it works fine.
Is there a way to debug what happens while the annotation processing ?

@dzikoysk
Copy link
Member

Hmm... Do you have other classes called MyRequestClass? Maybe it's related to the issue I've mentioned above with classes with the same name.

You can debug annotation processor like regular code if you use Gradle. Just add annotation processor module as implementation, enable debug mode for Gradle scripts in IntelliJ config and it should work just fine. For Maven... well, I'm afraid it's not an option, you'd need to setup remote debugging for whole Maven process & it's extremely slow.

We could work around the debug logging enabled by scripting api:

@dzikoysk dzikoysk added the bug Something isn't working label Jan 30, 2023
@VladDrakul1986
Copy link
Author

Thank you for your help,
i found the issue, there was an other request class implementing NestedID which doesn't had a getter.
So the mentioned overwriting of the NestedClass was the problem -> 100 % my fault 🙈 🙊

@dzikoysk
Copy link
Member

Sure, I've covered this issue with small enhancement to debug logging.

@dzikoysk dzikoysk added question Further information is requested and removed bug Something isn't working investigation labels Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants