这可能是微不足道的问题,但是我在了解服务器变量以及如何在Swagger上修改它们时遇到问题。
我的目的是使用以下规格(其接口的5G 3GPP定义)创建服务器。
。
如您在此文件的顶部看到的那样,我们拥有一个称为 apiroot
的服务器变量,该变量定义了服务器URL的根。该设置为 example.com
的默认值。 Swagger-UI稍后将使用该URL为API提供图形接口。
servers:
- url: '{apiRoot}/nnef-eventexposure/v1'
variables:
apiRoot:
default: https://example.com
description: apiRoot as defined in clause 4.4 of 3GPP TS 29.501
我正在尝试使用Swagger-codegen生成服务器,该摇摇欲坠可生成一个包含该规范所需的所有元素的合并文件(因为原始YAML文件包含对其他文件的引用),
swagger-codegen generate -i https://www.3gpp.org/ftp/Specs/archive/OpenAPI/Rel-16/TS29122_PfdManagement.yaml -l go-server -o server
问题是该文件嵌入了默认值。因此,我无法在多个主机上使用该文件。
执行 Swagger-Codegen
时,有什么方法可以修改变量 apiroot
?甚至更好,是否有任何方法可以使用某种 envar
更改默认值?或者有什么方法可以通过Swagger apiroot
的
想法是,我们可以在不同的服务器中使用相同的规格,而无需修改原始规格文件或生成的文件。修改YAML文件的问题在于,将会有更多版本从3GPP开始,其中包括 apiroot
变量,因此我们不会每次都在修改。我们想以某种方式在运行时覆盖它。
this may be trivial question, but I am having problems understanding server variables and how to modify them on swagger.
My objective is to create a server using the specs below (5G 3gpp definitions for of its interfaces).
https://www.3gpp.org/ftp/Specs/archive/OpenAPI/Rel-16/TS29122_PfdManagement.yaml.
As you can see at the top of this file we have a server variable called apiRoot
which defines the root of the url of the server. That is set up to default value of example.com
. That url will later be used by swagger-ui to provide a graphic interface to the API.
servers:
- url: '{apiRoot}/nnef-eventexposure/v1'
variables:
apiRoot:
default: https://example.com
description: apiRoot as defined in clause 4.4 of 3GPP TS 29.501
I am trying to generate the server with the swagger-codegen which generates a consolidated file with all the elements this spec needs (since the original yaml file contains references to other files)
swagger-codegen generate -i https://www.3gpp.org/ftp/Specs/archive/OpenAPI/Rel-16/TS29122_PfdManagement.yaml -l go-server -o server
The problem is the file embeds the default value. So I can not use that file on multiple hosts.
Is there any way to modify variable apiRoot
when executing swagger-codegen
? Or even better, is there any way to change the value of the default using some kind of envar
? Or is there any way to pass swagger the value of apiRoot
The idea is we can use the same specs in different servers without having to modify the original spec file or the generated one. The problem with modifying the yaml files is that there will be more versions comming from 3gpp which will include apiRoot
variable, so we don't wang to keep modifying every single time. We would like to overwrite it somehow on runtime.
发布评论