-
Notifications
You must be signed in to change notification settings - Fork 2
Description
suppose I have two files
# api.yaml
openapi: 3.0.3
info:
title: chicken
version: 0.0.0
paths:
/get:
post:
operationId: getOneThing
requestBody:
$ref: '#/components/requestBodies/GetOneThingRequest'
responses:
200:
$ref: '#/components/responses/GetOneThingResponse'
components:
requestBodies:
GetOneThingRequest:
content:
application/json:
schema:
$ref: 'schemas.yaml#/components/schemas/ThingKey'
responses:
GetOneThingResponse:
description: one thing
content:
application/json:
schema:
$ref: 'schemas.yaml#/components/schemas/Thing'
# schemas.yaml
components:
schemas:
ThingKey:
type: object
properties:
userId:
type: integer
thingId:
type: integer
required:
- userId
- thingId
ThingData:
type: object
properties:
lastSeen:
type: string
format: date-time
value:
type: integer
Thing:
type: object
allOf:
- $ref: '#/components/schemas/ThingKey'
- $ref: '#/components/schemas/ThingData'
This is valid according to swagger-cli. However, if I run oapi2ts I get
stack: 'SyntaxError: Error resolving $ref pointer "#/components/schemas/ThingKey". \n' +
'Token "schemas" does not exist.\n' +
However, if I change the definition of Thing to
Thing:
type: object
allOf:
- $ref: 'schemas.yaml#/components/schemas/ThingKey'
- $ref: 'schemas.yaml#/components/schemas/ThingData'
It works correctly.
It almost seems as if the references are being resolved with respect to the original file they are given.
I can see that it might be very difficult to fix this issue with your current setup (which might require a stack of contexts or something equally awful). One option might be to look at using SwaggerParser.bundle at the beginning of execution to prevent this issue from arising.
Metadata
Metadata
Assignees
Labels
No labels