The openapi-generator-maven-plugin does not generate @ExampleObject
Asked Answered
U

1

1

I am using The openapi-generator-maven-plugin:6.4.0 to generate swagger code. I am able to access the APIs.

But, in generated files @ExampleObject is not present. Also, in Swagger UI I am unable to see the examples specified in inputSpec. Please suggest.

Below are the dependencies and plugins used in pom.xml file

Dependencies:

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-ui</artifactId>
    <version>1.6.14</version>
</dependency>
<dependency>
    <groupId>org.openapitools</groupId>
    <artifactId>jackson-databind-nullable</artifactId>
    <version>0.2.1</version>
</dependency>

Plugin:

<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>6.4.0</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>/src/main/resources/openapi.json</inputSpec>
       <apiPackage>com.example.api</apiPackage>
<modelPackage>com.example.model</modelPackage>
<skipOperationExample>false</skipOperaionExample>         <generatorName>spring</generatorName>
                <configOptions> <sourceFolder>src/gen/java/main</sourceFolder<delegatePattern>true</delegatePattern>
<interfaceOnly>true</interfaceOnly>
                </configOptions>
            </configuration>
        </execution>
    </executions>
</plugin>
Ulm answered 30/3, 2023 at 10:56 Comment(2)
The openapi-generator doesn't create @ExampleObject annotations. You can verify this by checking the mustache templates used to generate the objects. It sets the example using the @schema annotation instead. As for the examples not showing up in the ui, I can't help you without being able to see the input spec. Can you please share your input spec and your maven configuration? Thank you.Abrupt
@Abrupt I have updated the question with the detailsUlm
M
0

you can use

<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>6.6.0</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>${project.basedir}/misc/spec/SOP.yml</inputSpec>
                <generatorName>java</generatorName>
                <generateApiDocumentation>false</generateApiDocumentation>
                <generateApiTests>false</generateApiTests>
                <generateModelDocumentation>false</generateModelDocumentation>
                <generateModelTests>false</generateModelTests>
                <generateApiTests>false</generateApiTests>
                <generateSupportingFiles>false</generateSupportingFiles>
                <library>resttemplate</library>
                <modelPackage>com.abc.omsvclyr.gen.sop</modelPackage>
                <configOptions>
                    <interfaceOnly>true</interfaceOnly>
                    <useJakartaEe>true</useJakartaEe>
                    <sourceFolder>src/java/main</sourceFolder>
                    <generateApis>false</generateApis>
                    <useSpringBoot3>true</useSpringBoot3>
                </configOptions>
            </configuration>
        </execution>
    </executions>
</plugin>
Mikol answered 8/8, 2023 at 11:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.