I made a openapi spec and we use it to generate code BE and FE. It works fine but gives me a warning about the type of my schema. It defaults then to 'object' which is why it works, but that is not a good solution.
Please have a look at the code and help me see something (obvious) that I am missing here. Thx. The error:
[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
And the code:
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
Change: $ref: '#components/schemas/Flashcard'
to: $ref: '#/components/schemas/Flashcard'
(you missed the /)
Also add this into the first get (/flashcard/{id}:
)
to return the correct type:
responses:
200:
description: flash card
content:
application/json:
schema:
$ref: '#/components/schemas/Flashcard'