有一个带有字段的实体
cises:
type: array
description: An array of brands. The length must match the value of the quantity field, or the array must be empty
items:
type: string
Run Code Online (Sandbox Code Playgroud)
代码java
@SerializedName("cises")
private List<String> cises = null;
Run Code Online (Sandbox Code Playgroud)
如何使用 swagger codegen 默认设置一个空列表,而不是 null
问题:
我的 Rest Endpoint 的路由参数看起来像这样
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteDocument([FromRoute] DeleteDocumentRequest request)
Run Code Online (Sandbox Code Playgroud)
其中“DeleteDocumentRequest”有一个 gettor / settor
public Guid Id {get; set;}
Run Code Online (Sandbox Code Playgroud)
但是,当 swagger gen 将其序列化到 OpenApi 3.0 中时,它会生成错误,因为类中属性“Id”的大小写与路由中属性“id”不匹配。
问题:
如何重写序列化器以将我的所有属性更改为驼峰命名法以确保一致性?
在.NET 6中使用Newtonsoft Json,我尝试使用CamelCasePropertyNamesContractResolver以及ResolvePropertyName和CreateProperties的覆盖,但控制器端点中的参数不是被命中的“属性”。
我有一个django rest_framework API,Swagger和一个Swagger UI.当我没有登录时,我可以看到"登录"和"文档"的非常有限的视图.当我登录时,我可以看到很多东西.
我正在尝试使用swagger-codegen生成客户端:
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar \
generate -i http://127.0.0.1:8080/api/docs/ -l python -o myclient
Run Code Online (Sandbox Code Playgroud)
但是,它只生成一个非常有限的客户端,提供"登录"和"文档"功能.
如何让swagger-codegen知道如何使用http基本身份验证登录,以便生成更完整的客户端?
文档说我应该做以下,但我不知道它的期望:
-a <authorization>, --auth <authorization>
adds authorization headers when fetching the swagger definitions
remotely. Pass in a URL-encoded string of name:header with a comma
separating multiple values
Run Code Online (Sandbox Code Playgroud) 我正在使用 swagger 编辑器(版本 2.10.5)生成一个使用自定义标头的 Flask api,并开始向每个路径添加以下行:
parameters:
- $ref: '#/parameters/X-Forwarded-Host'
Run Code Online (Sandbox Code Playgroud)
相对定义:
X-Forwarded-Host:
name: 'X-Forwarded-Host'
in: header
description: Forwarded host header
required: true
type: string
Run Code Online (Sandbox Code Playgroud)
然后运行自动生成的flask server
$ python3 -m swagger_server
Run Code Online (Sandbox Code Playgroud)
造成一些问题:
发出 curl 请求时,标头未正确评估:
$ curl -X GET --header 'Accept: application/json' --header 'X-Forwarded-Host: example.com' http://localhost:8080
Run Code Online (Sandbox Code Playgroud)
返回
health_get() missing required positional argument: 'X_Forwarded_Host'
Run Code Online (Sandbox Code Playgroud)自动生成的测试也没有用:
headers = [('X_Forwarded_Host', 'X_Forwarded_Host_example'), ...
Run Code Online (Sandbox Code Playgroud)我究竟做错了什么?为什么swagger-editor(或codegen)将所有“-”设置为“_”?
提前致谢
我正在使用swagger-codegen为我的一个REST API生成Java REST客户端。REST API使用可选的标头参数。客户端中生成的方法具有一个附加参数,该参数采用标头。我希望在方法签名中没有header参数的情况下生成方法。我已经阅读了文档,但是找不到任何参考。
例如,对于具有选项X-CUSTOM-HEADER参数的GET all API,swagger-codegen生成如下方法:
public List<SomeType> findAllUsingGET1(String optionalHeader)
Run Code Online (Sandbox Code Playgroud)
我希望在哪里:
public List<SomeType> findAllUsingGET1()
Run Code Online (Sandbox Code Playgroud)
寻找解决方法的指针,而不是自定义客户端代码的生成。
"get": {
"summary": "findAll",
"operationId": "findAllUsingGET1",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"parameters": [
{
"name": "X-CUSTOM-HEADER",
"in": "header",
"description": "Custom Header",
"required": false,
"type": "string"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
Run Code Online (Sandbox Code Playgroud) 我nodejs-server根据我的swagger规范生成了我的服务器代码().
问题是,当我尝试从我的UI(不同的域)命中API时,我得到了一个众所周知的错误,即没有启用CORS:
XMLHttpRequest cannot load http://127.0.0.1:10010/events. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
我生成的index.js如下:
'use strict';
var fs = require('fs'),
path = require('path'),
http = require('http');
var app = require('connect')();
var swaggerTools = require('swagger-tools');
var jsyaml = require('js-yaml');
var serverPort = 10010;
// swaggerRouter configuration
var options = {
swaggerUi: path.join(__dirname, '/swagger.json'),
controllers: path.join(__dirname, './controllers'),
useStubs: process.env.NODE_ENV === 'development' // Conditionally turn on stubs (mock mode)
};
// The …Run Code Online (Sandbox Code Playgroud) 在我的新工作中,我遇到了一个麻烦的配置文件,如下所示:
{
"modelPackage": "aa",
"apiPackage": "aa.model",
"invokerPackage": "aa.model",
"bigDecimalAsString": true,
"hideGenerationTimestamp": true,
"withXml": false,
"serializableModel": false,
"dateLibrary": "java8-localdatetime",
"java8": true,
"fullJavaUtil": false,
"useRuntimeException": false,
"library": "resttemplate"
}
我想知道是否有任何可用参数的完整列表可用于配置摇摇欲坠。我一直在swagger官方网站上搜索它,但是找不到上面列出的所有命令。我将非常感谢您提供任何全面的资源,甚至可能是提及的列表:)
我正在使用Swagger Codegen生成JavaScript客户端:
swagger-codegen generate -i http://localhost:8080/v2/api-docs \
-l javascript -o subscreasy-javascript-client
Run Code Online (Sandbox Code Playgroud)
生成的模块的名称是api-documentation.
如何配置swagger-codegen以便使用自定义名称生成JavaScript模块?
我有一种下载二进制文件的方法。目前在 openapi.yaml 中有以下规范:
/processing/getZippedReports:
post:
tags:
- ProcessingRest
description: Get the reports
operationId: getZippedReports
requestBody:
description: The list of items for which to get the HTML
content:
application/json:
schema:
type: array
items:
type: string
required: true
responses:
200:
description: file with zipped reports
content:
application/octet-stream: {}
Run Code Online (Sandbox Code Playgroud)
生成的 typescript-angular 代码包含对 httpClient 的调用:
return this.httpClient.post<any>(`${this.configuration.basePath}/processing/getZippedReports`,
requestBody,
{
withCredentials: this.configuration.withCredentials,
headers: headers,
observe: observe,
reportProgress: reportProgress
}
);
Run Code Online (Sandbox Code Playgroud)
这样,angular 似乎无法接收二进制内容。我不得不更改 httpClient,使用 的非类型变量签名post并添加responseType: blob到参数
return this.httpClient.post(`${this.configuration.basePath}/processing/getZippedReports`,
requestBody,
{
withCredentials: this.configuration.withCredentials, …Run Code Online (Sandbox Code Playgroud) 尝试使用 swagger-codegen 为 PHP 生成 API 类。
[根据文档][1],它应该自动知道 JSON 和 YML 之间的区别。
看起来情况并非如此:
docker run --rm -v ${PWD}:/local swaggerapi/swagger-codegen-cli generate \
-i https://.../interface.yml \
-l php \
-o /local/out/php
Run Code Online (Sandbox Code Playgroud)
例外:
[main] ERROR io.swagger.parser.SwaggerCompatConverter - failed to read resource listing
com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'openapi': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
at [Source: (String)"openapi: 3.0.1
info:
title: Orders
description: This API documentation describes all endpoints for orders
...
Run Code Online (Sandbox Code Playgroud)
从 YML 生成客户端和实体的正确指令是什么?