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

OpenAPI 3.1 - SchemaResolution.INLINE not working with Array Type objects #4771

Closed
YousefHaggy opened this issue Oct 28, 2024 · 5 comments
Closed

Comments

@YousefHaggy
Copy link

YousefHaggy commented Oct 28, 2024

Having an issue with ModelResolver when resolving Array types

Say I have CustomObject.class, trying to resolve the schema of it's Array type class results in a Array schema with a reference

ModelResolver resolver = new ModelResolver(mapper).openapi31(true);
resolver.setSchemaResolution(SchemaResolution.INLINE);
context = new ModelConverterContextImpl(resolver);
context.resolve(new AnnotatedType().type(CustomObject[].class));

Resulting schema component:

{
  "items": {
    "$ref": "#/components/schemas/CustomObject"
   },
  type": "array"
}

SchemaResolution.INLINE doesn't inline these types. When I resolve a schema with that option, any properties that are array types on the class, ex: List, CustomObject[], get converted to Array reference schemas.

Is there anyways to generate fully inline Schemas when there are Array types? For SchemaResolution.INLINE, I would expect my above example to resolve as:

{
  "items": {
    "type": "object",
     "properties": {
       ...
      }
   },
  type": "array"
}
@YousefHaggy
Copy link
Author

YousefHaggy commented Oct 29, 2024

@frantuma Seeing that you worked on SchemaResolution PRs, do you think this change would make sense for SchemaResolution.INLINE? I could make a PR

Thanks!

@frantuma
Copy link
Member

As mentioned in wiki SchemaResolution only applies to OAS 3.0 specification, however the behaviour also occurred with OAS 3.0 specs (openapi31 = false) and this is fixed by this #4784 .

#4784 also introduces the option to set an ENV or System property apply-schema-resolution=true which causes the SchemaResolution to be partially processed also for 3.1 specs.

Closing ticket, please reopen if you're still experiencing issues

@YousefHaggy
Copy link
Author

Thanks @frantuma, I appreciate this. Could applySchemaResolution be moved to a function call in ModelResolver so that we can just override it in our custom resolver? Setting System properties is unideal in our workflow. I can open a PR for that if you think it's reasonable

protected boolean shouldApplySchemaResolution(){
return !openapi31 ||
                        (Boolean.parseBoolean(System.getProperty(Schema.APPLY_SCHEMA_RESOLUTION_PROPERTY, "false")) ||
                                Boolean.parseBoolean(System.getenv(Schema.APPLY_SCHEMA_RESOLUTION_PROPERTY)));
}

@frantuma
Copy link
Member

@YousefHaggy the flag has been added as quick solution for such edge use case, what I meant with partially processed also for 3.1 specs. is that to have it fully working more work is needed, both adding the option along all the involved code in different modules (basically similarly to what done for the schemaResolution option, and also ensure that behavior is correct.

That said, a PR to allow the same outcome currently obtained with the system property by updating ModelResolver is welcome!

@YousefHaggy
Copy link
Author

@frantuma Made a small PR to obtain the same outcome but move the check to a method to allow clients to override the default behavior
#4791

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants