Search code examples
javaopenapiopenapi-generator-maven-plugin

How to generate metadata info with openapi-generator


In my openapi.yaml file there are some information I would like to access in my code.

openapi: "3.0.0"
info:
  title: Title
  description: My description
  version: "1.0"

Now I would like to be able to access the version information contained in the api-specification. Is there a way to tell the generator to generate these metadata?

I am using the openapi-generator-maven-plugin with the spring generator.


Solution

  • Hopefully this will helpful. I'm using this plugin to get the MetaData information, this will generate configuration class

    <plugin>
                    <groupId>org.openapitools</groupId>
                    <artifactId>openapi-generator-maven-plugin</artifactId>
                    <version>7.6.0</version>
                    <executions>
                        <execution>
                            <id>openapi-generator</id>
                            <phase>generate-sources</phase>
                            <goals>
                                <goal>generate</goal>
                            </goals><!---->
                            <configuration>
                                <inputSpec>
                                    ${project.basedir}/src/main/resources/petstore.yml
                                </inputSpec>
                                <library>spring-boot</library>
                                <generatorName>spring</generatorName>
                                <apiPackage>com.example.openapigenerator.api</apiPackage>
                                <modelPackage>com.example.openapigenerator.model</modelPackage>
                                <configOptions>
                                    <GenerateOpenAPIMetadata>true</GenerateOpenAPIMetadata>
                                </configOptions>
    
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
    

    Basically this config helping to get this information

    <configOptions>                            
          <GenerateOpenAPIMetadata>true</GenerateOpenAPIMetadata>
    </configOptions>
    

    enter image description here