Referencing from a JSON Schema V7 file conatining multiple definitions

Issue #228 new
Former user created an issue

Hi all, I'm getting this error when loading a YAML spec which references schemas held in a single JSON schema file.

com.atlassian.oai.validator.OpenApiInteractionValidator$ApiLoadException: Unable to load API spec from provided URL or payload:
        - attribute  is not of type `object`
        at com.atlassian.oai.validator.OpenApiInteractionValidator.loadApi(OpenApiInteractionValidator.java:162) ~[swagger-request-validator-core-2.4.6.jar:na]

Here's the OpenAPI spec file:

openapi: 3.0.0
info:
  title: Customer Service - demonstrating a request validation
  version: 1.0.0
paths:
  /customers:
    post:
      summary: Adds a new Customer
      requestBody:
        required: true
        content:
          application/vnd.api+json:
            schema:
              type: object
              required:
                - data
              properties:
                data:
                  $ref: '#/components/schemas/postCustomer'
      responses:
        '200':
          description: The new customer's data
          content:
            application/vnd.api+json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/getCustomer'
  '/customers/{customerId}':
    get:
      summary: Retrieves a single customer's data
      parameters:
        - $ref: '#/components/parameters/customerId'
      responses:
        '200':
          description: The matching customer data
          content:
            application/vnd.api+json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/getCustomer'
components:
  schemas:
    postCustomer:
      $ref: './api-customers-singleSchemaFile.json#/definitions/post'
    getCustomer:
      $ref: './api-customers-singleSchemaFile.json#/definitions/get'
  parameters:
    customerId:
      name: customerId
      in: path
      description: The id of the customer
      required: true
      schema:
        type: string

and the api-customers-singleSchemaFile.json:

{
    "$id": "https://example.com/customer.schema.json",
    "$schema": "http://json-schema.org/draft-07/schema#",
    "definitions": {
        "attributes": {
            "id": "#/definitions/attributes",
            "type": "object",
            "required": [
                "name"
            ],
            "properties": {
                "name": {
                    "type": "string"
                },
                "sector": {
                    "type": "string"
                }
            }
        },
        "post": {
            "id": "#/definitions/post",
            "type": "object",
            "properties":{
                "type": {
                    "type": "string"
                },
                "attributes": {
                    "$ref": "#/definitions/attributes"
                }
            }
        },
        "get": {
            "id": "#/definitions/get",
            "type": "object",
            "properties":{
                "id": {
                    "type": "string"
                },
                "type": {
                    "type": "string"
                },
                "attributes": {
                    "allOf": [
                        { 
                            "$ref": "#/definitions/attributes"
                        },
                        {
                            "properties": {
                                "createdOn": {
                                    "type": "string",
                                    "format": "date-time"        
                                },
                                "updatedOn": {
                                    "type": "string",
                                    "format": "date-time"        
                                }
                            }
                        }
                    ]
                }
            }
        }
    }
}

However, I can reference the same definitions referenced their own JSON schema file:

components:
  schemas:
    postCustomer:
      $ref: './api-customers-schemas-post.json'
    getCustomer:
      $ref: './api-customers-schemas-get.json'

api-customers-schemas-post.json:

{
    "$id": "https://example.com/customer-post.schema.json",
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "properties":{
        "type": {
            "type": "string"
        },
        "attributes": {
            "$ref": "api-customers-schemas-attributes.json"
        }
    }
}

I've read that some swagger-parser features aren't supported by 2.0.5, and followed the advice to add the dependency to my pom.xml with no luck:

        <dependency>
            <groupId>io.swagger.parser.v3</groupId>
            <artifactId>swagger-parser</artifactId>
            <version>2.0.13</version>
        </dependency>

Any ideas?

Comments (2)

  1. Alex Stevens

    Edit: I actually get this when starting the API:

    com.atlassian.oai.validator.OpenApiInteractionValidator$ApiLoadException: Unable to load API spec from provided URL or payload:
            - null
    
  2. James Navin

    Version 2.7.0 has bumped swagger-parser to 2.0.14. Could you please try that version and let me know if the problem still exists.

  3. Log in to comment