# how to generate java classes using swagger and yaml ?

1.56K views
1

how to generate java classes using swagger and YAML? how swagger internally works to generate java class?

1

Swagger.yaml file can not generate code on it’s own. You can use  belowmaven plugin if you are using maven . And you have to run .  If you are using some other build tool, you have to look for alternative plugins

swagger-codegen-maven-plugin

Your pom.xml would look something like this

<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>generate-api</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>src/main/resources/contract/api.yaml</inputSpec>
<apiPackage>com.dk.api</apiPackage>
<modelPackage>com.dk.model</modelPackage>
<language>spring</language>
<configOptions>
<output>target/generated-sources/</output>
<useBeanValidation>true</useBeanValidation>
<serializableModel>true</serializableModel>
<recursiveBeanValidation>true</recursiveBeanValidation>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>