OAS3 Resolving external schema containing allOf with $ref
See original GitHub issueWhen resolving a $ref to an external schema containing a $ref withing an allOf that internal $ref is not resolved.
The file to resolve:
openapi: 3.0.0
info:
version: 0.0.0
title: oneOf and anyOf
paths:
/oneOf:
get:
responses:
'200':
description: One of Cat or Dog
content:
application/json:
schema:
oneOf:
- $ref: 'http://timotej.se/smartbear/pets.yaml#/components/schemas/Cat'
- $ref: 'http://timotej.se/smartbear/pets.yaml#/components/schemas/Dog'
/anyOf:
get:
responses:
'200':
description: Any of Cat or Dog
content:
application/json:
schema:
anyOf:
- $ref: 'http://timotej.se/smartbear/pets.yaml#/components/schemas/Cat'
- $ref: 'http://timotej.se/smartbear/pets.yaml#/components/schemas/Dog'
Content of the external file:
openapi: 3.0.0
info:
version: 0.0.0
title: apa
components:
schemas:
Pet:
required:
- name
- petType
properties:
name:
type: string
petType:
type: string
Cat:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
properties:
huntingSkill:
type: string
default: lazy
enum:
- lazy
- aggressive
required:
- huntingSkill
Dog:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
properties:
packSize:
description: The size of the pack the dog is from
type: integer
required:
- packSize
Resolve using this code:
ParseOptions options = new ParseOptions();
options.setResolve(true);
OpenAPI openAPI = new OpenAPIV3Parser().readContents(yaml, null, options).getOpenAPI();
Yaml.pretty().writeValue(System.out, openAPI);
I would expect the output schema to contain Pet, Cat and Dog (since Pet is $ref:d from Cat and Dog). The actual value is only Cat and Dog. The $ref to Pet is now broken.
I have tested this with the currently latest version of 2.0 branch (1292a4e1a77fd4fdc3c4b1dfe29b3d15ac88fa7b)
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Using $ref - Swagger
OAS 3 This guide is for OpenAPI 3.0. Using $ref. When you document an API, it is common to have some features which...
Read more >OpenAPI Specification v3.1.0 | Introduction, Definitions, & More
The OpenAPI Specification (OAS) defines a standard, programming language-agnostic interface description for HTTP APIs.
Read more >External Services OpenAPI 3.0 Schema - Salesforce Help
Here's an example of an API spec that contains a supported JSON schema for OpenAPI 3.0. ... Example 2: Named Object Schema Reference...
Read more >json - Resolver error when referencing external schema files
Resolver error at paths./pet.get.responses.200.content.application/json.schema.allOf.1.properties.pets.items.allOf.0.$ref Could not resolve ...
Read more >How to use JSON references ($refs) - Redocly
re-use of schemas or other content. Reference structure. $ref key. The JSON Reference uses a $ ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yeah, it’s enough, I just added two more schemas 👍
I see 😃 But that example you created is enough for you, or did you want me to create something?