swagger-api / swagger-api/swagger-parser
ExternalRefProcessor cannot read from a JSON schema file containing #/definitions
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 867
- Forks
- 560
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 7
Description
Hi all, I'm getting this error when loading a YAML spec which references mulitple schemas held in a single JSON schema file.
com.atlassian.oai.validator.OpenApiInteractionValidator$ApiLoadException: Unable to load API spec from provided URL or payload:
- null
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"
}
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with ExternalRefProcessor and the loadApi failure reported at OpenApiInteractionValidator.java:162. Reproduce the issue using the supplied OpenAPI YAML and shared JSON schema, then compare it with the working separate-schema references. Done means references using #/definitions load successfully without breaking the existing external-reference behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100