在我的项目中,我使用 Open API 3.0 来生成 mmodel 类。
我的要求是我必须将父类属性重用到子类。
例如:
public class Student {
private String id;
private String name;
}
public class Address {
private String id;
private String name;
private String city;
private String state;
}
但问题是 allOf 生成像下面这样的 bean 类,而不是上面的类。
public class Address {
public Student student;
private String city;
private String state;
}
下面是我的 schema.yaml
Student:
properties :
id:
type: integer
format: int64
description: The ID of the new account
name:
type: string
description: The human-readable description of this account
Address:
properties :
allOf:
$ref : '#/Student'
city:
type: string
description: City
state:
type: string
description: State
如何确保属性是重复的而不是创建对象。
任何帮助将不胜感激!!!
您可以在
allOf
元素下定义单独的部分。第一部分是对父对象的引用。第二部分是具有附加属性的对象。
以下内容在 https://editor.swagger.io 中正确解析:
openapi: 3.0.1
info:
title: "example"
version: "1.0"
paths:
/example:
post:
responses:
"200":
description: example
content:
application/json:
schema:
$ref: '#/components/schemas/Address'
components:
schemas:
Student:
properties:
id:
type: integer
format: int64
description: The ID of the new account
name:
type: string
description: The human-readable description of this account
Address:
allOf:
- $ref : '#/components/schemas/Student'
- type: object
properties:
city:
type: string
description: City
state:
type: string
description: State
I want to use two reference altogether in examples tags. How we can use that
"ResponseBody": {
"allOf": [
{ "$ref": "#/components/examples/exampleA" },
{ "$ref": "#/components/examples/exampleB" }
]
}
Its giving error as its saying it should not have additional properties allOf