swagger-api / swagger-api/swagger-parser

[Openapi3.1] Ref inside of Items are not resolved

Open
#2,201 1 comment 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

I have an OrderCreate Schema that holds properties, one of this properties is an buggedProperty which is of type array, this property holds a schema OrderItem in Items that is not resolved. Is it normal behavior for items not to be resolved ?

Options Used:

ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveFully(true);
options.setInferSchemaType(true);
SwaggerParseResult result = new OpenAPIParser().readLocation(path, null, options);

Using the Following JSON :

{
    "openapi": "3.1.0",
    "info": {
        "title": "test",
        "description": "test desc",
        "version": "1.0.0"
    },
    "servers": [
        {
            "url": "redacted",
            "description": "desc"
        }
    ],
    "paths": {
        "/orders": {
            "post": {
                "tags": [
                    "orders"
                ],
                "summary": "Create Order",
                "operationId": "create_order_orders_post",
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/OrderCreate"
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "OrderCreate": {
                "properties": {
                    "delivery_address": {
                        "type": "string",
                        "title": "Delivery Address"
                    },
                    "phone_number": {
                        "type": "string",
                        "title": "Phone Number"
                    },
                    "buggedProperty": {
                        "items": {
                            "$ref": "#/components/schemas/OrderItem"
                        },
                        "type": "array",
                        "title": "Items",
                        "default": []
                    }
                },
                "type": "object",
                "required": [
                    "delivery_address",
                    "phone_number"
                ],
                "title": "OrderCreate"
            },
            "OrderItem": {
                "properties": {
                    "menu_item_id": {
                        "type": "integer",
                        "title": "Menu Item Id"
                    },
                    "quantity": {
                        "type": "integer",
                        "title": "Quantity"
                    }
                },
                "type": "object",
                "required": [
                    "menu_item_id",
                    "quantity"
                ],
                "title": "OrderItem"
            }
        }
    }
}

Result from:

 Schema<?> scheme = ((Schema<?>) parsedAPI.getComponents().getSchemas().get("OrderCreate").getProperties().get("buggedProperty")).getItems();

Is:

class JsonSchema {
    class Schema {
        type: null
        format: null
        $ref: #/components/schemas/OrderItem
        description: null
        title: null
        multipleOf: null
        maximum: null
        exclusiveMaximum: null
        minimum: null
        exclusiveMinimum: null
        maxLength: null
        minLength: null
        pattern: null
        maxItems: null
        minItems: null
        uniqueItems: null
        maxProperties: null
        minProperties: null
        required: null
        not: null
        properties: null
        additionalProperties: null
        nullable: null
        readOnly: null
        writeOnly: null
        example: null
        externalDocs: null
        deprecated: null
        discriminator: null
        xml: null
        patternProperties: null
        contains: null
        $id: null
        $anchor: null
        $schema: null
        $vocabulary: null
        $dynamicAnchor: null
        const: null
        contentEncoding: null
        contentMediaType: null
        contentSchema: null
        propertyNames: null
        unevaluatedProperties: null
        maxContains: null
        minContains: null
        additionalItems: null
        unevaluatedItems: null
        _if: null
        _else: null
        then: null
        dependentRequired: null
        dependentSchemas: null
        $comment: null
        prefixItems: null
    }
}

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

Reproduce the issue with OpenAPIParser().readLocation using the shown ParseOptions and JSON, then inspect OrderCreate.properties.buggedProperty.items. Compare the resolved result with the expected OrderItem schema and add a regression test showing whether references inside array items are resolved when resolve and resolveFully are enabled.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.