我有一个REST服务要记录,其中一些服务接受简单的数组,比如:
[
{ "name":"a" },
{ "name":"b" },
{ "name":"c" }
]
我该如何在“大摇大摆的模特”一节中描述这一点?我只能像这样创建“命名数组”
model {
properties: { "arr": { "type":"array", ......
但它描述的数据如下:
"arr": [
{ "name":"a" },
{ "name":"b" },
{ "name":"c" }
]
可能是这样的:
...
"parameters" : [{
"name" : "whatEverThatArrayCalled",
"type" : "array",
"items" : {
"$ref" : "whatEverThatArrayCalled"
}
...
}],
"models" : {
{
"id" : "whatEverThatArrayCalled",
"properties":
{
"whatEverThatArrayCalled" :
{
"type" : "array",
"items":{"name":"a",
"name":"b",
"name":"c"
},
}
}
}
}
...
将此粘贴到http://editor.swagger.io/#/,然后点击“尝试此操作”
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Privacy-Service API"
},
"paths": {
"/allNames": {
"post": {
"consumes": [
"application/json",
"application/xml"
],
"produces": [
"application/json",
"application/xml"
],
"parameters": [
{
"name": "request",
"in": "body",
"schema": {
"$ref": "#/definitions/ArrayOfNames"
}
}
],
"responses": {
"200": {
"description": "List of names",
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
}
},
"definitions": {
"ArrayOfNames": {
"type": "array",
"items": {
"minItems": 1,
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"type": "string"
}
}
}
}
}
}
Tony YUEN很接近,但没有雪茄。这是在OpenAPI/Swagger中使用YAML的正确定义:
/test:
post:
summary: test 123
description: test 123
parameters:
- name: param1
in: body
required: true
description: test param1
schema:
$ref: '#/definitions/stackoverflow'
responses:
200:
description: OK
这将产生:
stackoverflow2[
{
name: string
}
]
托尼的例子产生了:
[
stackoverflow {
name: string
}
]
完成Swagger/OpenAPI作为YAML(复制
swagger: '2.0'
################################################################################
# API Information #
################################################################################
info:
version: "Two-point-Oh!"
title: Simple objects in array test
description: |
Simple objects in array test
################################################################################
# Parameters #
################################################################################
paths:
/test:
post:
summary: Array with named objects
description: Array with named objects
parameters:
- name: param1
in: body
required: true
description: test param1
schema:
type: array
items:
$ref: '#/definitions/stackoverflow'
responses:
200:
description: OK
/test2:
post:
summary: Array with simpel (nameless) objects
description: Array with simpel (nameless) objects
parameters:
- name: param1
in: body
required: true
description: test param1
schema:
$ref: '#/definitions/stackoverflow2'
responses:
200:
description: OK
definitions:
stackoverflow:
type: object
properties:
name:
type: string
description: name of the object
stackoverflow2:
type: array
items:
type: object
properties:
name:
type: string
description: name of the object
下面是一个JSON版本的Swagger/OpenAPI
{
"swagger" : "2.0",
"info" : {
"description" : "Simple objects in array test\n",
"version" : "Two-point-Oh!",
"title" : "Simple objects in array test"
},
"paths" : {
"/test" : {
"post" : {
"summary" : "Array with named objects",
"description" : "Array with named objects",
"parameters" : [ {
"in" : "body",
"name" : "param1",
"description" : "test param1",
"required" : true,
"schema" : {
"type" : "array",
"items" : {
"$ref" : "#/definitions/stackoverflow"
}
}
} ],
"responses" : {
"200" : {
"description" : "OK"
}
}
}
},
"/test2" : {
"post" : {
"summary" : "Array with simpel (nameless) objects",
"description" : "Array with simpel (nameless) objects",
"parameters" : [ {
"in" : "body",
"name" : "param1",
"description" : "test param1",
"required" : true,
"schema" : {
"$ref" : "#/definitions/stackoverflow2"
}
} ],
"responses" : {
"200" : {
"description" : "OK"
}
}
}
}
},
"definitions" : {
"stackoverflow" : {
"type" : "object",
"properties" : {
"name" : {
"type" : "string",
"description" : "name of the object"
}
}
},
"stackoverflow2" : {
"type" : "array",
"items" : {
"$ref" : "#/definitions/stackoverflow2_inner"
}
},
"stackoverflow2_inner" : {
"properties" : {
"name" : {
"type" : "string",
"description" : "name of the object"
}
}
}
}
}
可以为此使用注释吗?我不知道如何使用Yaml。 例: ItemsDto: 文章: https://swagger.io/docs/specification/data-models/dictionaries/自由形式对象"如果字典值可以是任何类型(也称为自由形式对象),请使用addtionalProperties: true:" 我将尝试在@Schema注释中使用'ref=myfile.yaml'
一般来说,一个描述器是一个有“绑定行为”的对象属性 (object attribute),它的访问控制被描述器协议方法重写。 这些方法是 __get__(), __set__() , 和 __delete__() 。 有这些方法的对象叫做描述器。 默认对属性的访问控制是从对象的字典里面 (__dict__) 中获取 (get) , 设置 (set) 和删除 (delete) 。 举例来说, a.x
本文向大家介绍简要描述下JS有哪些内置的对象相关面试题,主要包含被问及简要描述下JS有哪些内置的对象时的应答技巧和注意事项,需要的朋友参考一下 时间对象Date 字符串对象String 数学对象Math 数值对象Number 数组对象Array 函数对象Function 函数参数集合arguments 布尔对象Boolean 错误对象Error 基础对象Object
我有以下数组,当我做,我得到: 我尝试按如下方式访问阵列: 但这让我明白: 未定义的0 注: 我从Facebook SDK 4中获得了这个数组,所以我不知道最初的数组结构。 作为示例,我如何访问值来自阵列?
概述 JavaScript 提供了一个内部数据结构,用来描述对象的属性,控制它的行为,比如该属性是否可写、可遍历等等。这个内部数据结构称为“属性描述对象”(attributes object)。每个属性都有自己对应的属性描述对象,保存该属性的一些元信息。 下面是属性描述对象的一个例子。 { value: 123, writable: false, enumerable: true,
本文向大家介绍简述JavaScript对传统文档对象模型的支持,包括了简述JavaScript对传统文档对象模型的支持的使用技巧和注意事项,需要的朋友参考一下 这是将其在JavaScript语言早期版本中引入的模型。大家都被所有浏览器都支持,但只允许访问文件的某些关键部分,如表单,表单元素和图像。 该模型提供了若干个只读属性,如标题,URL和上次更改提供关于文档整体的信息。除了有由该模型可用于设