swagger-api / swagger-api/swagger-core

[Open API 3.1] Json31 is incorrectly assuming that property containing `anyOf` is of type: object

Open
#4,810 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

backlog
Dominant language
Java
Stars
7.5k
Forks
2.3k
Avg merge
18h 1m
Merged PRs (30d)
10

Description

Using Json31.pretty() I'm getting back properties with anyOf containing "type": "object"

"image" : {
      "type" : "object",
      "anyOf" : [ {
        "type" : "string"
      }, {
        "type" : "null"
      } ],
      "title" : "Image"
    },

but this doesn't match my schema below, image doesn't contain "type": "object" :

"PreviewProduct": {
        "properties": {
          "id": {
            "type": "string",
            "title": "Id"
          },
          "handle": {
            "type": "string",
            "title": "Handle"
          },
          "title": {
            "type": "string",
            "title": "Title"
          },
          "productType": {
            "type": "string",
            "title": "Producttype"
          },
          "image": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Image"
          },
          "size": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Size"
          },
          "color": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Color"
          }
        },
        "type": "object",
        "required": [
          "id",
          "handle",
          "title",
          "productType"
        ],
        "title": "PreviewProduct",
        "description": "NOTE: This class is auto generated by OpenAPI Generator ([https://openapi-generator.tech).\n\nDo](https://openapi-generator.tech)./n/nDo) not edit the class manually.\n\nPreviewProduct - a model defined in OpenAPI\n\n    id: The id of this PreviewProduct.\n    handle: The handle of this PreviewProduct.\n    title: The title of this PreviewProduct.\n    product_type: The product_type of this PreviewProduct.\n    image: The image of this PreviewProduct [Optional].\n    size: The size of this PreviewProduct [Optional].\n    color: The color of this PreviewProduct [Optional]."
      }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in modules/swagger-core/src/main/java/io/swagger/v3/core/util/Json31.java at Json31.pretty(), and trace how properties containing anyOf are serialized. Compare the output with the supplied PreviewProduct schema; done means anyOf properties such as image, size, and color no longer gain an unsupported type: object.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.