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

[REQ] reduce log level of "allOf with multiple schemas defined..." warning message #11841

Closed
jahlbornG opened this issue Mar 9, 2022 · 7 comments

Comments

@jahlbornG
Copy link

Is your feature request related to a problem? Please describe.

When i currently run the openapi generator in our project, we get a ton of warning messages like:

[WARNING] allOf with multiple schemas defined. Using only the first one: FooBar

Build warnings should be reserved for things which are potentially problems that i should think of fixing. From what i can tell, this message pertains to no real problem, and there is nothing i can do to remove the message. To me, this message seems like it should be at best an info message (if not debug). In general, a build should be silent unless there is something meaningful to say, and this message just doesn't seem meaningful

Describe the solution you'd like

Lower the log level of this message to info or debug.

Describe alternatives you've considered

As far as i can tell, there is nothing i can do on my end to fix the problem. if there is a change i can make, i'd love to know what that is.

Additional context

@nikosmoum
Copy link

The problem with this warning is not that it should be info/debug, but that it's entirely wrong and shouldn't be there. allOf is supposed to be used with multiple schemas by design, and this warning is saying the opposite. So this is a bug

@Andy2003
Copy link

This warning is printed when the name for the composite schema of the allOf-Type is determined, regardless of whether it is later used for generating a class:

public String toAllOfName(List<String> names, ComposedSchema composedSchema) {
Map<String, Object> exts = composedSchema.getExtensions();
if (exts != null && exts.containsKey("x-all-of-name")) {
return (String) exts.get("x-all-of-name");
}
if (names.size() == 0) {
LOGGER.error("allOf has no member defined: {}. Default to ERROR_ALLOF_SCHEMA", composedSchema);
return "ERROR_ALLOF_SCHEMA";
} else if (names.size() == 1) {
return names.get(0);
} else {
LOGGER.warn("allOf with multiple schemas defined. Using only the first one: {}", names.get(0));
return names.get(0);
}
}

The warning can currently be suppressed by defining x-all-of-name

Instead of printing out the warning I would suggest joining all names of the names list instead of just taking the 1st one.

@RemekGdansk
Copy link

I am getting this warning when I generate code from the schema that was generated based on the following Java code and annotations:

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "A popular feline pet")
public class Cat extends Pet { }

Which results in the following API description:

{
  "Cat": {
    "type": "object",
    "description": "A popular feline pet",
    "allOf": [
      {
        "$ref": "#/components/schemas/Pet"
      },
      {
        "type": "object",
        "properties": {
          "specificCatProperty": {
            "type": "string",
            "description": "A specific Cat property"
          }
        }
      }
    ]
  }
}

If there is a way to explicitly state the name of the schema, it could be hinted in the warning.

And if I am just using the annotation incorrectly here, please let me know.

@aaron-613
Copy link

@RemekGdansk I've been running into this as well, and just stumbled on this thread. I don't have an answer for you, but a question:

In my generated Java code, that comes from this snippet of my spec:

      "InvalidStateReference": {
        "type": "object",
        "allOf": [
          {
            "$ref": "#/components/schemas/ErrorResponse"
          },
          {
            "type": "object",
            "properties": {
              "targetStateId": {
                "type": "string"
              },
              "inboundInvalidNonStateReferences": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/InvalidNonStateReference"
                }
              },
<SNIP>

I end up with 3 different Java files... one for the parent class (ErrorResponse), one for the subclass (InvalidStateReference) which inherits from ErrorResponse and has a couple extra instance vars... and then a 3rd (InvalidStateReferenceAllOf) which has all of the instance vars of the other one, but doesn't inherit from ErrorReponse. I have no idea what the 3rd class would be used for? Like, somehow just representing all the non-inherited fields of the child object?? Anyhow...

@RemekGdansk
Copy link

@aaron-613 Yes, in my case I also get 3 classes:

  • 1 for the superclass
  • 1 for the subclass that extends the superclass
  • 1 with -AllOf suffix that does not extend the superclass

So, the same situation as yours.

In my case, when I use the superclass as a generic type in some collection in another class - an even different class is additionally generated and used instead of the expected superclass Pet:

public class Owner {
  public String name;
  public List<OwnerPetsInner> pets;
}

This -Inner suffixed class contains fields of the superclass Pet and all possible subclasses (Cat, Dog etc.).

Thus, I am wondering if this is the right way to use the tool or not.

@Mettbrot
Copy link

The problem with this warning is not that it should be info/debug, but that it's entirely wrong and shouldn't be there. allOf is supposed to be used with multiple schemas by design, and this warning is saying the opposite. So this is a bug

As I understand it the warning only says that the name is determined using only the first schema. If so, the message is just simply wrong and should be something like:
allOf with multiple schemas defined. Using only the first one for name generation: ???

@wing328
Copy link
Member

wing328 commented Dec 3, 2023

thanks for the feedback. already fixed in the latest stable version v7.1.0

@wing328 wing328 closed this as completed Dec 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants