Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenApi 3.0: a reference to the existing class

I want to use a class from a library as a type of a property. Say it is foo.lib.Foo. What is the right way to properly define it as a type of the property?

SomeDto:
  type: object
  properties:
     foo:
        $ref: `foo.lib.Foo`??? 
like image 832
Andremoniy Avatar asked Apr 28 '26 02:04

Andremoniy


1 Answers

This can be done through defining a type mapping and referring the type explicitly.

  1. Define a type mapping in the plugin configuration
    <configuration>
         ...
         <importMappings>
             <importMapping>Foo=foo.lib.Foo</importMapping>
         </importMappings>
         ...
    </configuration>
  1. Refer the type:
SomeDto:
  type: object
  properties:
     foo:
        $ref: '#/components/schema/Foo' 
  1. Include the dependency of the library in the classpath (the dependencies section).

UPDATE in case it still doesn't work, try to refer your class as follows:

SomeDto:
  type: object
  properties:
     foo:
        $ref: 'Foo' 
like image 164
Andremoniy Avatar answered Apr 30 '26 21:04

Andremoniy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!