Java ์ฝ๋๋ฅผ ์์ฑํ๊ธฐ ์ํด Maven ํ๋ฌ๊ทธ์ธ์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค. ์์ฑ ํ ๋ค์๊ณผ ๊ฐ์ ์์ฑ ๋ ์ฝ๋๋ฅผ ์ปดํ์ผํ๋ ๋์ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
package com.google.gson.annotations does not exist
package okio does not exist
_Jersey ํด๋ผ์ด์ธํธ 1.18์ ๊ธฐ๋ํ๊ธฐ ๋๋ฌธ์ ๋๋์ต๋๋ค. JSON ์ฒ๋ฆฌ : Jackson 2.4.2_๋ readme์ ์ค๋ช ๋๋๋ก ์ฌ์ฉ๋ฉ๋๋ค. GSON ๋๋ OKIO๊ฐ ํ์ํ ์ด์ ๋ ๋ฌด์์ ๋๊น? ๊ทธ๋ ๊ฒํ๋ฉด์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด ์ถ๊ฐํด์ผ ํ ์ข ์์ฑ์ ์ฐพ์ ์ ์์ต๋๋ค. swagger-maven-plugin ๋ฌธ์์ ์์ ๋ฅผ ์ฌ์ฉํ๊ณ ์์ง๋ง ๋น๋๊ฐ ์ฌ์ ํ ์คํจํฉ๋๋ค.
2.2.1-2.1.6์์ ์๋ํ์ต๋๋ค.
https://github.com/amadeus-travel-innovation-sandbox/sandbox-content/blob/master/swagger.yml
Codegen ๊ตฌ์ฑ
<configuration>
<inputSpec>https://raw.githubusercontent.com/amadeus-travel-innovation-sandbox/sandbox-content/master/swagger.yml</inputSpec>
<language>java</language>
<configOptions>
<dateLibrary>joda</dateLibrary>
</configOptions>
<output>${project.build.directory}/generated-sources/swagger</output>
</configuration>
์ข ์์ฑ ๋ฐ ์์ฑ
<dependencies>
<!-- dependencies are needed for the client being generated -->
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${swagger-annotations-version}</version>
</dependency>
<!-- HTTP client: jersey-client -->
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey-version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>${jersey-version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.22.1</version>
</dependency>
<!-- JSON processing: jackson -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>2.1.5</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${jodatime-version}</version>
</dependency>
<!-- Base64 encoding that works in both JVM and Android -->
<dependency>
<groupId>com.brsanthu</groupId>
<artifactId>migbase64</artifactId>
<version>2.2</version>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<swagger-annotations-version>1.5.0</swagger-annotations-version>
<jersey-version>2.12</jersey-version>
<jackson-version>2.4.2</jackson-version>
<jodatime-version>2.3</jodatime-version>
<maven-plugin-version>1.0.0</maven-plugin-version>
<junit-version>4.8.1</junit-version>
</properties>
https://github.com/tadhgpearson/swagger-maven-plugin-dependencies ๋ณต์ ๋ฐ ๋น๋
Java 8 ๋ฐ Maven 3.3์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
์๋ง๋ # 3261?
๋์์ ๋ฐ๋ฅด๋ฉด ๊ธฐ๋ณธ๊ฐ์ ์ด์ GSON + OK HTTP๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ ๋๋ค. ๋ฒ๊ทธ๊ฐ์๋ ๊ณณ์ผ๊น์?
์ํ-๋จ์๋ # 3919์์ ์
๋ฐ์ดํธ ๋ JavaClientCodegen:56
์ ์์ต๋๋ค.
CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
libraryOption.setEnum(supportedLibraries);
// set okhttp-gson as the default
libraryOption.setDefault("okhttp-gson");
cliOptions.add(libraryOption);
setLibrary("okhttp-gson");
์ด๊ฒ์ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์ ์งํ๋ ค๋ฉด (Jackson / Jersey๋ฅผ ์ ํธํ์ง๋ง ๋ด ์๊ฒฌ ์ผ๋ฟ์
๋๋ค) maven codegen ์์ ๋ฅผ ์
๋ฐ์ดํธํด์ผํ๋ฉฐ ๋ฌธ์๋ ์ด์ ์ ์ฌ์ฉํ๋ ๊ฒ์ ํธ์ถ ํ ์์๋ ๋ฐฉ๋ฒ์ ์๋ ค์ค๋๋ค. ๊ธฐ๋ณธ ์ต์
( jersey1
์
๋๊น?)
ํ์ธ-์ฝ๋๋ฅผ ํตํด์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ณ ๋ฌธ์๋ฅผ ์ ๋ฐ์ดํธํ๊ธฐ ์ํด ์์ pull ์์ฒญ์ ์ ๊ณตํ์ต๋๋ค. ๋์์ด ๋์๊ธฐ๋ฅผ ๋ฐ๋๋๋ค.
2.2.1์์ ์๋ํ๋ ์๋ก์ด "templateDirectory"๊ธฐ๋ฅ์ด ํ์ํ๊ธฐ ๋๋ฌธ์ ์ต๊ทผ์ 2.1.6์์ 2.2.1๋ก ์ ๋ฐ์ดํธํ์ต๋๋ค. ๊ทธ๋ฌ๋ ๋ด๊ฐ ๊ทธ๋ ๊ฒํ์๋ง์ ๋์ผํ ์ปดํ์ผ๋ฌ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค. ์ด ๋ฌธ์ ๋ฅผ ์ด๋ป๊ฒ ํด๊ฒฐ ํ์ต๋๊น? ๋์!
์ฌ์ ํ jersy๋ฅผ ์ฌ์ฉํ๊ณ ์๋ก์ด ๊ธฐ๋ณธ GSON ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๋ฌด์ํ๋ ๋ฐฉ๋ฒ์ด ์์ต๋๊น?
@aparnarus : readme์ ์ค๋ช
๋๋๋ก jersey1
์ค์์น๋ฅผ ์ฌ์ฉํฉ๋๋ค.
๊ฐ์ฌํฉ๋๋ค! ๋ด๊ฐ ์ด๋ป๊ฒ ๋์ณค๋ ์ง ๋ชจ๋ฅด๊ฒ ์ง๋ง ๊ทธ๋๋ ํจ๊ณผ๊ฐ ์์ต๋๋ค.
@aparnarus : readme์ ์ค๋ช ๋๋๋ก
jersey1
์ค์์น๋ฅผ ์ฌ์ฉํฉ๋๋ค.
<build>
<plugins>
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>/src/main/resources/swagger.json</inputSpec>
<language>java</language>
<output></output>
<apiPackage>it.eng.sil.scoop</apiPackage>
<modelPackage>it.eng.sil.ws.scoop.client.model</modelPackage>
<generateModels>true</generateModels>
<generateApis>false</generateApis>
<generateApiTests>false</generateApiTests>
<generateApiDocumentation>false</generateApiDocumentation>
<generateSupportingFiles>false</generateSupportingFiles>
<generateModelDocumentation>false</generateModelDocumentation>
**<library>jersey1</library>**
<configOptions>
<dateLibrary>java8</dateLibrary>
<sourceFolder>src/main/java</sourceFolder>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
๊ทธ๊ฒ์ ๋๋ฅผ ์ํด ํด๊ฒฐ๋์์ต๋๋ค
๋ง์ ๊ฐ์ฌ