增加了openapi
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
* Copyright (c) 杭州颉创科技有限公司 2025. All rights reserved.
|
||||
* This source file is licensed under the MIT License found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package simcu::simapi.openapi.models
|
||||
|
||||
protected import simcu::simapi.openapi.interfaces.*
|
||||
@@ -0,0 +1,46 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
/*
|
||||
* Copyright (c) 杭州颉创科技有限公司 2025. All rights reserved.
|
||||
* This source file is licensed under the MIT License found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package simcu::simapi.openapi.models
|
||||
|
||||
import std.collection.*
|
||||
|
||||
/**
|
||||
* @brief 表示 OpenAPI 组件集合。
|
||||
*/
|
||||
public class OpenApiComponents <: IOpenApiSerializable {
|
||||
/**
|
||||
* @brief 表示组件中的架构集合。
|
||||
*/
|
||||
public var schemas = HashMap<String, OpenApiSchema>()
|
||||
|
||||
/**
|
||||
* @brief 创建 OpenAPI 组件实例。
|
||||
*/
|
||||
public init() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 按 OpenAPI V3 格式写出当前组件集合。
|
||||
* @param writer OpenAPI 写入器。
|
||||
*/
|
||||
public func serializeAsV3(writer: IOpenApiWriter): Unit {
|
||||
writer.startObject()
|
||||
if (!schemas.isEmpty()) {
|
||||
writer.writeName("schemas")
|
||||
writer.startObject()
|
||||
for ((key, value) in schemas) {
|
||||
writer.writeName(key)
|
||||
value.serializeAsV3(writer)
|
||||
}
|
||||
writer.endObject()
|
||||
}
|
||||
writer.endObject()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
/*
|
||||
* Copyright (c) 杭州颉创科技有限公司 2025. All rights reserved.
|
||||
* This source file is licensed under the MIT License found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package simcu::simapi.openapi.models
|
||||
|
||||
/**
|
||||
* @brief 表示 OpenAPI 联系人信息。
|
||||
*/
|
||||
public class OpenApiContact <: IOpenApiSerializable {
|
||||
/**
|
||||
* @brief 表示联系人名称。
|
||||
*/
|
||||
public var name: ?String = None
|
||||
/**
|
||||
* @brief 表示联系人地址。
|
||||
*/
|
||||
public var url: ?String = None
|
||||
/**
|
||||
* @brief 表示联系人邮箱。
|
||||
*/
|
||||
public var email: ?String = None
|
||||
/**
|
||||
* @brief 创建 OpenAPI 联系人实例。
|
||||
*/
|
||||
public init() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 按 OpenAPI V3 格式写出当前联系人信息。
|
||||
* @param writer OpenAPI 写入器。
|
||||
*/
|
||||
public func serializeAsV3(writer: IOpenApiWriter): Unit {
|
||||
writer.startObject()
|
||||
if (let Some(value) <- name) {
|
||||
writer.writeName("name")
|
||||
writer.writeValue(value)
|
||||
}
|
||||
|
||||
if (let Some(value) <- url) {
|
||||
writer.writeName("url")
|
||||
writer.writeValue(value)
|
||||
}
|
||||
|
||||
if (let Some(value) <- email) {
|
||||
writer.writeName("email")
|
||||
writer.writeValue(value)
|
||||
}
|
||||
|
||||
writer.endObject()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
/*
|
||||
* Copyright (c) 杭州颉创科技有限公司 2025. All rights reserved.
|
||||
* This source file is licensed under the MIT License found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package simcu::simapi.openapi.models
|
||||
|
||||
import std.collection.*
|
||||
|
||||
/**
|
||||
* @brief 表示 OpenAPI 文档对象。
|
||||
*/
|
||||
public class OpenApiDocument <: IOpenApiSerializable {
|
||||
/**
|
||||
* @brief 表示 OpenAPI 版本号。
|
||||
*/
|
||||
public var openapi: String = "3.0.1"
|
||||
/**
|
||||
* @brief 表示文档基本信息。
|
||||
*/
|
||||
public var info: ?OpenApiInfo = None
|
||||
/**
|
||||
* @brief 表示路径集合。
|
||||
*/
|
||||
public var paths: ?OpenApiPaths = None
|
||||
/**
|
||||
* @brief 表示组件集合。
|
||||
*/
|
||||
public var components: ?OpenApiComponents = None
|
||||
/**
|
||||
* @brief 表示标签集合。
|
||||
*/
|
||||
public var tags = ArrayList<OpenApiTag>()
|
||||
/**
|
||||
* @brief 表示服务器集合。
|
||||
*/
|
||||
public var servers = ArrayList<OpenApiServer>()
|
||||
/**
|
||||
* @brief 表示安全需求集合。
|
||||
*/
|
||||
public var securityRequirements = ArrayList<OpenApiSecurityRequirement>()
|
||||
|
||||
/**
|
||||
* @brief 创建 OpenAPI 文档对象。
|
||||
*/
|
||||
public init() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 按 OpenAPI V3 格式写出当前文档对象。
|
||||
* @param writer OpenAPI 写入器。
|
||||
*/
|
||||
public func serializeAsV3(writer: IOpenApiWriter): Unit {
|
||||
writer.startObject()
|
||||
writer.writeName("openapi")
|
||||
writer.writeValue(openapi)
|
||||
if (let Some(value) <- info) {
|
||||
writer.writeName("info")
|
||||
value.serializeAsV3(writer)
|
||||
}
|
||||
if (let Some(value) <- paths) {
|
||||
writer.writeName("paths")
|
||||
value.serializeAsV3(writer)
|
||||
}
|
||||
if (let Some(value) <- components) {
|
||||
writer.writeName("components")
|
||||
value.serializeAsV3(writer)
|
||||
}
|
||||
if (!tags.isEmpty()) {
|
||||
writer.writeName("tags")
|
||||
writer.startArray()
|
||||
for (tag in tags) {
|
||||
tag.serializeAsV3(writer)
|
||||
}
|
||||
writer.endArray()
|
||||
}
|
||||
if (!servers.isEmpty()) {
|
||||
writer.writeName("servers")
|
||||
writer.startArray()
|
||||
for (server in servers) {
|
||||
server.serializeAsV3(writer)
|
||||
}
|
||||
writer.endArray()
|
||||
}
|
||||
if (!securityRequirements.isEmpty()) {
|
||||
writer.writeName("security")
|
||||
writer.startArray()
|
||||
for (sec in securityRequirements) {
|
||||
sec.serializeAsV3(writer)
|
||||
}
|
||||
writer.endArray()
|
||||
}
|
||||
writer.endObject()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
/*
|
||||
* Copyright (c) 杭州颉创科技有限公司 2025. All rights reserved.
|
||||
* This source file is licensed under the MIT License found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package simcu::simapi.openapi.models
|
||||
|
||||
import std.collection.*
|
||||
|
||||
/**
|
||||
* @brief 表示 OpenAPI 可扩展字典基类。
|
||||
*/
|
||||
public abstract class OpenApiExtensibleDictionary<T> <: IOpenApiSerializable where T <: IOpenApiSerializable {
|
||||
private let _items: HashMap<String, T>
|
||||
|
||||
/**
|
||||
* @brief 创建一个空的 OpenAPI 可扩展字典。
|
||||
*/
|
||||
protected init() {
|
||||
this(HashMap<String, T>())
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 使用已有项创建 OpenAPI 可扩展字典。
|
||||
* @param items 初始字典项集合。
|
||||
*/
|
||||
protected init(items: HashMap<String, T>) {
|
||||
_items = items
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 返回内部字典项集合。
|
||||
* @return 当前字典中的所有项。
|
||||
*/
|
||||
protected prop items: HashMap<String, T> {
|
||||
get() {
|
||||
_items
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 添加字典项。
|
||||
* @param key 字典键。
|
||||
* @param value 字典值。
|
||||
*/
|
||||
public func add(key: String, value: T): Unit {
|
||||
_items.add(key, value)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 检查是否包含指定键。
|
||||
* @param key 要检查的字典键。
|
||||
* @return 如果包含指定键则返回 `true`。
|
||||
*/
|
||||
public func contains(key: String): Bool {
|
||||
_items.contains(key)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 通过键读取字典值。
|
||||
* @param key 要读取的字典键。
|
||||
* @return 对应的字典值。
|
||||
*/
|
||||
public operator func [](key: String): T {
|
||||
_items[key]
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 通过键设置字典值。
|
||||
* @param key 要设置的字典键。
|
||||
* @param value 要设置的字典值。
|
||||
*/
|
||||
public operator func [](key: String, value!: T): Unit {
|
||||
_items[key] = value
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 按 OpenAPI V3 格式写出当前字典对象。
|
||||
* @param writer OpenAPI 写入器。
|
||||
*/
|
||||
public func serializeAsV3(writer: IOpenApiWriter): Unit {
|
||||
writer.startObject()
|
||||
for ((key, value) in _items) {
|
||||
writer.writeName(key)
|
||||
value.serializeAsV3(writer)
|
||||
}
|
||||
writer.endObject()
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 检查当前字典是否为空。
|
||||
* @return 如果当前字典没有任何项则返回 `true`。
|
||||
*/
|
||||
public func isEmpty(): Bool {
|
||||
return _items.isEmpty()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
/*
|
||||
* Copyright (c) 杭州颉创科技有限公司 2025. All rights reserved.
|
||||
* This source file is licensed under the MIT License found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package simcu::simapi.openapi.models
|
||||
|
||||
/**
|
||||
* @brief 表示 OpenAPI 基本信息。
|
||||
*/
|
||||
public class OpenApiInfo <: IOpenApiSerializable {
|
||||
/**
|
||||
* @brief 表示文档标题。
|
||||
*/
|
||||
public var title: ?String = None
|
||||
/**
|
||||
* @brief 表示文档描述。
|
||||
*/
|
||||
public var description: ?String = None
|
||||
/**
|
||||
* @brief 表示文档版本。
|
||||
*/
|
||||
public var version: ?String = None
|
||||
/**
|
||||
* @brief 表示联系人信息。
|
||||
*/
|
||||
public var contact: ?OpenApiContact = None
|
||||
/**
|
||||
* @brief 表示许可证信息。
|
||||
*/
|
||||
public var license: ?OpenApiLicense = None
|
||||
|
||||
/**
|
||||
* @brief 创建 OpenAPI 基本信息实例。
|
||||
* @param title 文档标题。
|
||||
* @param version 文档版本。
|
||||
*/
|
||||
public init(title!: String, version!: String) {
|
||||
this.title = title
|
||||
this.version = version
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 按 OpenAPI V3 格式写出当前基本信息。
|
||||
* @param writer OpenAPI 写入器。
|
||||
*/
|
||||
public func serializeAsV3(writer: IOpenApiWriter): Unit {
|
||||
writer.startObject()
|
||||
if (let Some(value) <- title) {
|
||||
writer.writeName("title")
|
||||
writer.writeValue(value)
|
||||
}
|
||||
if (let Some(value) <- description) {
|
||||
writer.writeName("description")
|
||||
writer.writeValue(value)
|
||||
}
|
||||
if (let Some(value) <- version) {
|
||||
writer.writeName("version")
|
||||
writer.writeValue(value)
|
||||
}
|
||||
if (let Some(value) <- contact) {
|
||||
writer.writeName("contact")
|
||||
value.serializeAsV3(writer)
|
||||
}
|
||||
if (let Some(value) <- license) {
|
||||
writer.writeName("license")
|
||||
value.serializeAsV3(writer)
|
||||
}
|
||||
writer.endObject()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
/*
|
||||
* Copyright (c) 杭州颉创科技有限公司 2025. All rights reserved.
|
||||
* This source file is licensed under the MIT License found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package simcu::simapi.openapi.models
|
||||
|
||||
/**
|
||||
* @brief 表示 OpenAPI 许可证信息。
|
||||
*/
|
||||
public class OpenApiLicense <: IOpenApiSerializable {
|
||||
/**
|
||||
* @brief 表示许可证名称。
|
||||
*/
|
||||
public var name: ?String = None
|
||||
/**
|
||||
* @brief 表示许可证地址。
|
||||
*/
|
||||
public var url: ?String = None
|
||||
|
||||
/**
|
||||
* @brief 创建 OpenAPI 许可证实例。
|
||||
*/
|
||||
public init() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 按 OpenAPI V3 格式写出当前许可证信息。
|
||||
* @param writer OpenAPI 写入器。
|
||||
*/
|
||||
public func serializeAsV3(writer: IOpenApiWriter): Unit {
|
||||
writer.startObject()
|
||||
if (let Some(value) <- name) {
|
||||
writer.writeName("name")
|
||||
writer.writeValue(value)
|
||||
}
|
||||
if (let Some(value) <- url) {
|
||||
writer.writeName("url")
|
||||
writer.writeValue(value)
|
||||
}
|
||||
writer.endObject()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
/*
|
||||
* Copyright (c) 杭州颉创科技有限公司 2025. All rights reserved.
|
||||
* This source file is licensed under the MIT License found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package simcu::simapi.openapi.models
|
||||
|
||||
/**
|
||||
* @brief 表示 OpenAPI 媒体类型对象。
|
||||
*/
|
||||
public class OpenApiMediaType <: IOpenApiSerializable {
|
||||
/**
|
||||
* @brief 表示媒体类型对应的架构。
|
||||
*/
|
||||
public var schema: ?OpenApiSchema = None
|
||||
|
||||
/**
|
||||
* @brief 创建 OpenAPI 媒体类型实例。
|
||||
* @param schema 媒体类型对应的架构。
|
||||
*/
|
||||
public init(schema: ?OpenApiSchema) {
|
||||
this.schema = schema
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 按 OpenAPI V3 格式写出当前媒体类型对象。
|
||||
* @param writer OpenAPI 写入器。
|
||||
*/
|
||||
public func serializeAsV3(writer: IOpenApiWriter): Unit {
|
||||
writer.startObject()
|
||||
if (let Some(value) <- schema) {
|
||||
writer.writeName("schema")
|
||||
value.serializeAsV3(writer)
|
||||
}
|
||||
writer.endObject()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
/*
|
||||
* Copyright (c) 杭州颉创科技有限公司 2025. All rights reserved.
|
||||
* This source file is licensed under the MIT License found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package simcu::simapi.openapi.models
|
||||
|
||||
import std.collection.*
|
||||
|
||||
/**
|
||||
* @brief 表示 OpenAPI 操作对象。
|
||||
*/
|
||||
public class OpenApiOperation <: IOpenApiSerializable {
|
||||
/**
|
||||
* @brief 表示操作摘要。
|
||||
*/
|
||||
public var summary: ?String = None
|
||||
/**
|
||||
* @brief 表示操作描述。
|
||||
*/
|
||||
public var description: ?String = None
|
||||
/**
|
||||
* @brief 表示操作标识。
|
||||
*/
|
||||
public var operationId: ?String = None
|
||||
/**
|
||||
* @brief 表示操作响应集合。
|
||||
*/
|
||||
public var response = OpenApiResponses()
|
||||
/**
|
||||
* @brief 表示操作标签集合。
|
||||
*/
|
||||
public var tags = ArrayList<OpenApiTag>()
|
||||
/**
|
||||
* @brief 表示操作服务器集合。
|
||||
*/
|
||||
public var servers = ArrayList<OpenApiServer>()
|
||||
/**
|
||||
* @brief 表示操作请求体。
|
||||
*/
|
||||
public var requestBody:? OpenApiRequestBody = None
|
||||
/**
|
||||
* @brief 表示操作参数集合。
|
||||
*/
|
||||
public var parameters = ArrayList<OpenApiParameter>()
|
||||
/**
|
||||
* @brief 表示操作安全需求集合。
|
||||
*/
|
||||
public var security = ArrayList<OpenApiSecurityRequirement>()
|
||||
|
||||
/**
|
||||
* @brief 创建 OpenAPI 操作对象。
|
||||
*/
|
||||
public init() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 按 OpenAPI V3 格式写出当前操作对象。
|
||||
* @param writer OpenAPI 写入器。
|
||||
*/
|
||||
public func serializeAsV3(writer: IOpenApiWriter): Unit {
|
||||
writer.startObject()
|
||||
if (!tags.isEmpty()) {
|
||||
writer.writeName("tags")
|
||||
writer.startArray()
|
||||
for (tag in tags) {
|
||||
tag.serializeAsV3(writer)
|
||||
}
|
||||
writer.endArray()
|
||||
}
|
||||
if (let Some(value) <- summary) {
|
||||
writer.writeName("summary")
|
||||
writer.writeValue(value)
|
||||
}
|
||||
if (let Some(value) <- description) {
|
||||
writer.writeName("description")
|
||||
writer.writeValue(value)
|
||||
}
|
||||
if (let Some(value) <- operationId) {
|
||||
writer.writeName("operationId")
|
||||
writer.writeValue(value)
|
||||
}
|
||||
if (!servers.isEmpty()) {
|
||||
writer.writeName("servers")
|
||||
writer.startArray()
|
||||
for (server in servers) {
|
||||
server.serializeAsV3(writer)
|
||||
}
|
||||
writer.endArray()
|
||||
}
|
||||
if (!parameters.isEmpty()) {
|
||||
writer.writeName("parameters")
|
||||
writer.startArray()
|
||||
for (param in parameters) {
|
||||
param.serializeAsV3(writer)
|
||||
}
|
||||
writer.endArray()
|
||||
}
|
||||
if (!security.isEmpty()) {
|
||||
writer.writeName("security")
|
||||
writer.startArray()
|
||||
for (sec in security) {
|
||||
sec.serializeAsV3(writer)
|
||||
}
|
||||
writer.endArray()
|
||||
}
|
||||
if (!response.isEmpty()) {
|
||||
writer.writeName("responses")
|
||||
response.serializeAsV3(writer)
|
||||
}
|
||||
if (let Some(requestBody) <- requestBody) {
|
||||
writer.writeName("requestBody")
|
||||
requestBody.serializeAsV3(writer)
|
||||
}
|
||||
writer.endObject()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
/*
|
||||
* Copyright (c) 杭州颉创科技有限公司 2025. All rights reserved.
|
||||
* This source file is licensed under the MIT License found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package simcu::simapi.openapi.models
|
||||
|
||||
/**
|
||||
* @brief 表示 OpenAPI 参数对象。
|
||||
*/
|
||||
public class OpenApiParameter <: IOpenApiSerializable {
|
||||
/**
|
||||
* @brief 表示参数名称。
|
||||
*/
|
||||
public var name: ?String
|
||||
/**
|
||||
* @brief 表示参数是否必填。
|
||||
*/
|
||||
public var required: ?Bool
|
||||
/**
|
||||
* @brief 表示参数是否已弃用。
|
||||
*/
|
||||
public var deprecated: ?Bool
|
||||
/**
|
||||
* @brief 表示参数描述。
|
||||
*/
|
||||
public var description: ?String
|
||||
/**
|
||||
* @brief 表示参数架构。
|
||||
*/
|
||||
public var schema: ?OpenApiSchema = None
|
||||
/**
|
||||
* @brief 表示参数位置。
|
||||
*/
|
||||
public var location: ?ParameterLocation = None
|
||||
|
||||
/**
|
||||
* @brief 创建 OpenAPI 参数对象。
|
||||
* @param name 参数名称。
|
||||
* @param location 参数位置。
|
||||
* @param description 参数描述。
|
||||
* @param required 参数是否必填。
|
||||
* @param deprecated 参数是否已弃用。
|
||||
* @param schema 参数架构。
|
||||
*/
|
||||
public init(name!: ?String, location!: ?ParameterLocation = None, description!: ?String = None,
|
||||
required!: ?Bool = None, deprecated!: ?Bool = None, schema!: ?OpenApiSchema = None) {
|
||||
this.name = name
|
||||
this.schema = schema
|
||||
this.location = location
|
||||
this.required = required
|
||||
this.deprecated = deprecated
|
||||
this.description = description
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 按 OpenAPI V3 格式写出当前参数对象。
|
||||
* @param writer OpenAPI 写入器。
|
||||
*/
|
||||
public func serializeAsV3(writer: IOpenApiWriter): Unit {
|
||||
writer.startObject()
|
||||
if (let Some(value) <- name) {
|
||||
writer.writeName("name")
|
||||
writer.writeValue(value)
|
||||
}
|
||||
if (let Some(loc) <- location) {
|
||||
writer.writeName("in")
|
||||
writer.writeValue(loc.toString())
|
||||
}
|
||||
if (let Some(desc) <- description) {
|
||||
writer.writeName("description")
|
||||
writer.writeValue(desc)
|
||||
}
|
||||
if (let Some(req) <- required) {
|
||||
writer.writeName("required")
|
||||
writer.writeValue(req)
|
||||
}
|
||||
if (let Some(dep) <- deprecated) {
|
||||
writer.writeName("deprecated")
|
||||
writer.writeValue(dep)
|
||||
}
|
||||
if (let Some(s) <- schema) {
|
||||
writer.writeName("schema")
|
||||
s.serializeAsV3(writer)
|
||||
}
|
||||
writer.endObject()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
/*
|
||||
* Copyright (c) 杭州颉创科技有限公司 2025. All rights reserved.
|
||||
* This source file is licensed under the MIT License found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package simcu::simapi.openapi.models
|
||||
|
||||
import std.collection.*
|
||||
|
||||
/**
|
||||
* @brief 表示 OpenAPI 路径项对象。
|
||||
*/
|
||||
public class OpenApiPathItem <: IOpenApiSerializable {
|
||||
/**
|
||||
* @brief 表示路径项摘要。
|
||||
*/
|
||||
public var summary: ?String = None
|
||||
/**
|
||||
* @brief 表示路径项描述。
|
||||
*/
|
||||
public var description: ?String = None
|
||||
/**
|
||||
* @brief 表示当前路径项是否未解析引用。
|
||||
*/
|
||||
public var unresolvedReference: Bool = false
|
||||
/**
|
||||
* @brief 表示路径项引用。
|
||||
*/
|
||||
public var reference: ?OpenApiReference = None
|
||||
/**
|
||||
* @brief 表示路径项服务器集合。
|
||||
*/
|
||||
public var servers = ArrayList<OpenApiServer>()
|
||||
/**
|
||||
* @brief 表示路径项参数集合。
|
||||
*/
|
||||
public var parameters = ArrayList<OpenApiParameter>()
|
||||
/**
|
||||
* @brief 表示路径项操作集合。
|
||||
*/
|
||||
public var operations = HashMap<OperationType, OpenApiOperation>()
|
||||
|
||||
/**
|
||||
* @brief 创建 OpenAPI 路径项对象。
|
||||
*/
|
||||
public init() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 按 OpenAPI V3 格式写出当前路径项对象。
|
||||
* @param writer OpenAPI 写入器。
|
||||
*/
|
||||
public func serializeAsV3(writer: IOpenApiWriter): Unit {
|
||||
writer.startObject()
|
||||
if (let Some(value) <- summary) {
|
||||
writer.writeName("summary")
|
||||
writer.writeValue(value)
|
||||
}
|
||||
if (let Some(value) <- description) {
|
||||
writer.writeName("description")
|
||||
writer.writeValue(value)
|
||||
}
|
||||
if (unresolvedReference) {
|
||||
writer.writeName("$ref")
|
||||
if (let Some(value) <- reference) {
|
||||
writer.writeValue(value.toReferenceString())
|
||||
}
|
||||
}
|
||||
if (!servers.isEmpty()) {
|
||||
writer.writeName("servers")
|
||||
writer.startArray()
|
||||
for (server in servers) {
|
||||
server.serializeAsV3(writer)
|
||||
}
|
||||
writer.endArray()
|
||||
}
|
||||
if (!parameters.isEmpty()) {
|
||||
writer.writeName("parameters")
|
||||
writer.startArray()
|
||||
for (param in parameters) {
|
||||
param.serializeAsV3(writer)
|
||||
}
|
||||
writer.endArray()
|
||||
}
|
||||
for ((key, value) in operations) {
|
||||
writer.writeName(key.toString())
|
||||
value.serializeAsV3(writer)
|
||||
}
|
||||
writer.endObject()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
/*
|
||||
* Copyright (c) 杭州颉创科技有限公司 2025. All rights reserved.
|
||||
* This source file is licensed under the MIT License found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package simcu::simapi.openapi.models
|
||||
|
||||
import std.collection.*
|
||||
|
||||
/**
|
||||
* @brief 表示 OpenAPI 路径集合。
|
||||
*/
|
||||
public class OpenApiPaths <: OpenApiExtensibleDictionary<OpenApiPathItem> {
|
||||
/**
|
||||
* @brief 创建 OpenAPI 路径集合实例。
|
||||
*/
|
||||
public init() {
|
||||
|
||||
}
|
||||
|
||||
private init(paths: HashMap<String, OpenApiPathItem>) {
|
||||
super(paths)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
/*
|
||||
* Copyright (c) 杭州颉创科技有限公司 2025. All rights reserved.
|
||||
* This source file is licensed under the MIT License found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package simcu::simapi.openapi.models
|
||||
|
||||
/**
|
||||
* @brief 表示 OpenAPI 引用对象。
|
||||
*/
|
||||
public class OpenApiReference <: IOpenApiSerializable {
|
||||
/**
|
||||
* @brief 表示引用标识。
|
||||
*/
|
||||
public var id: String
|
||||
/**
|
||||
* @brief 表示引用类型。
|
||||
*/
|
||||
public var referenceType: ReferenceType
|
||||
|
||||
/**
|
||||
* @brief 创建 OpenAPI 引用对象。
|
||||
* @param referenceType 引用类型。
|
||||
* @param id 引用标识。
|
||||
*/
|
||||
public init(referenceType: ReferenceType, id: String) {
|
||||
this.id = id
|
||||
this.referenceType = referenceType
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 返回当前引用在 OpenAPI 文档中的字符串值。
|
||||
* @return 引用字符串。
|
||||
*/
|
||||
public func toReferenceString(): String {
|
||||
if (ReferenceType.Tag == referenceType) {
|
||||
return id
|
||||
}
|
||||
return "#/components/${referenceType.toString()}/${id}"
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 按 OpenAPI V3 格式写出当前引用对象。
|
||||
* @param writer OpenAPI 写入器。
|
||||
*/
|
||||
public func serializeAsV3(writer: IOpenApiWriter): Unit {
|
||||
if (ReferenceType.Tag == referenceType) {
|
||||
writer.writeValue(id)
|
||||
return
|
||||
}
|
||||
writer.startObject()
|
||||
writer.writeName("$ref")
|
||||
writer.writeValue(toReferenceString())
|
||||
writer.endObject()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
/*
|
||||
* Copyright (c) 杭州颉创科技有限公司 2025. All rights reserved.
|
||||
* This source file is licensed under the MIT License found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package simcu::simapi.openapi.models
|
||||
|
||||
import std.collection.*
|
||||
|
||||
/**
|
||||
* @brief 表示 OpenAPI 请求体对象。
|
||||
*/
|
||||
public class OpenApiRequestBody <: IOpenApiSerializable {
|
||||
/**
|
||||
* @brief 表示请求体是否必填。
|
||||
*/
|
||||
public var required: Bool = false
|
||||
/**
|
||||
* @brief 表示请求体描述。
|
||||
*/
|
||||
public var description: ?String = None
|
||||
/**
|
||||
* @brief 表示请求体内容映射。
|
||||
*/
|
||||
public var content = HashMap<String, OpenApiMediaType>()
|
||||
|
||||
/**
|
||||
* @brief 创建 OpenAPI 请求体对象。
|
||||
* @param required 请求体是否必填。
|
||||
* @param description 请求体描述。
|
||||
*/
|
||||
public init(required!: Bool = false, description!: ?String = None) {
|
||||
this.required = required
|
||||
this.description = description
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 按 OpenAPI V3 格式写出当前请求体对象。
|
||||
* @param writer OpenAPI 写入器。
|
||||
*/
|
||||
public func serializeAsV3(writer: IOpenApiWriter): Unit {
|
||||
writer.startObject()
|
||||
if (let Some(desc) <- description) {
|
||||
writer.writeName("description")
|
||||
writer.writeValue(desc)
|
||||
}
|
||||
if (!content.isEmpty()) {
|
||||
writer.writeName("content")
|
||||
writer.startObject()
|
||||
for ((key, value) in content) {
|
||||
writer.writeName(key)
|
||||
value.serializeAsV3(writer)
|
||||
}
|
||||
writer.endObject()
|
||||
}
|
||||
if (required) {
|
||||
writer.writeName("required")
|
||||
writer.writeValue(true)
|
||||
}
|
||||
writer.endObject()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
/*
|
||||
* Copyright (c) 杭州颉创科技有限公司 2025. All rights reserved.
|
||||
* This source file is licensed under the MIT License found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package simcu::simapi.openapi.models
|
||||
|
||||
import std.collection.*
|
||||
|
||||
/**
|
||||
* @brief 表示 OpenAPI 响应对象。
|
||||
*/
|
||||
public class OpenApiResponse <: IOpenApiSerializable {
|
||||
/**
|
||||
* @brief 表示响应描述。
|
||||
*/
|
||||
public var description: String
|
||||
/**
|
||||
* @brief 表示响应内容映射。
|
||||
*/
|
||||
public var content = HashMap<String, OpenApiMediaType>()
|
||||
|
||||
/**
|
||||
* @brief 创建 OpenAPI 响应对象。
|
||||
* @param description 响应描述。
|
||||
*/
|
||||
public init(description: String) {
|
||||
this.description = description
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 按 OpenAPI V3 格式写出当前响应对象。
|
||||
* @param writer OpenAPI 写入器。
|
||||
*/
|
||||
public func serializeAsV3(writer: IOpenApiWriter): Unit {
|
||||
writer.startObject()
|
||||
writer.writeName("description")
|
||||
writer.writeValue(description)
|
||||
if (!content.isEmpty()) {
|
||||
writer.writeName("content")
|
||||
writer.startObject()
|
||||
for ((key, value) in content) {
|
||||
writer.writeName(key)
|
||||
value.serializeAsV3(writer)
|
||||
}
|
||||
writer.endObject()
|
||||
}
|
||||
writer.endObject()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
/*
|
||||
* Copyright (c) 杭州颉创科技有限公司 2025. All rights reserved.
|
||||
* This source file is licensed under the MIT License found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package simcu::simapi.openapi.models
|
||||
|
||||
/**
|
||||
* @brief 表示 OpenAPI 响应集合。
|
||||
*/
|
||||
public class OpenApiResponses <: OpenApiExtensibleDictionary<OpenApiResponse> {
|
||||
/**
|
||||
* @brief 创建 OpenAPI 响应集合实例。
|
||||
*/
|
||||
public init() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
/*
|
||||
* Copyright (c) 杭州颉创科技有限公司 2025. All rights reserved.
|
||||
* This source file is licensed under the MIT License found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package simcu::simapi.openapi.models
|
||||
|
||||
import std.collection.*
|
||||
|
||||
/**
|
||||
* @brief 表示 OpenAPI 架构对象。
|
||||
*/
|
||||
public class OpenApiSchema <: IOpenApiSerializable {
|
||||
/**
|
||||
* @brief 表示架构标题。
|
||||
*/
|
||||
public var title: ?String = None
|
||||
/**
|
||||
* @brief 表示架构是否可为空。
|
||||
*/
|
||||
public var nullable: ?Bool = None
|
||||
/**
|
||||
* @brief 表示架构类型。
|
||||
*/
|
||||
public var `type`: ?String = None
|
||||
/**
|
||||
* @brief 表示数组元素架构。
|
||||
*/
|
||||
public var items: ?OpenApiSchema = None
|
||||
/**
|
||||
* @brief 表示架构格式。
|
||||
*/
|
||||
public var format: ?String = None
|
||||
/**
|
||||
* @brief 表示架构描述。
|
||||
*/
|
||||
public var description: ?String = None
|
||||
/**
|
||||
* @brief 表示架构引用。
|
||||
*/
|
||||
public var reference: ?OpenApiReference = None
|
||||
/**
|
||||
* @brief 表示对象属性集合。
|
||||
*/
|
||||
public var properties = HashMap<String, OpenApiSchema>()
|
||||
/**
|
||||
* @brief 表示 allOf 组合架构。
|
||||
*/
|
||||
public var allOf = ArrayList<OpenApiSchema>()
|
||||
/**
|
||||
* @brief 表示是否允许附加属性。
|
||||
*/
|
||||
public var additionalProperties: ?Bool = None
|
||||
/**
|
||||
* @brief 表示附加属性的值架构。
|
||||
*/
|
||||
public var additionalPropertiesSchema: ?OpenApiSchema = None
|
||||
|
||||
/**
|
||||
* @brief 创建 OpenAPI 架构对象。
|
||||
* @param title 架构标题。
|
||||
* @param nullable 架构是否可为空。
|
||||
* @param `type` 架构类型。
|
||||
* @param items 数组元素架构。
|
||||
* @param format 架构格式。
|
||||
* @param reference 架构引用。
|
||||
* @param description 架构描述。
|
||||
*/
|
||||
public init(title!: ?String = None, nullable!: ?Bool = None, `type`!: ?String = None, items!: ?OpenApiSchema = None,
|
||||
format!: ?String = None, reference!: ?OpenApiReference = None, description!: ?String = None) {
|
||||
this.title = title
|
||||
this.format = format
|
||||
this.`type` = `type`
|
||||
this.items = items
|
||||
this.nullable = nullable
|
||||
this.reference = reference
|
||||
this.description = description
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 按 OpenAPI V3 格式写出当前架构对象。
|
||||
* @param writer OpenAPI 写入器。
|
||||
*/
|
||||
public func serializeAsV3(writer: IOpenApiWriter): Unit {
|
||||
if (let Some(reference) <- reference) {
|
||||
reference.serializeAsV3(writer)
|
||||
} else {
|
||||
serializeAsV3WithoutReference(writer)
|
||||
}
|
||||
}
|
||||
|
||||
private func serializeAsV3WithoutReference(writer: IOpenApiWriter) {
|
||||
writer.startObject()
|
||||
if (let Some(value) <- title) {
|
||||
writer.writeName("title")
|
||||
writer.writeValue(value)
|
||||
}
|
||||
if (let Some(value) <- `type`) {
|
||||
writer.writeName("type")
|
||||
writer.writeValue(value)
|
||||
}
|
||||
if (let Some(value) <- items) {
|
||||
writer.writeName("items")
|
||||
value.serializeAsV3(writer)
|
||||
}
|
||||
if (let Some(value) <- nullable && value) {
|
||||
writer.writeName("nullable")
|
||||
writer.writeValue(value)
|
||||
}
|
||||
if (let Some(value) <- format) {
|
||||
writer.writeName("format")
|
||||
writer.writeValue(value)
|
||||
}
|
||||
if (let Some(value) <- description) {
|
||||
writer.writeName("description")
|
||||
writer.writeValue(value)
|
||||
}
|
||||
if (!properties.isEmpty()) {
|
||||
writer.writeName("properties")
|
||||
writer.startObject()
|
||||
for ((key, value) in properties) {
|
||||
writer.writeName(key)
|
||||
value.serializeAsV3(writer)
|
||||
}
|
||||
writer.endObject()
|
||||
}
|
||||
if (!allOf.isEmpty()) {
|
||||
writer.writeName("allOf")
|
||||
writer.startArray()
|
||||
for (schema in allOf) {
|
||||
schema.serializeAsV3(writer)
|
||||
}
|
||||
writer.endArray()
|
||||
}
|
||||
if (let Some(value) <- additionalPropertiesSchema) {
|
||||
writer.writeName("additionalProperties")
|
||||
value.serializeAsV3(writer)
|
||||
} else if (let Some(value) <- additionalProperties) {
|
||||
writer.writeName("additionalProperties")
|
||||
writer.writeValue(value)
|
||||
}
|
||||
writer.endObject()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 杭州颉创科技有限公司 2025. All rights reserved.
|
||||
* This source file is licensed under the MIT License found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package simcu::simapi.openapi.models
|
||||
|
||||
import std.reflect.*
|
||||
|
||||
|
||||
private let numbers = ["Float16", "Float32", "Float64", "Decimal"]
|
||||
private let integers = ["Int8", "Int16", "Int32", "Int64", "UInt8", "UInt16", "UInt32", "UInt64"]
|
||||
|
||||
protected class OpenApiSchemaTypes {
|
||||
public static const OBJECT = "object"
|
||||
public static const STRING = "string"
|
||||
public static const ARRAY = "array"
|
||||
|
||||
/**
|
||||
* @brief 将类型信息转换为 OpenAPI Schema 类型名称。
|
||||
* @param typeInfo 要转换的类型信息。
|
||||
* @return 对应的 OpenAPI Schema 类型名称。
|
||||
*/
|
||||
public static func convert(typeInfo: TypeInfo): String {
|
||||
if (typeInfo.name == "Bool") {
|
||||
return "boolean"
|
||||
}
|
||||
if (typeInfo.name == "String" || typeInfo.name == "DateTime" || typeInfo.name == "BigInt" ||
|
||||
typeInfo.name == "Rune") {
|
||||
return "string"
|
||||
}
|
||||
if (numbers.contains(typeInfo.name)) {
|
||||
return "number"
|
||||
}
|
||||
if (integers.contains(typeInfo.name)) {
|
||||
return "integer"
|
||||
}
|
||||
return OpenApiSchemaTypes.OBJECT
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
/*
|
||||
* Copyright (c) 杭州颉创科技有限公司 2025. All rights reserved.
|
||||
* This source file is licensed under the MIT License found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package simcu::simapi.openapi.models
|
||||
|
||||
/**
|
||||
* @brief 表示 OpenAPI 安全需求对象。
|
||||
*/
|
||||
public class OpenApiSecurityRequirement <: IOpenApiSerializable {
|
||||
/**
|
||||
* @brief 创建 OpenAPI 安全需求对象。
|
||||
*/
|
||||
public init() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 按 OpenAPI V3 格式写出当前安全需求对象。
|
||||
* @param writer OpenAPI 写入器。
|
||||
*/
|
||||
public func serializeAsV3(writer: IOpenApiWriter): Unit {}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
/*
|
||||
* Copyright (c) 杭州颉创科技有限公司 2025. All rights reserved.
|
||||
* This source file is licensed under the MIT License found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package simcu::simapi.openapi.models
|
||||
|
||||
/**
|
||||
* @brief 表示 OpenAPI 服务器对象。
|
||||
*/
|
||||
public class OpenApiServer <: IOpenApiSerializable {
|
||||
/**
|
||||
* @brief 表示服务器描述。
|
||||
*/
|
||||
public var description: ?String = None
|
||||
/**
|
||||
* @brief 表示服务器地址。
|
||||
*/
|
||||
public var url: ?String = None
|
||||
|
||||
/**
|
||||
* @brief 创建 OpenAPI 服务器对象。
|
||||
*/
|
||||
public init() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 按 OpenAPI V3 格式写出当前服务器对象。
|
||||
* @param writer OpenAPI 写入器。
|
||||
*/
|
||||
public func serializeAsV3(writer: IOpenApiWriter): Unit {
|
||||
writer.startObject()
|
||||
if (let Some(value) <- url) {
|
||||
writer.writeName("url")
|
||||
writer.writeValue(value)
|
||||
}
|
||||
if (let Some(value) <- description) {
|
||||
writer.writeName("description")
|
||||
writer.writeValue(value)
|
||||
}
|
||||
writer.endObject()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
/*
|
||||
* Copyright (c) 杭州颉创科技有限公司 2025. All rights reserved.
|
||||
* This source file is licensed under the MIT License found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package simcu::simapi.openapi.models
|
||||
|
||||
/**
|
||||
* @brief 表示 OpenAPI 标签对象。
|
||||
*/
|
||||
public class OpenApiTag <: IOpenApiSerializable {
|
||||
/**
|
||||
* @brief 表示标签名称。
|
||||
*/
|
||||
public var name: ?String = None
|
||||
/**
|
||||
* @brief 表示标签描述。
|
||||
*/
|
||||
public var description: ?String = None
|
||||
/**
|
||||
* @brief 表示标签引用。
|
||||
*/
|
||||
public var reference: ?OpenApiReference = None
|
||||
|
||||
/**
|
||||
* @brief 创建 OpenAPI 标签对象。
|
||||
* @param name 标签名称。
|
||||
* @param reference 标签引用。
|
||||
* @param description 标签描述。
|
||||
*/
|
||||
public init(name!: ?String = None, reference!: ?OpenApiReference = None, description!: ?String = None) {
|
||||
this.name = name
|
||||
this.reference = reference
|
||||
this.description = description
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 按 OpenAPI V3 格式写出当前标签对象。
|
||||
* @param writer OpenAPI 写入器。
|
||||
*/
|
||||
public func serializeAsV3(writer: IOpenApiWriter): Unit {
|
||||
if (let Some(reference) <- reference) {
|
||||
reference.serializeAsV3(writer)
|
||||
return
|
||||
}
|
||||
if (let Some(name) <- name) {
|
||||
writer.writeValue(name)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
/*
|
||||
* Copyright (c) 杭州颉创科技有限公司 2025. All rights reserved.
|
||||
* This source file is licensed under the MIT License found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package simcu::simapi.openapi.models
|
||||
|
||||
import soulsoft_web_http.*
|
||||
|
||||
/**
|
||||
* @brief 表示 OpenAPI 操作类型。
|
||||
*/
|
||||
public enum OperationType <: Equatable<OperationType> & Hashable & IOpenApiSerializable {
|
||||
/**
|
||||
* @brief 表示 GET 操作。
|
||||
*/
|
||||
Get
|
||||
/**
|
||||
* @brief 表示 PUT 操作。
|
||||
*/
|
||||
| Put
|
||||
/**
|
||||
* @brief 表示 POST 操作。
|
||||
*/
|
||||
| Post
|
||||
/**
|
||||
* @brief 表示 DELETE 操作。
|
||||
*/
|
||||
| Delete
|
||||
/**
|
||||
* @brief 表示 OPTIONS 操作。
|
||||
*/
|
||||
| Options
|
||||
/**
|
||||
* @brief 表示 HEAD 操作。
|
||||
*/
|
||||
| Head
|
||||
/**
|
||||
* @brief 表示 PATCH 操作。
|
||||
*/
|
||||
| Patch
|
||||
/**
|
||||
* @brief 表示 TRACE 操作。
|
||||
*/
|
||||
| Trace
|
||||
/**
|
||||
* @brief 表示未知操作。
|
||||
*/
|
||||
| Unkonw
|
||||
|
||||
/**
|
||||
* @brief 比较两个操作类型是否相等。
|
||||
* @param that 要比较的操作类型。
|
||||
* @return 如果两个操作类型相等则返回 `true`。
|
||||
*/
|
||||
public operator func ==(that: OperationType): Bool {
|
||||
match ((this, that)) {
|
||||
case (Get, Get) => true
|
||||
case (Put, Put) => true
|
||||
case (Post, Post) => true
|
||||
case (Delete, Delete) => true
|
||||
case (Options, Options) => true
|
||||
case (Head, Head) => true
|
||||
case (Patch, Patch) => true
|
||||
case (Trace, Trace) => true
|
||||
case _ => false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 按 OpenAPI V3 格式写出当前操作类型。
|
||||
* @param writer OpenAPI 写入器。
|
||||
*/
|
||||
public func serializeAsV3(writer: IOpenApiWriter): Unit {
|
||||
writer.writeValue(this.toString())
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 返回当前操作类型的哈希值。
|
||||
* @return 当前操作类型的哈希值。
|
||||
*/
|
||||
public func hashCode(): Int64 {
|
||||
this.toString().hashCode()
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 将 HTTP 方法字符串解析为操作类型。
|
||||
* @param str 要解析的 HTTP 方法字符串。
|
||||
* @return 解析得到的操作类型。
|
||||
* @throws IllegalFormatException 当字符串不是支持的 HTTP 方法时抛出。
|
||||
*/
|
||||
public static func parse(str: String): OperationType {
|
||||
match (str) {
|
||||
case x where HttpMethods.isGet(x) => Get
|
||||
case x where HttpMethods.isPut(x) => Put
|
||||
case x where HttpMethods.isPost(x) => Post
|
||||
case x where HttpMethods.isDelete(x) => Delete
|
||||
case x where HttpMethods.isOptions(x) => Options
|
||||
case x where HttpMethods.isHead(x) => Head
|
||||
case x where HttpMethods.isPatch(x) => Patch
|
||||
case x where HttpMethods.isTrace(x) => Trace
|
||||
case _ => throw IllegalFormatException("Invalid OperationType format: ${str}")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 返回操作类型对应的名称。
|
||||
* @return 当前操作类型对应的名称字符串。
|
||||
*/
|
||||
public func toString(): String {
|
||||
match (this) {
|
||||
case Get => "get"
|
||||
case Put => "put"
|
||||
case Post => "post"
|
||||
case Delete => "delete"
|
||||
case Options => "options"
|
||||
case Head => "head"
|
||||
case Patch => "patch"
|
||||
case Trace => "trace"
|
||||
case Unkonw => "*"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
/*
|
||||
* Copyright (c) 杭州颉创科技有限公司 2025. All rights reserved.
|
||||
* This source file is licensed under the MIT License found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package simcu::simapi.openapi.models
|
||||
|
||||
/**
|
||||
* @brief 表示 OpenAPI 参数位置。
|
||||
*/
|
||||
public enum ParameterLocation <: ToString {
|
||||
/**
|
||||
* @brief 表示查询字符串参数。
|
||||
*/
|
||||
Query
|
||||
/**
|
||||
* @brief 表示请求头参数。
|
||||
*/
|
||||
| Header
|
||||
/**
|
||||
* @brief 表示路径参数。
|
||||
*/
|
||||
| Path
|
||||
|
||||
/**
|
||||
* @brief 返回参数位置对应的名称。
|
||||
* @return 当前参数位置对应的名称字符串。
|
||||
*/
|
||||
public func toString(): String {
|
||||
match (this) {
|
||||
case Query => "query"
|
||||
case Header => "header"
|
||||
case Path => "path"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
/*
|
||||
* Copyright (c) 杭州颉创科技有限公司 2025. All rights reserved.
|
||||
* This source file is licensed under the MIT License found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package simcu::simapi.openapi.models
|
||||
|
||||
/**
|
||||
* @brief 表示 OpenAPI 引用类型。
|
||||
*/
|
||||
public enum ReferenceType <: Equatable<ReferenceType> & ToString {
|
||||
/**
|
||||
* @brief 表示标签引用类型。
|
||||
*/
|
||||
Tag
|
||||
/**
|
||||
* @brief 表示链接引用类型。
|
||||
*/
|
||||
| Link
|
||||
/**
|
||||
* @brief 表示架构引用类型。
|
||||
*/
|
||||
| Schema
|
||||
|
||||
/**
|
||||
* @brief 比较两个引用类型是否相等。
|
||||
* @param that 要比较的引用类型。
|
||||
* @return 如果两个引用类型相等则返回 `true`。
|
||||
*/
|
||||
public operator func ==(that: ReferenceType): Bool {
|
||||
match ((this, that)) {
|
||||
case (Tag, Tag) => true
|
||||
case (Link, Link) => true
|
||||
case (Schema, Schema) => true
|
||||
case _ => false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 返回引用类型对应的名称。
|
||||
* @return 当前引用类型对应的名称字符串。
|
||||
*/
|
||||
public func toString(): String {
|
||||
match (this) {
|
||||
case Tag => "tags"
|
||||
case Link => "links"
|
||||
case Schema => "schemas"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user