Repository navigation
feat: add spring-boot4 petstore sample, tests and CI workflow #12791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Daniel Kmiecik (daniel-kmiecik)
wants to merge
4
commits into
3.0.0
Choose a base branch
from
handle-spring-boot-4-workflow
base: 3.0.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0061dfe
feat: add spring-boot4 petstore sample, tests and CI workflow
daniel-kmiecik ebfbd0c
Merge branch '3.0.0' into handle-spring-boot-4-workflow
daniel-kmiecik ec98ee6
ci: bump GitHub Actions versions in springboot4 workflow
daniel-kmiecik 3c888df
fix: comments after review
daniel-kmiecik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| name: Test Framework V3 Springboot4 (Spring Boot 4 / Jackson 3) | ||
|
|
||
| on: | ||
| # execute on demand | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
|
|
||
| # builds codegen cli and uploads its artifact | ||
| build-codegen: | ||
|
|
||
| runs-on: ubuntu-latest | ||
|
|
||
| strategy: | ||
| matrix: | ||
| java: [ 11 ] | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v7 | ||
| with: | ||
| ref: 3.0.0 | ||
| - uses: actions/setup-java@v6 | ||
| with: | ||
| distribution: temurin | ||
| java-version: ${{ matrix.java }} | ||
| - name: build codegen | ||
| run: | | ||
| mkdir codegen-cli | ||
| echo "BUILDING 3.0.0" | ||
| mvn -version | ||
| mvn -q -B package -DskipTests -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 -Dmaven.wagon.http.retryHandler.count=3 | ||
| cp modules/swagger-codegen-cli/target/swagger-codegen-cli.jar codegen-cli | ||
| - name: upload codegen cli | ||
| uses: actions/upload-artifact@v7 | ||
| with: | ||
| name: codegen-cli | ||
| path: codegen-cli | ||
| - name: upload test files | ||
| uses: actions/upload-artifact@v7 | ||
| with: | ||
| name: spring-custom-test-files | ||
| path: samples/custom-tests/spring/v3/springboot4 | ||
|
|
||
| generate: | ||
|
|
||
| needs: build-codegen | ||
|
|
||
| runs-on: ubuntu-latest | ||
|
|
||
| strategy: | ||
| matrix: | ||
| java: [ 21 ] | ||
|
|
||
|
|
||
| outputs: | ||
| generate_outcome: ${{ steps.outcome.outputs.generate_outcome }} | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v7 | ||
| with: | ||
| ref: 3.0.0 | ||
| - uses: actions/setup-java@v6 | ||
| with: | ||
| distribution: temurin | ||
| java-version: ${{ matrix.java }} | ||
| - name: Download codegen cli | ||
| uses: actions/download-artifact@v8 | ||
| with: | ||
| name: codegen-cli | ||
| - name: generate | ||
| id: generate | ||
| continue-on-error: true | ||
| uses: ./.github/actions/generate | ||
| with: | ||
| language: spring | ||
| job-name: ${{ env.JOB_NAME }} | ||
| spec-url: https://raw.githubusercontent.com/swagger-api/swagger-codegen/3.0.0/modules/swagger-codegen/src/test/resources/3_0_0/petstore-with-issue-cases.yaml | ||
| options: "--library spring-boot4" | ||
| - id: outcome | ||
| run: | | ||
| echo "generate_outcome=${{ steps.generate.outcome }}" >> $GITHUB_OUTPUT | ||
| echo ${{ steps.generate.outcome }} > generate_outcome_${{ env.JOB_NAME }} | ||
| - name: upload generate outcome | ||
| uses: actions/upload-artifact@v7 | ||
| with: | ||
| name: ${{ env.JOB_NAME }}generate_outcome | ||
| path: generate_outcome_${{ env.JOB_NAME }} | ||
| - name: upload generate logs | ||
| uses: actions/upload-artifact@v7 | ||
| with: | ||
| name: ${{ env.JOB_NAME }}generate_logs | ||
| path: ${{ steps.generate.outputs.logs }} | ||
| - name: upload generated code | ||
| if: contains(steps.generate.outcome, 'success') | ||
| uses: actions/upload-artifact@v7 | ||
| with: | ||
| name: ${{ env.JOB_NAME }}generated | ||
| path: ${{ steps.generate.outputs.path }} | ||
| env: | ||
| JOB_NAME: "springboot4-v3-sample" | ||
|
|
||
| build: | ||
|
|
||
| needs: generate | ||
| if: contains(needs.generate.outputs.generate_outcome, 'success') | ||
| runs-on: ubuntu-latest | ||
|
|
||
| strategy: | ||
| ############################################### | ||
| ##### DYNAMIC: Dependent on build environment | ||
| ############################################### | ||
| matrix: | ||
| java-version: [17, 21] | ||
| ############################################### | ||
| ##### END DYNAMIC: Dependent on build environment | ||
| ############################################### | ||
| steps: | ||
| - uses: actions/checkout@v7 | ||
| with: | ||
| ref: 3.0.0 | ||
| - name: Download artifacts | ||
| uses: actions/download-artifact@v8 | ||
| with: | ||
| name: ${{ env.JOB_NAME }}generated | ||
| path: generated/${{ env.JOB_NAME }} | ||
| - name: Download logs | ||
| uses: actions/download-artifact@v8 | ||
| with: | ||
| name: ${{ env.JOB_NAME }}generate_logs | ||
| ############################################### | ||
| ##### DYNAMIC: Dependent on build environment | ||
| ############################################### | ||
| - name: Set up JDK ${{ matrix.java-version }} | ||
| uses: actions/setup-java@v6 | ||
| with: | ||
| distribution: temurin | ||
| java-version: ${{ matrix.java-version }} | ||
| ############################################### | ||
| ##### END DYNAMIC: Dependent on build environment | ||
| ############################################### | ||
| - name: Download Java Test Files | ||
| uses: actions/download-artifact@v8 | ||
| with: | ||
| name: spring-custom-test-files | ||
| path: spring-custom-test-files | ||
| - name: setup test files | ||
| id: test-files | ||
| run: | | ||
| echo "adding test directories path" | ||
|
|
||
| mkdir -p generated/${{ env.JOB_NAME }}/src/test/java/io/swagger/api | ||
|
|
||
| echo "copying custom test files" | ||
| cp spring-custom-test-files/PetApiTest.java generated/${{ env.JOB_NAME }}/src/test/java/io/swagger/api/ | ||
| cp spring-custom-test-files/StoreApiTest.java generated/${{ env.JOB_NAME }}/src/test/java/io/swagger/api/ | ||
| cp spring-custom-test-files/UserApiTest.java generated/${{ env.JOB_NAME }}/src/test/java/io/swagger/api/ | ||
|
|
||
| - name: build | ||
| id: build | ||
| uses: ./.github/actions/build | ||
| continue-on-error: true | ||
| with: | ||
| path: generated/${{ env.JOB_NAME }} | ||
| job-name: ${{ env.JOB_NAME }} | ||
| build-commands: "mvn clean package -Dmaven.compiler.release=${{ matrix.java-version }} -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 -Dmaven.wagon.http.retryHandler.count=3" | ||
| - id: outcome | ||
| run: | | ||
| echo "build_outcome=${{ steps.build.outcome }}" >> $GITHUB_OUTPUT | ||
| echo ${{ steps.build.outcome }} > ${{ env.JOB_NAME }}build_outcome | ||
| - name: upload build outcome | ||
| uses: actions/upload-artifact@v7 | ||
| with: | ||
| name: ${{ env.JOB_NAME }}build_outcome-java${{ matrix.java-version }} | ||
| path: ${{ env.JOB_NAME }}build_outcome | ||
| - name: upload logs | ||
| uses: actions/upload-artifact@v7 | ||
| with: | ||
| name: ${{ env.JOB_NAME }}logs-java${{ matrix.java-version }} | ||
| path: ${{ steps.build.outputs.logs }} | ||
| env: | ||
| JOB_NAME: "springboot4-v3-sample" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #!/bin/sh | ||
|
|
||
| SCRIPT="$0" | ||
|
|
||
| while [ -h "$SCRIPT" ] ; do | ||
| ls=`ls -ld "$SCRIPT"` | ||
| link=`expr "$ls" : '.*-> \(.*\)$'` | ||
| if expr "$link" : '/.*' > /dev/null; then | ||
| SCRIPT="$link" | ||
| else | ||
| SCRIPT=`dirname "$SCRIPT"`/"$link" | ||
| fi | ||
| done | ||
|
|
||
| if [ ! -d "${APP_DIR}" ]; then | ||
| APP_DIR=`dirname "$SCRIPT"`/.. | ||
| APP_DIR=`cd "${APP_DIR}"; pwd` | ||
| fi | ||
|
|
||
| executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar" | ||
|
|
||
| if [ ! -f "$executable" ] | ||
| then | ||
| mvn clean package | ||
| fi | ||
|
|
||
| output="samples/server/petstore/springboot-4" | ||
| # if you've executed sbt assembly previously it will use that instead. | ||
| export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -Dlogback.configurationFile=bin/logback.xml" | ||
| ags="$@ generate -i modules/swagger-codegen/src/test/resources/3_0_0/petstore.yaml -l spring --library spring-boot4 -o $output -DhideGenerationTimestamp=true" | ||
|
|
||
| echo "Removing files and folders under samples/server/petstore/springboot-4/src/main" | ||
| rm -rf samples/server/petstore/springboot-4/src/main | ||
| rm -rf samples/server/petstore/springboot-4/src/gen | ||
| find samples/server/petstore/springboot-4 -maxdepth 1 -type f ! -name "README.md" -exec rm {} + | ||
| java $JAVA_OPTS -jar $executable $ags | ||
|
|
||
| #cd $output | ||
| #mvn package |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
samples/custom-tests/spring/v3/springboot4/PetApiTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| package io.swagger.api; | ||
|
|
||
| import io.swagger.model.ModelApiResponse; | ||
| import io.swagger.model.Pet; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| @SpringBootTest | ||
| public class PetApiTest { | ||
|
|
||
| @Autowired | ||
| private PetApi api; | ||
|
|
||
| @Test | ||
| public void addPetTest() throws Exception { | ||
| Pet body = new Pet() | ||
| .id(789L) | ||
| .name("doggie") | ||
| .status(Pet.StatusEnum.AVAILABLE); | ||
| ResponseEntity<Pet> responseEntity = api.addPet(body); | ||
| assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode()); | ||
| } | ||
|
|
||
| @Test | ||
| public void deletePetTest() throws Exception { | ||
| Long petId = 789L; | ||
| String apiKey = "apiKey_example"; | ||
| ResponseEntity<Void> responseEntity = api.deletePet(petId, apiKey); | ||
| assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode()); | ||
| } | ||
|
|
||
| @Test | ||
| public void findPetsByStatusTest() throws Exception { | ||
| String status = "available"; | ||
| ResponseEntity<List<Pet>> responseEntity = api.findPetsByStatus(status); | ||
| assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode()); | ||
| } | ||
|
|
||
| @Test | ||
| public void findPetsByTagsTest() throws Exception { | ||
| List<String> tags = Arrays.asList("tags_example"); | ||
| ResponseEntity<List<Pet>> responseEntity = api.findPetsByTags(tags); | ||
| assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode()); | ||
| } | ||
|
|
||
| @Test | ||
| public void getPetByIdTest() throws Exception { | ||
| Long petId = 789L; | ||
| ResponseEntity<Pet> responseEntity = api.getPetById(petId); | ||
| assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode()); | ||
| } | ||
|
|
||
| @Test | ||
| public void updatePetTest() throws Exception { | ||
| Pet body = new Pet() | ||
| .id(789L) | ||
| .name("doggie") | ||
| .status(Pet.StatusEnum.AVAILABLE); | ||
| ResponseEntity<Pet> responseEntity = api.updatePet(body); | ||
| assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode()); | ||
| } | ||
|
|
||
| @Test | ||
| public void uploadFileTest() throws Exception { | ||
| Long petId = 789L; | ||
| String additionalMetadata = "additionalMetadata_example"; | ||
| org.springframework.web.multipart.MultipartFile body = null; | ||
| ResponseEntity<ModelApiResponse> responseEntity = api.uploadFile(petId, additionalMetadata, body); | ||
| assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode()); | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.