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

Confusion over using @Schema(oneOf = { String.class, Number.class }... #4247

Closed
mebigfatguy opened this issue Sep 7, 2022 · 1 comment
Closed

Comments

@mebigfatguy
Copy link

Using swagger: 2.2.2

I have an object that is used in a request body, with the following annotation on one of it's fields

public static class Area {

    @Schema(oneOf = { String.class, Number.class }, description = SwaggerAPIMessages.KEY, required = true, example = "")
    private Object key;

When i generate swagger, and import to editor.swagger.io i get

structural error at components.schemas.Area.properties.key
should NOT have additional properties
additionalProperty: jsonSchema
Jump to line 404

where the generated swagger there, is

Area:
  required:
    - key
    - value
  type: object
  properties:
    key:
      type: object
      description: The category part for a x,y plot
      jsonSchema:
        type: object
        description: The category part for a x,y plot

I also see no creation of the oneOf specification.

Anyone know what i'm doing wrong?

@frantuma
Copy link
Member

frantuma commented Sep 7, 2022

I guess there are 2 separate problems:

  1. Given the presence of jsonSchema value, this looks like to be at least partially caused by lack of usage of ObjectMapper configured by io.swagger.v3.core.util.Json or io.swagger.v3.core.util.Yaml. How are you serializing the resolved OpenAPI object? please use Yaml.pretty(openAPI)

  2. In your scenario (primitive or object type of field annotated with oneOf) 2.2.2 version indeed ignores oneOf annotations. refs #4247 - fix composed schema resolving on props #4248 fixes this, and it should work ok in lastest snapshot / next release.

Closing ticket, please reopen if still experiencing issues

@frantuma frantuma closed this as completed Sep 7, 2022
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