swagger-api / swagger-api/swagger-parser

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

Open
#2,144 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
867
Forks
560
Avg merge
2d 21h
Merged PRs (30d)
7

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 with the linked Json31.java file, especially Json31.pretty() around line 38, and compare its output for the shown anyOf-only image, size, and color properties with the supplied schema. Verify that the serialized properties no longer gain an unexpected object type while retaining their string-or-null anyOf definitions.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.