首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自定义Oracle ORDS生成的Swagger文档

自定义Oracle ORDS生成的Swagger文档
EN

Stack Overflow用户
提问于 2020-02-11 07:56:36
回答 1查看 600关注 0票数 1

我正在使用Oracle ORDS编写REST-API。ORDS在预定义的URL上生成Swagger2.0API文档。

我找不到如何添加自定义信息,比如端点描述的文本或从端点返回的“对象”的名称和模式。

这里有人知道如何调整ORDS生成的Swagger文档吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-11 12:48:26

我们最近增强了ORDS,使您可以将自定义注释注入Swagger样式的OpenAPI文档中。

18.4.0中的

新特征

ENH:28028432 - Echo p_comments值进入生成的Swagger文档早期版本

这里有个例子-

定义我的职位

代码语言:javascript
复制
BEGIN
  ORDS.DEFINE_HANDLER(
      p_module_name    => 'EXAMPLES',
      p_pattern        => 'id/',
      p_method         => 'POST',
      p_source_type    => 'plsql/block',
      p_items_per_page =>  0,
      p_mimes_allowed  => 'application/json',
      p_comments       => 'This is a bad example, has no error handling',
      p_source         => 
'begin
insert into identity_table (words) values (:words);
commit;
end;'
      );

  COMMIT; 
END;
/

现在,如果我转到模块的OpenAPI端点,您可以看到处理程序的描述文本已经被“注入”到服务文档中。

“这是个糟糕的例子,没有错误处理”--这是一个自由的文本字段,所以你基本上可以把你想要的任何东西放在那里。

代码语言:javascript
复制
{
"swagger": "2.0",
"info": {
"title": "ORDS generated API for EXAMPLES",
"version": "1.0.0"
},
"host": "localhost:8080",
"basePath": "/ords/pdb2/jeff/examples",
"schemes": [
"http"
],
"produces": [
"application/json"
],
"paths": {
"/id/": {
"get": {
"description": "Retrieve records from EXAMPLES",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "The queried record.",
"schema": {
"type": "object",
"properties": {
"ID": {
"$ref": "#/definitions/NUMBER"
},
"WORDS": {
"$ref": "#/definitions/VARCHAR2"
}
}
}
}
},
"parameters": []
},
"post": {
"description": "This is a bad example, has no error handling",
"responses": {
"201": {
"description": "The successfully created record.",
"schema": {
"type": "object",
"properties": {}
}
}
},
"consumes": [
"application/json"
],
"parameters": [
{
"name": "payload",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/EXAMPLES_ITEM"
}
}
]
}
},
"/id/{pk}": {
"get": {
"description": "Retrieve records from EXAMPLES",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "The queried record.",
"schema": {
"type": "object",
"properties": {
"ID": {
"$ref": "#/definitions/NUMBER"
},
"WORDS": {
"$ref": "#/definitions/VARCHAR2"
}
}
}
}
},
"parameters": [
{
"name": "pk",
"in": "path",
"required": true,
"type": "string",
"description": "implicit",
"pattern": "^[^/]+$"
}
]
}
}
},
"definitions": {
"NUMBER": {
"type": "number"
},
"VARCHAR2": {
"type": "string"
},
"EXAMPLES_ITEM": {
"properties": {
"words": {
"type": "string"
}
}
}
}
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60164240

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档