Openapi 模式不正确
Openapi schema incorrect
我做了一个 openapi 规范,我们用它来生成代码 BE 和 FE。它工作正常但给我一个关于我的架构类型的警告。它默认为 'object' 这就是它起作用的原因,但这不是一个好的解决方案。
请查看代码并帮我看看我在这里缺少的东西(很明显)。谢谢。
错误:
[main] INFO o.o.c.l.TypeScriptAngularClientCodegen - generating code for Angular 11.0.0 ...
[main] INFO o.o.c.l.TypeScriptAngularClientCodegen - (you can select the angular version by setting the additionalProperty ngVersion)
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] INFO o.o.codegen.TemplateManager - writing file /home/chai/Nextcloud/Documents/nerdspul/werkspul/dev-division/mosar/src/frontend/mosar-frontend/./build/openapi/model/./flashcard.ts
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] WARN o.o.codegen.utils.ModelUtils - #components/schemas/Flashcard is not defined
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] WARN o.o.codegen.utils.ModelUtils - #components/schemas/Flashcard is not defined
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] WARN o.o.codegen.DefaultCodegen - Error obtaining the datatype from ref:#components/schemas/Flashcard. Default to 'object'
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] WARN o.o.codegen.utils.ModelUtils - #components/schemas/Flashcard is not defined
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] WARN o.o.codegen.DefaultCodegen - Error obtaining the datatype from ref:#components/schemas/Flashcard. Default to 'object'
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] WARN o.o.codegen.utils.ModelUtils - #components/schemas/Flashcard is not defined
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] WARN o.o.codegen.DefaultCodegen - Error obtaining the datatype from ref:#components/schemas/Flashcard. Default to 'object'
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] WARN o.o.codegen.utils.ModelUtils - #components/schemas/Flashcard is not defined
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] WARN o.o.codegen.DefaultCodegen - Error obtaining the datatype from ref:#components/schemas/Flashcard. Default to 'object'
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
代码:
openapi: '3.0.0'
servers:
# - url: http://localhost:8080/api
# mockapi.io
- url: https://6071a9e850aaea0017284e9d.mockapi.io/api
info:
version: 1.0.0
title: Flashcard API
paths:
/flashcard/{id}:
get:
tags:
- FlashcardApi
description: Returns a single flashcard by id.
operationId: getFlashcard
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
200:
$ref: '#/components/schemas/Flashcard'
404:
description: Flashcard does not exist.
500:
description: A server error occurred.
/flashcard:
post:
tags:
- FlashcardApi
description: Saves a single flashcard in the db.
operationId: createFlashcard
requestBody:
description: Json object to create a flashcard
required: true
content:
application/json:
schema:
$ref: '#components/schemas/Flashcard'
responses:
200:
description: A flashcard.
content:
application/json:
schema:
$ref: '#/components/schemas/Flashcard'
404:
description: Flashcard does not exist.
500:
description: A server error occurred.
components:
schemas:
Flashcard:
type: object
properties:
term:
type: string
explanation:
type: string
id:
type: string
createDate:
type: string
changeDate:
type: string
createdBy:
type: string
changedBy:
type: string
required:
- term
- explanation
变化:$ref: '#components/schemas/Flashcard'
至:$ref: '#/components/schemas/Flashcard'
(您错过了 /)
也将此添加到第一个 get (/flashcard/{id}:
)
return 正确的类型:
responses:
200:
description: flash card
content:
application/json:
schema:
$ref: '#/components/schemas/Flashcard'
我做了一个 openapi 规范,我们用它来生成代码 BE 和 FE。它工作正常但给我一个关于我的架构类型的警告。它默认为 'object' 这就是它起作用的原因,但这不是一个好的解决方案。
请查看代码并帮我看看我在这里缺少的东西(很明显)。谢谢。 错误:
[main] INFO o.o.c.l.TypeScriptAngularClientCodegen - generating code for Angular 11.0.0 ...
[main] INFO o.o.c.l.TypeScriptAngularClientCodegen - (you can select the angular version by setting the additionalProperty ngVersion)
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] INFO o.o.codegen.TemplateManager - writing file /home/chai/Nextcloud/Documents/nerdspul/werkspul/dev-division/mosar/src/frontend/mosar-frontend/./build/openapi/model/./flashcard.ts
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] WARN o.o.codegen.utils.ModelUtils - #components/schemas/Flashcard is not defined
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] WARN o.o.codegen.utils.ModelUtils - #components/schemas/Flashcard is not defined
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] WARN o.o.codegen.DefaultCodegen - Error obtaining the datatype from ref:#components/schemas/Flashcard. Default to 'object'
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] WARN o.o.codegen.utils.ModelUtils - #components/schemas/Flashcard is not defined
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] WARN o.o.codegen.DefaultCodegen - Error obtaining the datatype from ref:#components/schemas/Flashcard. Default to 'object'
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] WARN o.o.codegen.utils.ModelUtils - #components/schemas/Flashcard is not defined
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] WARN o.o.codegen.DefaultCodegen - Error obtaining the datatype from ref:#components/schemas/Flashcard. Default to 'object'
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] WARN o.o.codegen.utils.ModelUtils - #components/schemas/Flashcard is not defined
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
[main] WARN o.o.codegen.DefaultCodegen - Error obtaining the datatype from ref:#components/schemas/Flashcard. Default to 'object'
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: #components/schemas/Flashcard
代码:
openapi: '3.0.0'
servers:
# - url: http://localhost:8080/api
# mockapi.io
- url: https://6071a9e850aaea0017284e9d.mockapi.io/api
info:
version: 1.0.0
title: Flashcard API
paths:
/flashcard/{id}:
get:
tags:
- FlashcardApi
description: Returns a single flashcard by id.
operationId: getFlashcard
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
200:
$ref: '#/components/schemas/Flashcard'
404:
description: Flashcard does not exist.
500:
description: A server error occurred.
/flashcard:
post:
tags:
- FlashcardApi
description: Saves a single flashcard in the db.
operationId: createFlashcard
requestBody:
description: Json object to create a flashcard
required: true
content:
application/json:
schema:
$ref: '#components/schemas/Flashcard'
responses:
200:
description: A flashcard.
content:
application/json:
schema:
$ref: '#/components/schemas/Flashcard'
404:
description: Flashcard does not exist.
500:
description: A server error occurred.
components:
schemas:
Flashcard:
type: object
properties:
term:
type: string
explanation:
type: string
id:
type: string
createDate:
type: string
changeDate:
type: string
createdBy:
type: string
changedBy:
type: string
required:
- term
- explanation
变化:$ref: '#components/schemas/Flashcard'
至:$ref: '#/components/schemas/Flashcard'
(您错过了 /)
也将此添加到第一个 get (/flashcard/{id}:
)
return 正确的类型:
responses:
200:
description: flash card
content:
application/json:
schema:
$ref: '#/components/schemas/Flashcard'