Sta*_*son 11 swagger openapi openapi-generator
是否可以使用 OpenAPI 来描述 HATEOAS REST API?
当我以HAL格式描述 API 时,我需要为其定义三种模式(一种用于请求有效负载,一种用于收集资源,一种用于项目资源)。例如:
components:
schemas:
Link:
type: object
properties:
href:
type: string
hreflang:
type: string
title:
type: string
type:
type: string
deprecation:
type: string
profile:
type: string
name:
type: string
templated:
type: boolean
Links:
type: object
discriminator:
propertyName: _links
properties:
_links:
type: object
additionalProperties:
type: string
$ref: "#/components/schemas/Link"
CollectionModel:
type: object
discriminator:
propertyName: _embedded
properties:
_embedded:
type: object
_links:
type: object
properties:
self:
type: string
profile:
type: string
search:
type: string
CollectionModel_Foo:
type: object
allOf:
- $ref: "#/components/schemas/CollectionModel"
properties:
_embedded:
type: object
properties:
projects:
type: array
items:
$ref: "#/components/schemas/EntityModel_Foo"
EntityModel_Foo:
type: object
allOf:
- $ref: "#/components/schemas/Foo"
- $ref: "#/components/schemas/Links"
Foo:
type: object
properties:
id:
type: string
format: uuid
readOnly: true
bar:
type: string
Run Code Online (Sandbox Code Playgroud)
我认为这不是很有用,因为这使规范变得复杂,并且当使用OpenAPI Generator基于该模式生成客户端时,客户端不会关注 HATEOAS,而只是请求资源。所以在这种情况下它是没有用的。
我考虑过实现JSON:API,但遗憾的是,完整的 JSON 模式仅在当前的 OpenAPI 3.1 草案中受支持。
总而言之,我找不到将 OpenAPI 集成到 HATEOAS API 中的正确方法。
| 归档时间: |
|
| 查看次数: |
2398 次 |
| 最近记录: |