F
F
Floor is Java2022-03-28 09:32:11
Java
Floor is Java, 2022-03-28 09:32:11

How to describe in the OpenApi specification a DTO field, which is an object that lies in another package (not in a DTO)?

Good afternoon

There is a project without an OpenApi / Swagger specification with the described Model, Dto, etc. classes in the code. I
plan to describe the specification so that DTO classes are generated from it.
I describe DTO classes with fields in Components.
When you need to describe a field that is an object and lies in the same DTO package, then I write like this:

UserDto
type: object
properties:
status:
$ref: '#/components/schemas/StatusDTO'

(and below in the same spec I have described StatusDTO)

And how to make a link (and is it possible) if one of the UserDto fields is not a DTO object, but an object from the model? For example, just "Status" and lies in another package. models.

I tried to find a solution in the OpenApi documentation, but something did not work out. Found only links to other .yaml files.
OpenApi version: 3.0.1

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2022-03-28
@Maksclub

When you need to describe a field, <...>, then I write like this:

If you describe with your hands, then describe your model with your hands (your status), and specify it through $ ref
schemas:
     UserDto:
          type: object
          properties:
          status:
          $ref: '#/components/schemas/StatusModel'

     StatusModel: ~

For a yaml file, the name of the objects and their hierarchy / layers in the code are not important - it works within its standard and its hierarchy

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question