如何 return 只有一个没有主体的状态代码与连接框架模拟
How to return only a status code without a body with connexion framework mock
我尝试使用 Connexion 作为 API 第一个框架,它从 Swagger 文件(附在最后)生成模拟。
然后我用 运行 Connexion 命令 connexion run ./swagger/swagger.yaml --mock=all --debug
。
这对 get
和 post
方法有效,但对 patch
方法无效,该方法只应 return 和 201
。对于这种情况,Connexion returns 如下:"No example response was defined."
有没有办法告诉 Connexion Mock 中不需要示例正文,只应 returned 一个 http 代码?
swagger: '2.0'
info:
description: Manages the customer of a digital marketplace
version: 1.0.0
title: Customers
contact:
email: den.seidel@gmail.com
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
host: virtserver.swaggerhub.com
basePath: /
schemes:
- https
paths:
/customers/{customer-id}/clients:
post:
summary: Adds a client to a customer identity.
description: https://auth0.com/docs/api/management/v2#!/Clients/post_clients
parameters:
- in: path
name: customer-id
type: string
description: The id of the customer.
required: true
- in: body
name: client
description: "Client item data"
required: false
schema:
type: object
required:
- client_name
- client_description
properties:
client_name:
type: string
example: "Peffermiza Broker Frontend"
client_description:
type: string
example: "This is the the frontend app for brokers."
allowed_callback_urls:
type: array
items:
type: string
example: 'http://localhost:3000/callback'
allowed_logout_urls:
type: array
items:
type: string
example: 'http://localhost:3000/logout'
produces:
- application/json
responses:
201:
description: OK
schema:
$ref: '#/definitions/Client'
400:
description: "invalid input, object invalid"
409:
description: "an existing item already exists"
security:
- oauth2:
- "https://api.d10l.de/customers:write"
get:
summary: Gets the clients of a customer identity.
description: https://auth0.com/docs/api/management/v2#!/Clients/get_clients
parameters:
- in: path
name: customer-id
type: string
description: The id of the customer.
required: true
produces:
- application/json
responses:
200:
description: A list of clients of the customer identity
schema:
type: object
properties:
clients:
type: array
items:
$ref: '#/definitions/Client'
example:
clients:
- date_created: "2016-08-29T09:12:33.001Z"
allowed_logout_urls:
- "http://localhost:3000/logout"
- "http://localhost:3000/logout"
client_secret: "94YJaDlR5QDpaS7Em6aC02_gj6kA1Q_G"
allowed_callback_urls:
- "http://localhost:3000/callback"
- "http://localhost:3000/callback"
client_name: "Peffermiza Broker Frontend"
client_description: 'The new broker application for the south region.'
client_id: "94YJaDlR5QDpaS7Em6aC02_gj6kA1Q_G"
- date_created: "2016-08-29T09:12:33.001Z"
allowed_logout_urls:
- "http://localhost:3000/logout"
- "http://localhost:3000/logout"
client_secret: "94YJaDlR5QDpaS7Em6aC02_gj6kA1Q_G"
allowed_callback_urls:
- "http://localhost:3000/callback"
- "http://localhost:3000/callback"
client_name: "The new broker application for the south region."
client_description:
client_id: "94YJaDlR5QDpaS7Em6aC02_gj6kA1Q_G"
400:
description: "bad input parameter"
security:
- oauth2:
- "https://api.d10l.de/customers:read"
/customers/{customer-id}/clients/{client-id}:
patch:
summary: Update the client of a customer
description: https://auth0.com/docs/api/management/v2#!/Clients/patch_clients_by_id
parameters:
- in: path
name: customer-id
type: string
description: The id of the customer.
required: true
- in: path
name: client-id
type: string
description: The id of the customer.
required: true
- in: body
name: client
schema:
$ref: '#/definitions/Client'
responses:
200:
description: OK
security:
- oauth2:
- "https://api.d10l.de/customers:write"
securityDefinitions:
oauth2:
type: oauth2
authorizationUrl: 'https://d10l.eu.auth0.com/authorize'
tokenUrl: 'https://d10l.eu.auth0.com/oauth/token'
flow: accessCode
scopes:
'https://api.d10l.de/customers:write': Access right needed to write to the customers service.
'https://api.d10l.de/customers:read': Access right needed to read from the customers service.
definitions:
Client:
type: object
required:
- client_id
- client_name
- client_description
- date_created
- client_secret
- allowed_callback_urls
- allowed_logout_urls
properties:
client_id:
type: string
example: 94YJaDlR5QDpaS7Em6aC02_gj6kA1Q_G
client_name:
type: string
example: 'Peffermiza Broker Frontend'
client_description:
type: string
example: 'The new broker application for the south region.'
date_created:
type: string
format: int32
example: '2016-08-29T09:12:33.001Z'
client_secret:
type: string
example: 94YJaDlR5QDpaS7Em6aC02_gj6kA1Q_G
allowed_callback_urls:
type: array
items:
type: string
example: 'http://localhost:3000/callback'
allowed_logout_urls:
type: array
items:
type: string
example: 'http://localhost:3000/logout'
example:
date_created: "2016-08-29T09:12:33.001Z"
allowed_logout_urls:
- "http://localhost:3000/logout"
- "http://localhost:3000/logout"
client_secret: "94YJaDlR5QDpaS7Em6aC02_gj6kA1Q_G"
allowed_callback_urls:
- "http://localhost:3000/callback"
- "http://localhost:3000/callback"
client_name: "Peffermiza Broker Frontend"
client_description: "The new broker backend for the south region."
client_id: "94YJaDlR5QDpaS7Em6aC02_gj6kA1Q_G"
目前 Connexion 不支持。您可以做的是创建一个空示例。这应该适合你的情况。
我还建议在 Connexion repository 中打开一个问题。
我尝试使用 Connexion 作为 API 第一个框架,它从 Swagger 文件(附在最后)生成模拟。
然后我用 运行 Connexion 命令 connexion run ./swagger/swagger.yaml --mock=all --debug
。
这对 get
和 post
方法有效,但对 patch
方法无效,该方法只应 return 和 201
。对于这种情况,Connexion returns 如下:"No example response was defined."
有没有办法告诉 Connexion Mock 中不需要示例正文,只应 returned 一个 http 代码?
swagger: '2.0'
info:
description: Manages the customer of a digital marketplace
version: 1.0.0
title: Customers
contact:
email: den.seidel@gmail.com
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
host: virtserver.swaggerhub.com
basePath: /
schemes:
- https
paths:
/customers/{customer-id}/clients:
post:
summary: Adds a client to a customer identity.
description: https://auth0.com/docs/api/management/v2#!/Clients/post_clients
parameters:
- in: path
name: customer-id
type: string
description: The id of the customer.
required: true
- in: body
name: client
description: "Client item data"
required: false
schema:
type: object
required:
- client_name
- client_description
properties:
client_name:
type: string
example: "Peffermiza Broker Frontend"
client_description:
type: string
example: "This is the the frontend app for brokers."
allowed_callback_urls:
type: array
items:
type: string
example: 'http://localhost:3000/callback'
allowed_logout_urls:
type: array
items:
type: string
example: 'http://localhost:3000/logout'
produces:
- application/json
responses:
201:
description: OK
schema:
$ref: '#/definitions/Client'
400:
description: "invalid input, object invalid"
409:
description: "an existing item already exists"
security:
- oauth2:
- "https://api.d10l.de/customers:write"
get:
summary: Gets the clients of a customer identity.
description: https://auth0.com/docs/api/management/v2#!/Clients/get_clients
parameters:
- in: path
name: customer-id
type: string
description: The id of the customer.
required: true
produces:
- application/json
responses:
200:
description: A list of clients of the customer identity
schema:
type: object
properties:
clients:
type: array
items:
$ref: '#/definitions/Client'
example:
clients:
- date_created: "2016-08-29T09:12:33.001Z"
allowed_logout_urls:
- "http://localhost:3000/logout"
- "http://localhost:3000/logout"
client_secret: "94YJaDlR5QDpaS7Em6aC02_gj6kA1Q_G"
allowed_callback_urls:
- "http://localhost:3000/callback"
- "http://localhost:3000/callback"
client_name: "Peffermiza Broker Frontend"
client_description: 'The new broker application for the south region.'
client_id: "94YJaDlR5QDpaS7Em6aC02_gj6kA1Q_G"
- date_created: "2016-08-29T09:12:33.001Z"
allowed_logout_urls:
- "http://localhost:3000/logout"
- "http://localhost:3000/logout"
client_secret: "94YJaDlR5QDpaS7Em6aC02_gj6kA1Q_G"
allowed_callback_urls:
- "http://localhost:3000/callback"
- "http://localhost:3000/callback"
client_name: "The new broker application for the south region."
client_description:
client_id: "94YJaDlR5QDpaS7Em6aC02_gj6kA1Q_G"
400:
description: "bad input parameter"
security:
- oauth2:
- "https://api.d10l.de/customers:read"
/customers/{customer-id}/clients/{client-id}:
patch:
summary: Update the client of a customer
description: https://auth0.com/docs/api/management/v2#!/Clients/patch_clients_by_id
parameters:
- in: path
name: customer-id
type: string
description: The id of the customer.
required: true
- in: path
name: client-id
type: string
description: The id of the customer.
required: true
- in: body
name: client
schema:
$ref: '#/definitions/Client'
responses:
200:
description: OK
security:
- oauth2:
- "https://api.d10l.de/customers:write"
securityDefinitions:
oauth2:
type: oauth2
authorizationUrl: 'https://d10l.eu.auth0.com/authorize'
tokenUrl: 'https://d10l.eu.auth0.com/oauth/token'
flow: accessCode
scopes:
'https://api.d10l.de/customers:write': Access right needed to write to the customers service.
'https://api.d10l.de/customers:read': Access right needed to read from the customers service.
definitions:
Client:
type: object
required:
- client_id
- client_name
- client_description
- date_created
- client_secret
- allowed_callback_urls
- allowed_logout_urls
properties:
client_id:
type: string
example: 94YJaDlR5QDpaS7Em6aC02_gj6kA1Q_G
client_name:
type: string
example: 'Peffermiza Broker Frontend'
client_description:
type: string
example: 'The new broker application for the south region.'
date_created:
type: string
format: int32
example: '2016-08-29T09:12:33.001Z'
client_secret:
type: string
example: 94YJaDlR5QDpaS7Em6aC02_gj6kA1Q_G
allowed_callback_urls:
type: array
items:
type: string
example: 'http://localhost:3000/callback'
allowed_logout_urls:
type: array
items:
type: string
example: 'http://localhost:3000/logout'
example:
date_created: "2016-08-29T09:12:33.001Z"
allowed_logout_urls:
- "http://localhost:3000/logout"
- "http://localhost:3000/logout"
client_secret: "94YJaDlR5QDpaS7Em6aC02_gj6kA1Q_G"
allowed_callback_urls:
- "http://localhost:3000/callback"
- "http://localhost:3000/callback"
client_name: "Peffermiza Broker Frontend"
client_description: "The new broker backend for the south region."
client_id: "94YJaDlR5QDpaS7Em6aC02_gj6kA1Q_G"
目前 Connexion 不支持。您可以做的是创建一个空示例。这应该适合你的情况。
我还建议在 Connexion repository 中打开一个问题。