招摇$ref给"Could not resolve reference: undefined undefined"



所以我试图将我们在响应体中给出的对象分离到单独的yaml或json文件中它总是给出相同的错误

错误解析器错误:path ./api/thing.get.responses.200.content.application/json.schema.$ref无法解析引用:undefined undefined

这是我的主页。yaml文件:

openapi: 3.0.0
info:
version: '0.0.1'
title: 'thing-services'
license:
name: MIT
tags:
- name: thingReturn
description: ''
paths:
/api/thing:
get:
tags:
- thingReturn
description: 'Recovers things'
responses:
'200':
description: 'Returns a list of things.'
content:
application/json:
schema:
$ref: 'ThingList.yaml#/components/schemas/ThingList'
'204':
description: No Content. There was no content found.

这是我的ThingList。yaml文件:

components:
schemas:
ThingList:
type: array
items:
$ref: 'Thing.yaml#/components/schemas/Thing'

这是我的事。yaml文件:

components:
schemas:
Thing:
type: object
properties:
id:
type: string
property1:
type: integer
format: int32
property2:
type: integer
format: int32

假设所有东西都在同一个文件夹中(最初的想法是将对象放在"object-schemas"中)。文件夹),它也不起作用。如果我把对象放到Main中。带有"#/组件/模式/…"的Yaml文件,它工作得很好,但它违背了将所有内容组织在单独文件中的目的。我不知道我是不是忽略了什么。如有任何帮助,不胜感激。

好像有个小错字。

:

$ref: 'ThingList.yaml#components/schemas/ThingList'

一个缺失的斜杠,即需要:

$ref: 'ThingList.yaml#/components/schemas/ThingList'
另外,确保你引用的文件是有效的OpenAPI文档,例如:
openapi: 3.0.0
info:
version: '0.0.1'
title: 'thing'
license:
name: MIT
paths: {}
components:
schemas:
Thing:
type: object
properties:
id:
type: string
property1:
type: integer
format: int32
property2:
type: integer
format: int32

那么你的OpenAPI文件应该可以放在一起。

所以,在尝试并与我的同事交谈后,我们认为问题是围绕着相对路径,它是。我们必须写$ref关于它要去的存储库路径,它工作了!: D

真正给出提示的是浏览器的控制台。它给出了一个404错误,当点击它试图去的url时,它给出了一个{"error":"404 Not Found"},我们可以看到它试图去的url,这是错误的,关于我们正在开发的存储库。

编辑:如果MainFile。Yml与文件使用的对象在同一个文件夹中。这样的:

$ref: ../objectList.yml/raw?ref=branchName#/components/schemas/object

还在想办法怎么进入一个文件夹,里面应该包含我们正在使用的所有对象。我们尝试在$ref中写入,但仍然给出404:

$ref: ../folderOfObjects/objectList.yml/raw?ref=branchName#/components/schemas/object

第二次编辑:所以在和我的前辈谈过之后,这是一个编码的事情。参考gitlab api:

$ref: ..repository/files/folderOfObjects%2FobjectList.yml/raw?ref=branchName#/components/schemas/object

url "files/"后面的部分而在"&;/raw/"之前,如果有"&;/&;",则应该是"&;% 2f &;"。

这个帖子泄露了它:GitLab API -无法访问目录

中的文件

最新更新