Swagger-codegen: [Java] Maven ํ”Œ๋Ÿฌ๊ทธ์ธ์—์„œ ์ƒ์„ฑ ๋œ ์ฝ”๋“œ๋ฅผ ๋นŒ๋“œ ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

์— ๋งŒ๋“  2016๋…„ 11์›” 30์ผ  ยท  7์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: swagger-api/swagger-codegen

๊ธฐ์ˆ 

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 ๋ฌธ์„œ์˜ ์˜ˆ์ œ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์ง€๋งŒ ๋นŒ๋“œ๊ฐ€ ์—ฌ์ „ํžˆ ์‹คํŒจํ•ฉ๋‹ˆ๋‹ค.

Swagger-codegen ๋ฒ„์ „

2.2.1-2.1.6์—์„œ ์ž‘๋™ํ–ˆ์Šต๋‹ˆ๋‹ค.

Swagger ์„ ์–ธ ํŒŒ์ผ ๋‚ด์šฉ ๋˜๋Š” URL

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๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋ฒ„๊ทธ๊ฐ€์žˆ๋Š” ๊ณณ์ผ๊นŒ์š”?

Question Swagger Codegen Maven Plugin

๋ชจ๋“  7 ๋Œ“๊ธ€

์•„ํ•˜-๋‹จ์„œ๋Š” # 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>

๊ทธ๊ฒƒ์€ ๋‚˜๋ฅผ ์œ„ํ•ด ํ•ด๊ฒฐ๋˜์—ˆ์Šต๋‹ˆ๋‹ค

๋งŽ์€ ๊ฐ์‚ฌ

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰