├── .github
└── workflows
│ ├── codeql-analysis.yml
│ ├── dependency-review.yml
│ ├── deploy-docker.yml
│ ├── dockerhub-release.yaml
│ ├── maven-pulls.yml
│ ├── maven.yml
│ ├── prepare-release.yml
│ └── release.yml
├── .gitignore
├── .whitesource
├── CI
├── docker-release.sh
├── ghApiClient.py
├── lastRelease.py
├── post-release.sh
├── pre-release.sh
├── prepare-release.sh
├── publishRelease.py
├── releaseNotes.py
└── version.sh
├── Dockerfile
├── Dockerfile-telemetry
├── LICENSE
├── README.md
├── inflector.yaml
├── pom.xml
└── src
├── gen
└── java
│ └── io
│ └── swagger
│ ├── controllers
│ └── StringUtil.java
│ └── handler
│ └── StringUtil.java
├── main
├── java
│ └── io
│ │ └── swagger
│ │ └── petstore
│ │ ├── controller
│ │ ├── OrderController.java
│ │ ├── PetController.java
│ │ └── UserController.java
│ │ ├── data
│ │ ├── OrderData.java
│ │ ├── PetData.java
│ │ └── UserData.java
│ │ ├── exception
│ │ ├── ApiException.java
│ │ └── NotFoundException.java
│ │ ├── model
│ │ ├── ApiResponse.java
│ │ ├── Category.java
│ │ ├── Order.java
│ │ ├── Pet.java
│ │ ├── Tag.java
│ │ └── User.java
│ │ ├── notification
│ │ ├── BugSnagNotifier.java
│ │ ├── Notifier.java
│ │ └── NullNotifier.java
│ │ └── utils
│ │ ├── HandleAuthUrlProcessor.java
│ │ └── Util.java
├── resources
│ └── openapi.yaml
└── webapp
│ ├── WEB-INF
│ └── web.xml
│ └── index.html
└── test
└── java
└── ip
└── swagger
└── petstore
└── PetStoreTest.java
/.github/workflows/codeql-analysis.yml:
--------------------------------------------------------------------------------
1 | name: "Code scanning - action"
2 |
3 | on:
4 | push:
5 | branches: ["master"]
6 | pull_request:
7 | # The branches below must be a subset of the branches above
8 | branches: ["master"]
9 | schedule:
10 | - cron: '0 19 * * 1'
11 |
12 | jobs:
13 | CodeQL-Build:
14 |
15 | runs-on: ubuntu-latest
16 |
17 | steps:
18 | - name: Checkout repository
19 | uses: actions/checkout@v4
20 | with:
21 | # We must fetch at least the immediate parents so that if this is
22 | # a pull request then we can checkout the head.
23 | fetch-depth: 2
24 |
25 | # If this run was triggered by a pull request event, then checkout
26 | # the head of the pull request instead of the merge commit.
27 | - run: git checkout HEAD^2
28 | if: ${{ github.event_name == 'pull_request' }}
29 |
30 | # Initializes the CodeQL tools for scanning.
31 | - name: Initialize CodeQL
32 | uses: github/codeql-action/init@v3
33 | # Override language selection by uncommenting this and choosing your languages
34 | with:
35 | languages: java
36 |
37 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
38 | # If this step fails, then you should remove it and run the build manually (see below)
39 | - name: Autobuild
40 | uses: github/codeql-action/autobuild@v3
41 |
42 | # ℹ️ Command-line programs to run using the OS shell.
43 | # 📚 https://git.io/JvXDl
44 |
45 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
46 | # and modify them (or add more) to build your code if your project
47 | # uses a compiled language
48 |
49 | #- run: |
50 | # make bootstrap
51 | # make release
52 |
53 | - name: Perform CodeQL Analysis
54 | uses: github/codeql-action/analyze@v3
55 |
--------------------------------------------------------------------------------
/.github/workflows/dependency-review.yml:
--------------------------------------------------------------------------------
1 | name: 'Dependency Review'
2 | on: [pull_request]
3 |
4 | permissions:
5 | contents: read
6 |
7 | jobs:
8 | dependency-review:
9 | runs-on: ubuntu-latest
10 | steps:
11 | - name: 'Checkout Repository'
12 | uses: actions/checkout@v4
13 | - name: Dependency Review
14 | uses: actions/dependency-review-action@v3
15 | with:
16 | fail-on-severity: high
17 |
--------------------------------------------------------------------------------
/.github/workflows/deploy-docker.yml:
--------------------------------------------------------------------------------
1 | name: Deploy Docker
2 |
3 | on:
4 | workflow_dispatch:
5 | branches: ["master"]
6 | inputs:
7 | tag:
8 | description: tag/version to deploy
9 | required: true
10 | jobs:
11 | deploy:
12 |
13 | runs-on: ubuntu-latest
14 |
15 | steps:
16 | - name: deploy docker
17 | run: |
18 | SC_RELEASE_TAG="${{ env.TAG }}"
19 | echo "$SC_RELEASE_TAG"
20 |
21 | TOKEN="${{ secrets.RANCHER2_BEARER_TOKEN }}"
22 | BUGSNAG_API_KEY=${{ secrets.BUGSNAG_API_KEY }}
23 | RANCHER_HOST="rancher.tools.swagger.io"
24 | CLUSTER_ID="c-n8zp2"
25 | NAMESPACE_NAME="swagger-oss"
26 | K8S_OBJECT_TYPE="daemonsets"
27 | K8S_OBJECT_NAME="swagger-petstore-3"
28 | DEPLOY_IMAGE="swaggerapi/swagger-petstore3:$SC_RELEASE_TAG-telemetry"
29 |
30 | workloadStatus=""
31 | getStatus() {
32 | echo "Getting update status..."
33 | if ! workloadStatus="$(curl -s -X GET \
34 | -H "Authorization: Bearer ${TOKEN}" \
35 | -H 'Content-Type: application/json' \
36 | "https://${RANCHER_HOST}/k8s/clusters/${CLUSTER_ID}/apis/apps/v1/namespaces/${NAMESPACE_NAME}/${K8S_OBJECT_TYPE}/${K8S_OBJECT_NAME}/status")"
37 | then
38 | echo 'ERROR - get status k8s API call failed!'
39 | echo "Exiting build"...
40 | exit 1
41 | fi
42 | }
43 |
44 | # $1 = image to deploy
45 | updateObject() {
46 | local image="${1}"
47 | echo "Updating image value..."
48 |
49 | if ! curl -s -X PATCH \
50 | -H "Authorization: Bearer ${TOKEN}" \
51 | -H 'Content-Type: application/json-patch+json' \
52 | "https://${RANCHER_HOST}/k8s/clusters/${CLUSTER_ID}/apis/apps/v1/namespaces/${NAMESPACE_NAME}/${K8S_OBJECT_TYPE}/${K8S_OBJECT_NAME}" \
53 | -d "[{\"op\": \"replace\", \"path\": \"/spec/template/spec/containers/0/image\", \"value\": \"${image}\"}, {\"op\":\"add\",\"path\":\"/spec/template/spec/containers/0/env\",\"value\":[{\"name\":\"BUGSNAG_API_KEY\",\"value\":\"${BUGSNAG_API_KEY}\"},{\"name\":\"notifierClass\",\"value\":\"io.swagger.petstore.notification.BugSnagNotifier\"}]}]"
54 | then
55 | echo 'ERROR - image update k8s API call failed!'
56 | echo "Exiting build..."
57 | exit 1
58 | fi
59 | }
60 |
61 |
62 | # Check that the TAG is valid
63 | if [[ $SC_RELEASE_TAG =~ ^[vV]?[0-9]*\.[0-9]*\.[0-9]*$ ]]; then
64 | echo ""
65 | echo "This is a Valid TAG..."
66 |
67 | # Get current image/tag in case we need to rollback
68 | getStatus
69 | ROLLBACK_IMAGE="$(echo "${workloadStatus}" | jq -r '.spec.template.spec.containers[0].image')"
70 | echo ""
71 | echo "Current image: ${ROLLBACK_IMAGE}"
72 |
73 | # Update image and validate response
74 | echo ""
75 | updateObject "${DEPLOY_IMAGE}"
76 | echo ""
77 |
78 | echo ""
79 | echo "Waiting for pods to start..."
80 | echo ""
81 | sleep 60s
82 |
83 | # Get state of the k8s object. If numberReady == desiredNumberScheduled, consider the upgrade successful. Else raise error
84 | getStatus
85 | status="$(echo "${workloadStatus}" | jq '.status')"
86 | echo ""
87 | echo "${status}"
88 | echo ""
89 |
90 | numberDesired="$(echo "${status}" | jq -r '.desiredNumberScheduled')"
91 | numberReady="$(echo "${status}" | jq -r '.numberReady')"
92 |
93 | if (( numberReady == numberDesired )); then
94 | echo "${K8S_OBJECT_NAME} has been upgraded to ${DEPLOY_IMAGE}"
95 |
96 | # If pods are not starting, rollback the upgrade and exit the build with error
97 | else
98 | echo "state = error...rolling back upgrade"
99 | updateObject "${ROLLBACK_IMAGE}"
100 | echo ""
101 |
102 | echo ""
103 | echo "Waiting for rollback pods to start..."
104 | echo ""
105 | sleep 60s
106 |
107 | getStatus
108 | status="$(echo "${workloadStatus}" | jq '.status')"
109 | echo ""
110 | echo "${status}"
111 | echo ""
112 |
113 | numberDesired="$(echo "${status}" | jq -r '.desiredNumberScheduled')"
114 | numberReady="$(echo "${status}" | jq -r '.numberReady')"
115 |
116 | if (( numberReady == numberDesired )); then
117 | echo "Rollback to ${ROLLBACK_IMAGE} completed."
118 | else
119 | echo "FATAL - rollback failed"
120 | fi
121 | echo "Exiting Build..."
122 | exit 1
123 | fi
124 |
125 | else
126 | echo "This TAG is not in a valid format..."
127 | echo "Exiting Build..."
128 | exit 0
129 | fi
130 | echo "Exiting Build..."
131 | exit 0
132 | env:
133 | ACTIONS_ALLOW_UNSECURE_COMMANDS: true
134 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
135 | TAG: ${{ github.event.inputs.tag }}
136 |
--------------------------------------------------------------------------------
/.github/workflows/dockerhub-release.yaml:
--------------------------------------------------------------------------------
1 | name: Docker Release
2 |
3 | on:
4 | workflow_dispatch:
5 | branches: ["master"]
6 | inputs:
7 | tag:
8 | description: tag/version to release
9 | required: true
10 |
11 | jobs:
12 | build:
13 |
14 | runs-on: ubuntu-latest
15 |
16 | steps:
17 | - uses: actions/checkout@v4
18 | - name: Set up Python 3.10
19 | uses: actions/setup-python@v4
20 | with:
21 | python-version: '3.10'
22 | - name: Set up Java 11
23 | uses: actions/setup-java@v4
24 | with:
25 | java-version: 11
26 | distribution: 'temurin'
27 | - name: Run pre release script
28 | id: preRelease
29 | run: |
30 | # export GPG_TTY=$(tty)
31 | export MY_POM_VERSION=`mvn -q -Dexec.executable="echo" -Dexec.args='${projects.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
32 | if [[ $MY_POM_VERSION =~ ^.*SNAPSHOT$ ]];
33 | then
34 | echo "not releasing snapshot version: " ${MY_POM_VERSION}
35 | echo "RELEASE_OK=no" >> $GITHUB_ENV
36 | else
37 | . ./CI/pre-release.sh
38 | echo "RELEASE_OK=yes" >> $GITHUB_ENV
39 | fi
40 | echo "SC_VERSION=$SC_VERSION" >> $GITHUB_ENV
41 | echo "SC_NEXT_VERSION=$SC_NEXT_VERSION" >> $GITHUB_ENV
42 | echo "SC_LAST_RELEASE=$SC_LAST_RELEASE" >> $GITHUB_ENV
43 | - name: docker login
44 | run: |
45 | docker login --username=${{ secrets.DOCKERHUB_SB_USERNAME }} --password=${{ secrets.DOCKERHUB_SB_PASSWORD }}
46 | set -e
47 | - name: Build generator image and push
48 | if: env.RELEASE_OK == 'yes'
49 | uses: docker/build-push-action@v5
50 | with:
51 | context: .
52 | push: true
53 | platforms: linux/amd64
54 | provenance: false
55 | tags: swaggerapi/petstore3:${{ env.TAG }}
56 | - name: Build generator image and push
57 | if: env.RELEASE_OK == 'yes'
58 | uses: docker/build-push-action@v5
59 | with:
60 | file: Dockerfile-telemetry
61 | context: .
62 | push: true
63 | platforms: linux/amd64
64 | provenance: false
65 | tags: swaggerapi/petstore3:${{ env.TAG }}-telemetry
66 | env:
67 | ACTIONS_ALLOW_UNSECURE_COMMANDS: true
68 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
69 | SC_VERSION:
70 | SC_NEXT_VERSION:
71 | TAG: ${{ github.event.inputs.tag }}
72 |
73 |
--------------------------------------------------------------------------------
/.github/workflows/maven-pulls.yml:
--------------------------------------------------------------------------------
1 | name: Build Test PR
2 |
3 | on:
4 | pull_request:
5 | branches: [ "master" ]
6 |
7 | jobs:
8 | build:
9 |
10 | runs-on: ubuntu-latest
11 | strategy:
12 | matrix:
13 | java: [ 11 ]
14 |
15 | steps:
16 | - uses: actions/checkout@v4
17 | - name: Set up Java
18 | uses: actions/setup-java@v4
19 | with:
20 | java-version: ${{ matrix.java }}
21 | distribution: temurin
22 | server-id: central
23 | server-username: MAVEN_USERNAME
24 | server-password: MAVEN_PASSWORD
25 | - name: Cache local Maven repository
26 | uses: actions/cache@v4
27 | with:
28 | path: ~/.m2/repository
29 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
30 | restore-keys: |
31 | ${{ runner.os }}-maven-
32 | - name: Build with Maven
33 | run: |
34 | mvn --no-transfer-progress -B install --file pom.xml
35 | env:
36 | MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
37 | MAVEN_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
--------------------------------------------------------------------------------
/.github/workflows/maven.yml:
--------------------------------------------------------------------------------
1 | name: Build Test master
2 |
3 | on:
4 | push:
5 | branches: [ "master" ]
6 |
7 | jobs:
8 | build:
9 |
10 | runs-on: ubuntu-latest
11 | strategy:
12 | matrix:
13 | java: [ 11 ]
14 |
15 | steps:
16 | - uses: actions/checkout@v4
17 | - name: Set up Java
18 | uses: actions/setup-java@v4
19 | with:
20 | java-version: ${{ matrix.java }}
21 | distribution: temurin
22 | server-id: central
23 | server-username: MAVEN_USERNAME
24 | server-password: MAVEN_PASSWORD
25 | - name: Cache local Maven repository
26 | uses: actions/cache@v4
27 | with:
28 | path: ~/.m2/repository
29 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
30 | restore-keys: |
31 | ${{ runner.os }}-maven-
32 | - name: Build with Maven
33 | run: |
34 | mvn --no-transfer-progress -B install --file pom.xml
35 | env:
36 | MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
37 | MAVEN_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
--------------------------------------------------------------------------------
/.github/workflows/prepare-release.yml:
--------------------------------------------------------------------------------
1 | name: Prepare Release
2 |
3 | on:
4 | workflow_dispatch:
5 | branches: ["master"]
6 |
7 | jobs:
8 | build:
9 |
10 | runs-on: ubuntu-latest
11 |
12 | steps:
13 | - uses: actions/checkout@v4
14 | - uses: tibdex/github-app-token@v1
15 | id: generate-token
16 | with:
17 | app_id: ${{ secrets.APP_ID }}
18 | private_key: ${{ secrets.APP_PRIVATE_KEY }}
19 | - name: Set up Python 3.10
20 | uses: actions/setup-python@v4
21 | with:
22 | python-version: '3.10'
23 | - name: Set up Java
24 | uses: actions/setup-java@v4
25 | with:
26 | java-version: 11
27 | distribution: temurin
28 | server-id: central
29 | server-username: MAVEN_USERNAME
30 | server-password: MAVEN_PASSWORD
31 | - name: Cache local Maven repository
32 | uses: actions/cache@v4
33 | with:
34 | path: ~/.m2/repository
35 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
36 | restore-keys: |
37 | ${{ runner.os }}-maven-
38 | - name: Run prepare release script
39 | id: prepare-release
40 | run: |
41 | export MY_POM_VERSION=`mvn -q -Dexec.executable="echo" -Dexec.args='${projects.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
42 | if [[ $MY_POM_VERSION =~ ^.*SNAPSHOT$ ]];
43 | then
44 | . ./CI/prepare-release.sh
45 | echo "PREPARE_RELEASE_OK=yes" >> $GITHUB_ENV
46 | else
47 | echo "not preparing release for release version: " ${MY_POM_VERSION}
48 | echo "PREPARE_RELEASE_OK=no" >> $GITHUB_ENV
49 | fi
50 | echo "SC_VERSION=$SC_VERSION" >> $GITHUB_ENV
51 | echo "SC_NEXT_VERSION=$SC_NEXT_VERSION" >> $GITHUB_ENV
52 | - name: Create Prepare Release Pull Request
53 | uses: peter-evans/create-pull-request@v4
54 | if: env.PREPARE_RELEASE_OK == 'yes'
55 | with:
56 | token: ${{ steps.generate-token.outputs.token }}
57 | commit-message: prepare release ${{ env.SC_VERSION }}
58 | title: 'prepare release ${{ env.SC_VERSION }}'
59 | branch: prepare-release-${{ env.SC_VERSION }}
60 | env:
61 | ACTIONS_ALLOW_UNSECURE_COMMANDS: true
62 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63 | SC_VERSION:
64 | SC_NEXT_VERSION:
65 | MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
66 | MAVEN_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
67 |
--------------------------------------------------------------------------------
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | name: Release
2 |
3 | on:
4 | workflow_dispatch:
5 | branches: ["master"]
6 |
7 | jobs:
8 | build:
9 |
10 | runs-on: ubuntu-latest
11 |
12 | steps:
13 | - uses: actions/checkout@v4
14 | - uses: tibdex/github-app-token@v1
15 | id: generate-token
16 | with:
17 | app_id: ${{ secrets.APP_ID }}
18 | private_key: ${{ secrets.APP_PRIVATE_KEY }}
19 | - name: Set up Python 3.10
20 | uses: actions/setup-python@v4
21 | with:
22 | python-version: '3.10'
23 | - name: Set up Java
24 | uses: actions/setup-java@v4
25 | with:
26 | java-version: 11
27 | distribution: temurin
28 | server-id: central
29 | server-username: MAVEN_USERNAME
30 | server-password: MAVEN_PASSWORD
31 | - name: Cache local Maven repository
32 | uses: actions/cache@v4
33 | with:
34 | path: ~/.m2/repository
35 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
36 | restore-keys: |
37 | ${{ runner.os }}-maven-
38 | - name: Run pre release script
39 | id: preRelease
40 | run: |
41 | # export GPG_TTY=$(tty)
42 | export MY_POM_VERSION=`mvn -q -Dexec.executable="echo" -Dexec.args='${projects.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
43 | if [[ $MY_POM_VERSION =~ ^.*SNAPSHOT$ ]];
44 | then
45 | echo "not releasing snapshot version: " ${MY_POM_VERSION}
46 | echo "RELEASE_OK=no" >> $GITHUB_ENV
47 | else
48 | . ./CI/pre-release.sh
49 | echo "RELEASE_OK=yes" >> $GITHUB_ENV
50 | fi
51 | echo "SC_VERSION=$SC_VERSION" >> $GITHUB_ENV
52 | echo "SC_NEXT_VERSION=$SC_NEXT_VERSION" >> $GITHUB_ENV
53 | echo "SC_LAST_RELEASE=$SC_LAST_RELEASE" >> $GITHUB_ENV
54 | - name: configure git user email
55 | run: |
56 | git config --global user.email "action@github.com"
57 | git config --global user.name "GitHub Action"
58 | git config --global hub.protocol https
59 | git remote set-url origin https://\${{ secrets.GITHUB_TOKEN }}:x-oauth-basic@github.com/swagger-api/swagger-petstore.git
60 | - name: docker login
61 | run: |
62 | docker login --username=${{ secrets.DOCKERHUB_SB_USERNAME }} --password=${{ secrets.DOCKERHUB_SB_PASSWORD }}
63 | set -e
64 | - name: Docker build and push
65 | id: docker_build_push
66 | if: env.RELEASE_OK == 'yes'
67 | run: |
68 | . ./CI/docker-release.sh
69 | - name: Run post release script
70 | id: postRelease
71 | if: env.RELEASE_OK == 'yes'
72 | run: |
73 | . ./CI/post-release.sh
74 | - name: Create Next Snapshot Pull Request
75 | uses: peter-evans/create-pull-request@v4
76 | if: env.RELEASE_OK == 'yes'
77 | with:
78 | token: ${{ steps.generate-token.outputs.token }}
79 | commit-message: bump snapshot ${{ env.SC_NEXT_VERSION }}-SNAPSHOT
80 | title: 'bump snapshot ${{ env.SC_NEXT_VERSION }}-SNAPSHOT'
81 | branch: bump-snap-${{ env.SC_NEXT_VERSION }}-SNAPSHOT
82 | - name: deploy docker
83 | run: |
84 | SC_RELEASE_TAG="${{ env.SC_VERSION }}"
85 | echo "$SC_RELEASE_TAG"
86 |
87 | TOKEN="${{ secrets.RANCHER2_BEARER_TOKEN }}"
88 | BUGSNAG_API_KEY=${{ secrets.BUGSNAG_API_KEY }}
89 | RANCHER_HOST="rancher.tools.swagger.io"
90 | CLUSTER_ID="c-n8zp2"
91 | NAMESPACE_NAME="swagger-oss"
92 | K8S_OBJECT_TYPE="daemonsets"
93 | K8S_OBJECT_NAME="swagger-petstore-3"
94 | DEPLOY_IMAGE="swaggerapi/petstore3:$SC_RELEASE_TAG-telemetry"
95 |
96 | workloadStatus=""
97 | getStatus() {
98 | echo "Getting update status..."
99 | if ! workloadStatus="$(curl -s -X GET \
100 | -H "Authorization: Bearer ${TOKEN}" \
101 | -H 'Content-Type: application/json' \
102 | "https://${RANCHER_HOST}/k8s/clusters/${CLUSTER_ID}/apis/apps/v1/namespaces/${NAMESPACE_NAME}/${K8S_OBJECT_TYPE}/${K8S_OBJECT_NAME}/status")"
103 | then
104 | echo 'ERROR - get status k8s API call failed!'
105 | echo "Exiting build"...
106 | exit 1
107 | fi
108 | }
109 |
110 | # $1 = image to deploy
111 | updateObject() {
112 | local image="${1}"
113 | echo "Updating image value..."
114 |
115 | if ! curl -s -X PATCH \
116 | -H "Authorization: Bearer ${TOKEN}" \
117 | -H 'Content-Type: application/json-patch+json' \
118 | "https://${RANCHER_HOST}/k8s/clusters/${CLUSTER_ID}/apis/apps/v1/namespaces/${NAMESPACE_NAME}/${K8S_OBJECT_TYPE}/${K8S_OBJECT_NAME}" \
119 | -d "[{\"op\": \"replace\", \"path\": \"/spec/template/spec/containers/0/image\", \"value\": \"${image}\"}, {\"op\":\"add\",\"path\":\"/spec/template/spec/containers/0/env\",\"value\":[{\"name\":\"BUGSNAG_API_KEY\",\"value\":\"${BUGSNAG_API_KEY}\"},{\"name\":\"notifierClass\",\"value\":\"io.swagger.petstore.notification.BugSnagNotifier\"}]}]"
120 | then
121 | echo 'ERROR - image update k8s API call failed!'
122 | echo "Exiting build..."
123 | exit 1
124 | fi
125 | }
126 |
127 |
128 | # Check that the TAG is valid
129 | if [[ $SC_RELEASE_TAG =~ ^[vV]?[0-9]*\.[0-9]*\.[0-9]*$ ]]; then
130 | echo ""
131 | echo "This is a Valid TAG..."
132 |
133 | # Get current image/tag in case we need to rollback
134 | getStatus
135 | ROLLBACK_IMAGE="$(echo "${workloadStatus}" | jq -r '.spec.template.spec.containers[0].image')"
136 | echo ""
137 | echo "Current image: ${ROLLBACK_IMAGE}"
138 |
139 | # Update image and validate response
140 | echo ""
141 | updateObject "${DEPLOY_IMAGE}"
142 | echo ""
143 |
144 | echo ""
145 | echo "Waiting for pods to start..."
146 | echo ""
147 | sleep 60s
148 |
149 | # Get state of the k8s object. If numberReady == desiredNumberScheduled, consider the upgrade successful. Else raise error
150 | getStatus
151 | status="$(echo "${workloadStatus}" | jq '.status')"
152 | echo ""
153 | echo "${status}"
154 | echo ""
155 |
156 | numberDesired="$(echo "${status}" | jq -r '.desiredNumberScheduled')"
157 | numberReady="$(echo "${status}" | jq -r '.numberReady')"
158 |
159 | if (( numberReady == numberDesired )); then
160 | echo "${K8S_OBJECT_NAME} has been upgraded to ${DEPLOY_IMAGE}"
161 |
162 | # If pods are not starting, rollback the upgrade and exit the build with error
163 | else
164 | echo "state = error...rolling back upgrade"
165 | updateObject "${ROLLBACK_IMAGE}"
166 | echo ""
167 |
168 | echo ""
169 | echo "Waiting for rollback pods to start..."
170 | echo ""
171 | sleep 60s
172 |
173 | getStatus
174 | status="$(echo "${workloadStatus}" | jq '.status')"
175 | echo ""
176 | echo "${status}"
177 | echo ""
178 |
179 | numberDesired="$(echo "${status}" | jq -r '.desiredNumberScheduled')"
180 | numberReady="$(echo "${status}" | jq -r '.numberReady')"
181 |
182 | if (( numberReady == numberDesired )); then
183 | echo "Rollback to ${ROLLBACK_IMAGE} completed."
184 | else
185 | echo "FATAL - rollback failed"
186 | fi
187 | echo "Exiting Build..."
188 | exit 1
189 | fi
190 |
191 | else
192 | echo "This TAG is not in a valid format..."
193 | echo "Exiting Build..."
194 | exit 0
195 | fi
196 | echo "Exiting Build..."
197 | exit 0
198 | env:
199 | ACTIONS_ALLOW_UNSECURE_COMMANDS: true
200 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
201 | SC_VERSION:
202 | SC_NEXT_VERSION:
203 | MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
204 | MAVEN_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | build/
2 | lib/*.jar
3 | target
4 | .idea
5 | .idea_modules
6 | .settings
7 | .project
8 | .classpath
9 | .cache
10 | atlassian-ide-plugin.xml
11 | *.iml
12 | .java-version
13 | dependency-reduced-pom.xml
14 | *.pyc
--------------------------------------------------------------------------------
/.whitesource:
--------------------------------------------------------------------------------
1 | {
2 | "settingsInheritedFrom": "swagger-api/whitesource-config@main",
3 | "scanSettings": {
4 | "baseBranches": ["master", "v2"]
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/CI/docker-release.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | CUR=$(pwd)
4 |
5 | SC_RELEASE_TAG="$SC_VERSION"
6 |
7 | echo "docker tag:"
8 | echo "$SC_RELEASE_TAG"
9 |
10 | export DOCKER_PETSTORE_IMAGE_NAME=swaggerapi/petstore3
11 | docker build --rm=false -t $DOCKER_PETSTORE_IMAGE_NAME:$SC_RELEASE_TAG .
12 | docker tag $DOCKER_PETSTORE_IMAGE_NAME:$SC_RELEASE_TAG $DOCKER_PETSTORE_IMAGE_NAME:latest
13 | docker push $DOCKER_PETSTORE_IMAGE_NAME:$SC_RELEASE_TAG
14 | docker push $DOCKER_PETSTORE_IMAGE_NAME:latest
15 | docker build --rm=false -t $DOCKER_PETSTORE_IMAGE_NAME:$SC_RELEASE_TAG-telemetry -f Dockerfile-telemetry .
16 | docker tag $DOCKER_PETSTORE_IMAGE_NAME:$SC_RELEASE_TAG-telemetry $DOCKER_PETSTORE_IMAGE_NAME:latest-telemetry
17 | docker push $DOCKER_PETSTORE_IMAGE_NAME:$SC_RELEASE_TAG-telemetry
18 | docker push $DOCKER_PETSTORE_IMAGE_NAME:latest-telemetry
19 | echo "docker images:"
20 | docker images | grep -i petstore3
21 |
--------------------------------------------------------------------------------
/CI/ghApiClient.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 |
3 | import os
4 | import time
5 | import urllib.request, urllib.error, urllib.parse
6 | import http.client
7 | import json
8 |
9 | GH_BASE_URL = "https://api.github.com/"
10 |
11 | GH_TOKEN = os.environ['GH_TOKEN']
12 | GH_AUTH = "Bearer %s" % GH_TOKEN
13 |
14 | def readUrl(name):
15 | try:
16 | request = urllib.request.Request(GH_BASE_URL + name)
17 | request.add_header("Authorization", GH_AUTH)
18 | content = urllib.request.urlopen(request).read()
19 | jcont = json.loads(content)
20 | return jcont
21 | except urllib.error.HTTPError as e:
22 | print(('HTTPError = ' + str(e.code)))
23 | raise e
24 | except urllib.error.URLError as e:
25 | print(('URLError = ' + str(e.reason)))
26 | raise e
27 | except http.client.HTTPException as e:
28 | print(('HTTPException = ' + str(e)))
29 | raise e
30 | except Exception:
31 | import traceback
32 | print(('generic exception: ' + traceback.format_exc()))
33 | raise IOError
34 |
35 | def postUrl(name, body):
36 | global GH_BASE_URL
37 | try:
38 | time.sleep(0.05)
39 | request = urllib.request.Request(GH_BASE_URL + name)
40 | request.add_header("Authorization", GH_AUTH)
41 | request.add_header("Accept", "application/vnd.github.v3+json")
42 | data = body.encode('utf-8')
43 | content = urllib.request.urlopen(request, data).read()
44 | jcont = json.loads(content)
45 | return jcont
46 | except urllib.error.HTTPError as e:
47 | print(('HTTPError = ' + str(e.code)))
48 | print((str(e)))
49 | raise e
50 | except urllib.error.URLError as e:
51 | print(('URLError = ' + str(e.reason)))
52 | raise e
53 | except http.client.HTTPException as e:
54 | print(('HTTPException = ' + str(e)))
55 | raise e
56 | except Exception:
57 | import traceback
58 | print(('generic exception: ' + traceback.format_exc()))
59 | raise IOError
60 |
--------------------------------------------------------------------------------
/CI/lastRelease.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 |
3 | import ghApiClient
4 |
5 | def getLastReleaseTag():
6 | content = ghApiClient.readUrl('repos/swagger-api/swagger-petstore/releases')
7 | for l in content:
8 | draft = l["draft"]
9 | tag = l["tag_name"]
10 | if str(draft) != 'True' and tag.startswith("swagger-petstore-v3-"):
11 | return tag
12 | print ("NO RELEASE TAG FOUND, using default swagger-petstore-v3-1.0.17")
13 | return "swagger-petstore-v3-1.0.17"
14 | # main
15 | def main():
16 | result = getLastReleaseTag()
17 | print (result)
18 |
19 | # here start main
20 | main()
21 |
--------------------------------------------------------------------------------
/CI/post-release.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | CUR=$(pwd)
4 | TMPDIR="$(dirname -- "${0}")"
5 |
6 | SC_RELEASE_TAG="swagger-petstore-v3-$SC_VERSION"
7 |
8 | #####################
9 | ### publish pre-prepared release (tag is created)
10 | #####################
11 | python $CUR/CI/publishRelease.py "$SC_RELEASE_TAG"
12 |
13 | #####################
14 | ### update the version to next snapshot in maven project with set version
15 | #####################
16 | mvn versions:set -DnewVersion="${SC_NEXT_VERSION}-SNAPSHOT"
17 | mvn versions:commit
18 |
19 | #####################
20 | ### update all other versions in files around to the next snapshot or new release, including readme and gradle ###
21 | #####################
22 |
23 | sc_find="version\: $SC_VERSION"
24 | sc_replace="version: $SC_NEXT_VERSION-SNAPSHOT"
25 | sed -i -e "s/$sc_find/$sc_replace/g" $CUR/src/main/resources/openapi.yaml
26 |
--------------------------------------------------------------------------------
/CI/pre-release.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | CUR=$(pwd)
4 |
5 | export SC_VERSION=`mvn -q -Dexec.executable="echo" -Dexec.args='${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}' --non-recursive build-helper:parse-version org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
6 | export SC_NEXT_VERSION=`mvn -q -Dexec.executable="echo" -Dexec.args='${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.nextIncrementalVersion}' --non-recursive build-helper:parse-version org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
7 | SC_QUALIFIER=`mvn -q -Dexec.executable="echo" -Dexec.args='${parsedVersion.qualifier}' --non-recursive build-helper:parse-version org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
8 | #SC_LAST_RELEASE=`mvn -q -Dexec.executable="echo" -Dexec.args='${releasedVersion.version}' --non-recursive org.codehaus.mojo:build-helper-maven-plugin:3.2.0:released-version org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
9 | SC_LAST_RELEASE=`python $CUR/CI/lastRelease.py`
10 |
11 |
12 | SC_RELEASE_TAG="$SC_VERSION"
13 |
14 |
15 | #####################
16 | ### build and test maven ###
17 | #####################
18 | mvn --no-transfer-progress -B install --file pom.xml
19 |
--------------------------------------------------------------------------------
/CI/prepare-release.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | CUR=$(pwd)
4 |
5 | export SC_VERSION=`mvn -q -Dexec.executable="echo" -Dexec.args='${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}' --non-recursive build-helper:parse-version org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
6 | export SC_NEXT_VERSION=`mvn -q -Dexec.executable="echo" -Dexec.args='${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.nextIncrementalVersion}' --non-recursive build-helper:parse-version org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
7 | SC_QUALIFIER=`mvn -q -Dexec.executable="echo" -Dexec.args='${parsedVersion.qualifier}' --non-recursive build-helper:parse-version org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
8 | #SC_LAST_RELEASE=`mvn -q -Dexec.executable="echo" -Dexec.args='${releasedVersion.version}' --non-recursive org.codehaus.mojo:build-helper-maven-plugin:3.2.0:released-version org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
9 | SC_LAST_RELEASE=`python $CUR/CI/lastRelease.py`
10 |
11 |
12 |
13 | SC_RELEASE_TITLE="Swagger Petstore OpenAPI 3.0 release $SC_VERSION"
14 | SC_RELEASE_TAG="swagger-petstore-v3-$SC_VERSION"
15 |
16 | echo "SC_VERSION: $SC_VERSION"
17 | echo "SC_NEXT_VERSION: $SC_NEXT_VERSION"
18 | echo "SC_LAST_RELEASE: $SC_LAST_RELEASE"
19 | echo "SC_RELEASE_TITLE: $SC_RELEASE_TITLE"
20 | echo "SC_RELEASE_TAG: $SC_RELEASE_TAG"
21 |
22 | #####################
23 | ### draft release Notes with next release after last release, with tag
24 | #####################
25 | python $CUR/CI/releaseNotes.py "$SC_LAST_RELEASE" "$SC_RELEASE_TITLE" "$SC_RELEASE_TAG"
26 |
27 | #####################
28 | ### update the version to release in maven project with set version
29 | #####################
30 | mvn versions:set -DnewVersion=$SC_VERSION
31 | mvn versions:commit
32 |
33 | #####################
34 | ### update version in openapi.yaml file ###
35 | #####################
36 | sc_find="version\: $SC_VERSION\-SNAPSHOT"
37 | sc_replace="version: $SC_VERSION"
38 | sed -i -e "s/$sc_find/$sc_replace/g" $CUR/src/main/resources/openapi.yaml
39 |
40 | #####################
41 | ### build and test maven ###
42 | #####################
43 | mvn --no-transfer-progress -B install --file pom.xml
44 |
45 |
--------------------------------------------------------------------------------
/CI/publishRelease.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 |
3 | import sys
4 | import ghApiClient
5 |
6 | def lastReleaseId(tag):
7 | content = ghApiClient.readUrl('repos/swagger-api/swagger-petstore/releases')
8 | for l in content:
9 | draft = l["draft"]
10 | draft_tag = l["tag_name"]
11 | if str(draft) == 'True' and tag == draft_tag:
12 | return l["id"]
13 |
14 | def publishRelease(tag):
15 | id = lastReleaseId(tag)
16 | payload = "{\"tag_name\":\"" + tag + "\", "
17 | payload += "\"draft\":" + "false" + ", "
18 | payload += "\"target_commitish\":\"" + "master" + "\"}"
19 | content = ghApiClient.postUrl('repos/swagger-api/swagger-petstore/releases/' + str(id), payload)
20 | return content
21 |
22 | # main
23 | def main(tag):
24 | publishRelease (tag)
25 |
26 | # here start main
27 | main(sys.argv[1])
28 |
--------------------------------------------------------------------------------
/CI/releaseNotes.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 |
3 | import sys
4 | import json
5 | from datetime import datetime
6 | import ghApiClient
7 |
8 | def allPulls(releaseDate):
9 |
10 | result = ""
11 |
12 | baseurl = "https://api.github.com/repos/swagger-api/swagger-petstore/pulls/"
13 | content = ghApiClient.readUrl('repos/swagger-api/swagger-petstore/pulls?state=closed&base=master&per_page=100')
14 | for l in content:
15 | stripped = l["url"][len(baseurl):]
16 | mergedAt = l["merged_at"]
17 | if mergedAt is not None:
18 | if datetime.strptime(mergedAt, '%Y-%m-%dT%H:%M:%SZ') > releaseDate:
19 | if not l['title'].startswith("bump snap"):
20 | result += '\n'
21 | result += "* " + l['title'] + " (#" + stripped + ")"
22 | return result
23 |
24 |
25 | def lastReleaseDate(tag):
26 | content = ghApiClient.readUrl('repos/swagger-api/swagger-petstore/releases/tags/' + tag)
27 | publishedAt = content["published_at"]
28 | return datetime.strptime(publishedAt, '%Y-%m-%dT%H:%M:%SZ')
29 |
30 |
31 | def addRelease(release_title, tag, content):
32 | payload = "{\"tag_name\":\"" + tag + "\", "
33 | payload += "\"name\":" + json.dumps(release_title) + ", "
34 | payload += "\"body\":" + json.dumps(content) + ", "
35 | payload += "\"draft\":" + "true" + ", "
36 | payload += "\"prerelease\":" + "false" + ", "
37 | payload += "\"target_commitish\":\"" + "master" + "\"}"
38 | content = ghApiClient.postUrl('repos/swagger-api/swagger-petstore/releases', payload)
39 | return content
40 |
41 | def getReleases():
42 | content = ghApiClient.readUrl('repos/swagger-api/swagger-petstore/releases')
43 | return content
44 |
45 | # main
46 | def main(last_release, release_title, tag):
47 | result = allPulls(lastReleaseDate(last_release))
48 | addRelease (release_title, tag, result)
49 |
50 | # here start main
51 | main(sys.argv[1], sys.argv[2], sys.argv[3])
52 |
53 |
--------------------------------------------------------------------------------
/CI/version.sh:
--------------------------------------------------------------------------------
1 | grep version pom.xml | grep -v -e '//g' | awk '{print $1}'
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM openjdk:8-jre-alpine
2 |
3 | WORKDIR /swagger-petstore
4 |
5 | COPY target/lib/jetty-runner.jar /swagger-petstore/jetty-runner.jar
6 | COPY target/*.war /swagger-petstore/server.war
7 | COPY src/main/resources/openapi.yaml /swagger-petstore/openapi.yaml
8 | COPY inflector.yaml /swagger-petstore/
9 |
10 | EXPOSE 8080
11 |
12 | CMD ["java", "-jar", "-DswaggerUrl=openapi.yaml", "/swagger-petstore/jetty-runner.jar", "--log", "/var/log/yyyy_mm_dd-requests.log", "/swagger-petstore/server.war"]
13 |
--------------------------------------------------------------------------------
/Dockerfile-telemetry:
--------------------------------------------------------------------------------
1 | FROM openjdk:11-jre-slim
2 |
3 | WORKDIR /swagger-petstore
4 |
5 | RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
6 |
7 | RUN curl -Lo /swagger-petstore/otel-javaagent.jar \
8 | "https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar"
9 |
10 | COPY target/lib/jetty-runner.jar /swagger-petstore/jetty-runner.jar
11 | COPY target/*.war /swagger-petstore/server.war
12 | COPY src/main/resources/openapi.yaml /swagger-petstore/openapi.yaml
13 | COPY inflector.yaml /swagger-petstore/
14 |
15 | EXPOSE 8080
16 |
17 | ENV JAVA_TOOL_OPTIONS="-javaagent:/swagger-petstore/otel-javaagent.jar" \
18 | OTEL_JAVAAGENT_ENABLED=true \
19 | OTEL_TRACES_EXPORTER=otlp \
20 | OTEL_METRICS_EXPORTER=none \
21 | OTEL_LOGS_EXPORTER=otlp \
22 | OTEL_RESOURCE_ATTRIBUTES="service.name=swagger-petstore,deployment.environment=prod" \
23 | OTEL_JAVAAGENT_LOGGING=simple \
24 | OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST=user-agent,authorization \
25 | OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE=content-type \
26 | OTEL_INSTRUMENTATION_HTTP_CAPTURE_PARAMETERS=true \
27 | OTEL_INSTRUMENTATION_HTTP_SERVER_CAPTURE_REQUEST_PARAMETERS=true \
28 | OTEL_INSTRUMENTATION_HTTP_SERVER_CAPTURE_ROUTE=true \
29 | OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT=256 \
30 | OTEL_SESSION_TRACKING_ENABLED=true \
31 | OTEL_SESSION_TRACKING_INTERVAL=30s \
32 | OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="https://$BUGSNAG_API_KEY.otlp.bugsnag.com:4318" \
33 | BUGSNAG_SESSIONS_ENABLED=true
34 |
35 | CMD ["sh", "-c", "export BUGSNAG_API_KEY=$BUGSNAG_API_KEY && \
36 | export OTEL_EXPORTER_OTLP_ENDPOINT=https://$BUGSNAG_API_KEY.otlp.bugsnag.com && \
37 | exec java $JAVA_TOOL_OPTIONS -Dorg.eclipse.jetty.server.RequestLog=DEBUG -Dorg.eclipse.jetty.server.HttpChannel=DEBUG \
38 | -jar -DswaggerUrl=openapi.yaml /swagger-petstore/jetty-runner.jar --log /var/log/yyyy_mm_dd-requests.log /swagger-petstore/server.war"]
39 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Swagger Petstore Sample
2 |
3 | ## Overview
4 | This is the pet store sample hosted at https://petstore3.swagger.io. For other versions, check the branches.
5 | We welcome suggestion both the code and the API design.
6 | To make changes to the design itself, take a look at https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml.
7 |
8 | This is a java project to build a stand-alone server which implements the OpenAPI 3 Spec. You can find out
9 | more about both the spec and the framework at http://swagger.io.
10 |
11 | This sample is based on [swagger-inflector](https://github.com/swagger-api/swagger-inflector), and provides an example of swagger / OpenAPI 3 petstore.
12 |
13 | ### To run (with Maven)
14 | To run the server, run this task:
15 |
16 | ```
17 | mvn package jetty:run
18 | ```
19 |
20 | This will start Jetty embedded on port 8080.
21 |
22 | ### To run (via Docker)
23 |
24 | Expose port 8080 from the image and access petstore via the exposed port. You can then add and delete pets as you see fit.
25 |
26 |
27 | *Example*:
28 |
29 | ```
30 | docker build -t swaggerapi/petstore3:unstable .
31 | ```
32 |
33 | ```
34 | docker pull swaggerapi/petstore3:unstable
35 | docker run --name swaggerapi-petstore3 -d -p 8080:8080 swaggerapi/petstore3:unstable
36 | ```
37 |
38 |
39 | ### Testing the server
40 | Once started, you can navigate to http://localhost:8080/api/v3/openapi.json to view the Swagger Resource Listing.
41 | This tells you that the server is up and ready to demonstrate Swagger.
42 |
43 | ### Using the UI
44 | There is an HTML5-based API tool bundled in this sample--you can view it it at [http://localhost:8080](http://localhost:8080). This lets you inspect the API using an interactive UI. You can access the source of this code from [here](https://github.com/swagger-api/swagger-ui)
45 |
--------------------------------------------------------------------------------
/inflector.yaml:
--------------------------------------------------------------------------------
1 | controllerPackage: io.swagger.petstore.controller
2 | modelPackage: io.swagger.petstore.model
3 | swaggerUrl: openapi.yaml
4 |
5 | exposedSpecOptions:
6 | useOriginalNotParsed: true
7 |
8 | entityProcessors:
9 | - json
10 | - yaml
11 | - xml
12 |
13 | swaggerProcessors:
14 | - io.swagger.petstore.utils.HandleAuthUrlProcessor
15 |
16 | rootPath: /api
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
23 | * Note: This might be replaced by utility method from commons-lang or guava someday 24 | * if one of those libraries is added as dependency. 25 | *
26 | * 27 | * @param array The array of strings 28 | * @param separator The separator 29 | * @return the resulting string 30 | */ 31 | public static String join(String[] array, String separator) { 32 | int len = array.length; 33 | if (len == 0) return ""; 34 | 35 | StringBuilder out = new StringBuilder(); 36 | out.append(array[0]); 37 | for (int i = 1; i < len; i++) { 38 | out.append(separator).append(array[i]); 39 | } 40 | return out.toString(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/gen/java/io/swagger/handler/StringUtil.java: -------------------------------------------------------------------------------- 1 | package io.swagger.handler; 2 | 3 | @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaInflectorServerCodegen", date = "2017-04-08T15:48:56.501Z") 4 | public class StringUtil { 5 | /** 6 | * Check if the given array contains the given value (with case-insensitive comparison). 7 | * 8 | * @param array The array 9 | * @param value The value to search 10 | * @return true if the array contains the value 11 | */ 12 | public static boolean containsIgnoreCase(String[] array, String value) { 13 | for (String str : array) { 14 | if (value == null && str == null) return true; 15 | if (value != null && value.equalsIgnoreCase(str)) return true; 16 | } 17 | return false; 18 | } 19 | 20 | /** 21 | * Join an array of strings with the given separator. 22 | *23 | * Note: This might be replaced by utility method from commons-lang or guava someday 24 | * if one of those libraries is added as dependency. 25 | *
26 | * 27 | * @param array The array of strings 28 | * @param separator The separator 29 | * @return the resulting string 30 | */ 31 | public static String join(String[] array, String separator) { 32 | int len = array.length; 33 | if (len == 0) return ""; 34 | 35 | StringBuilder out = new StringBuilder(); 36 | out.append(array[0]); 37 | for (int i = 1; i < len; i++) { 38 | out.append(separator).append(array[i]); 39 | } 40 | return out.toString(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/io/swagger/petstore/controller/OrderController.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 SmartBear Software 3 | *4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *
10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.swagger.petstore.controller; 18 | 19 | import io.swagger.oas.inflector.models.RequestContext; 20 | import io.swagger.oas.inflector.models.ResponseContext; 21 | import io.swagger.petstore.data.OrderData; 22 | import io.swagger.petstore.model.Order; 23 | import io.swagger.petstore.utils.Util; 24 | import org.joda.time.DateTime; 25 | 26 | import javax.ws.rs.core.Response; 27 | import java.util.Date; 28 | 29 | @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaInflectorServerCodegen", date = "2017-04-08T15:48:56.501Z") 30 | public class OrderController { 31 | 32 | private static OrderData orderData = new OrderData(); 33 | 34 | public ResponseContext getInventory(final RequestContext request) { 35 | return new ResponseContext() 36 | .contentType(Util.getMediaType(request)) 37 | .entity(orderData.getCountByStatus()); 38 | } 39 | 40 | public ResponseContext getOrderById(final RequestContext request, final Long orderId) { 41 | if (orderId == null) { 42 | return new ResponseContext() 43 | .status(Response.Status.BAD_REQUEST) 44 | .entity("No orderId provided. Try again?"); 45 | } 46 | 47 | final Order order = orderData.getOrderById(orderId); 48 | 49 | if (order != null) { 50 | return new ResponseContext() 51 | .contentType(Util.getMediaType(request)) 52 | .entity(order); 53 | } 54 | 55 | return new ResponseContext().status(Response.Status.NOT_FOUND).entity("Order not found"); 56 | } 57 | 58 | public ResponseContext placeOrder(final RequestContext request, final Order order) { 59 | if (order == null) { 60 | return new ResponseContext() 61 | .status(Response.Status.BAD_REQUEST) 62 | .entity("No Order provided. Try again?"); 63 | } 64 | 65 | orderData.addOrder(order); 66 | return new ResponseContext() 67 | .contentType(Util.getMediaType(request)) 68 | .entity(order); 69 | } 70 | 71 | public ResponseContext placeOrder(final RequestContext request, final Long id, final Long petId, final Integer quantity, final DateTime shipDate, 72 | final String status, final Boolean complete) { 73 | final Order order = OrderData.createOrder(id, petId, quantity, new Date(), status, complete); 74 | return placeOrder(request,order); 75 | } 76 | 77 | public ResponseContext deleteOrder(final RequestContext request, final Long orderId) { 78 | if (orderId == null) { 79 | return new ResponseContext() 80 | .status(Response.Status.BAD_REQUEST) 81 | .entity("No orderId provided. Try again?"); 82 | } 83 | 84 | orderData.deleteOrderById(orderId); 85 | 86 | final Order order = orderData.getOrderById(orderId); 87 | 88 | if (null == order) { 89 | return new ResponseContext() 90 | .contentType(Util.getMediaType(request)) 91 | .entity(order); 92 | } else { 93 | return new ResponseContext().status(Response.Status.NOT_MODIFIED).entity("Order couldn't be deleted."); 94 | } 95 | } 96 | } -------------------------------------------------------------------------------- /src/main/java/io/swagger/petstore/controller/PetController.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 SmartBear Software 3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.swagger.petstore.controller;
18 |
19 | import io.swagger.oas.inflector.models.RequestContext;
20 | import io.swagger.oas.inflector.models.ResponseContext;
21 | import io.swagger.petstore.data.PetData;
22 | import io.swagger.petstore.model.Category;
23 | import io.swagger.petstore.model.Pet;
24 | import io.swagger.petstore.model.Tag;
25 | import io.swagger.petstore.notification.Notifier;
26 | import io.swagger.petstore.notification.NullNotifier;
27 | import io.swagger.petstore.utils.Util;
28 |
29 | import javax.ws.rs.core.MediaType;
30 | import javax.ws.rs.core.Response;
31 | import java.io.File;
32 | import java.util.List;
33 |
34 | @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaInflectorServerCodegen", date = "2017-04-08T15:48:56.501Z")
35 | public class PetController {
36 |
37 | private static PetData petData = new PetData();
38 | private Notifier notifier = new NullNotifier();
39 |
40 | public PetController() {
41 | if (System.getenv("notifierClass") != null) {
42 | try {
43 | notifier = (Notifier) this.getClass().forName(System.getenv("notifierClass")).newInstance();
44 | } catch (Exception e) {
45 | //
46 | }
47 | }
48 | }
49 |
50 | public ResponseContext findPetsByStatus(final RequestContext request, final String status) {
51 | if (status == null) {
52 | notifier.notify(new RuntimeException("No status provided"));
53 | return new ResponseContext()
54 | .status(Response.Status.BAD_REQUEST)
55 | .entity("No status provided. Try again?");
56 | }
57 |
58 | final List
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.swagger.petstore.controller;
18 |
19 | import io.swagger.oas.inflector.models.RequestContext;
20 | import io.swagger.oas.inflector.models.ResponseContext;
21 | import io.swagger.petstore.data.UserData;
22 | import io.swagger.petstore.model.User;
23 | import io.swagger.petstore.utils.Util;
24 | import org.apache.commons.lang3.RandomUtils;
25 |
26 | import javax.ws.rs.core.Response;
27 | import java.util.Date;
28 |
29 | @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaInflectorServerCodegen", date = "2017-04-08T15:48:56.501Z")
30 | public class UserController {
31 |
32 | private static UserData userData = new UserData();
33 |
34 | public ResponseContext createUser(final RequestContext request, final User user) {
35 | if (user == null) {
36 | return new ResponseContext()
37 | .status(Response.Status.BAD_REQUEST)
38 | .entity("No User provided. Try again?");
39 | }
40 |
41 | userData.addUser(user);
42 | return new ResponseContext()
43 | .contentType(Util.getMediaType(request))
44 | .entity(user);
45 | }
46 |
47 | public ResponseContext createUser(final RequestContext request, final Long id, final String username,
48 | final String firstName, final String lastName, final String email,
49 | final String password, final String phone, final Integer userStatus) {
50 | final User user = UserData.createUser(id, username, firstName, lastName, email, phone, userStatus);
51 | return createUser(request, user);
52 | }
53 |
54 | public ResponseContext getUserByName(final RequestContext request, final String username) {
55 | if (username == null) {
56 | return new ResponseContext()
57 | .status(Response.Status.BAD_REQUEST)
58 | .entity("No username provided. Try again?");
59 | }
60 |
61 | final User user = userData.findUserByName(username);
62 | if (user == null) {
63 | return new ResponseContext().status(Response.Status.NOT_FOUND).entity("User not found");
64 | }
65 |
66 | return new ResponseContext()
67 | .contentType(Util.getMediaType(request))
68 | .entity(user);
69 | }
70 |
71 | public ResponseContext createUsersWithArrayInput(final RequestContext request, final User[] users) {
72 | if (users == null || users.length == 0) {
73 | return new ResponseContext()
74 | .status(Response.Status.BAD_REQUEST)
75 | .entity("No User provided. Try again?");
76 | }
77 |
78 | for (final User user : users) {
79 | userData.addUser(user);
80 | }
81 |
82 | return new ResponseContext()
83 | .contentType(Util.getMediaType(request))
84 | .entity(users);
85 | }
86 |
87 | public ResponseContext createUsersWithListInput(final RequestContext request, final User[] users) {
88 | if (users == null || users.length == 0) {
89 | return new ResponseContext()
90 | .status(Response.Status.BAD_REQUEST)
91 | .entity("No User provided. Try again?");
92 | }
93 |
94 | for (final User user : users) {
95 | userData.addUser(user);
96 | }
97 |
98 | return new ResponseContext()
99 | .contentType(Util.getMediaType(request))
100 | .entity(users);
101 | }
102 |
103 | public ResponseContext loginUser(final RequestContext request, final String username, final String password) {
104 | Date date = new Date(System.currentTimeMillis() + 3600000);
105 | return new ResponseContext()
106 | .contentType(Util.getMediaType(request))
107 | .header("X-Rate-Limit", String.valueOf(5000))
108 | .header("X-Expires-After", date.toString())
109 | .entity("Logged in user session: " + RandomUtils.nextLong());
110 | }
111 |
112 | public ResponseContext logoutUser(final RequestContext request) {
113 | return new ResponseContext()
114 | .contentType(Util.getMediaType(request))
115 | .entity("User logged out");
116 |
117 | }
118 |
119 | public ResponseContext deleteUser(final RequestContext request, final String username) {
120 | if (username == null) {
121 | return new ResponseContext()
122 | .status(Response.Status.BAD_REQUEST)
123 | .entity("No username provided. Try again?");
124 | }
125 |
126 | userData.deleteUser(username);
127 |
128 | final User user = userData.findUserByName(username);
129 |
130 | if (null == user) {
131 | return new ResponseContext()
132 | .contentType(Util.getMediaType(request))
133 | .entity(user);
134 | } else {
135 | return new ResponseContext().status(Response.Status.NOT_MODIFIED).entity("User couldn't be deleted.");
136 | }
137 | }
138 |
139 | public ResponseContext updateUser(final RequestContext request, final String username, final User user) {
140 | if (username == null) {
141 | return new ResponseContext()
142 | .status(Response.Status.BAD_REQUEST)
143 | .entity("No Username provided. Try again?");
144 | }
145 |
146 | if (user == null) {
147 | return new ResponseContext()
148 | .status(Response.Status.BAD_REQUEST)
149 | .entity("No User provided. Try again?");
150 | }
151 |
152 | final User existingUser = userData.findUserByName(username);
153 |
154 | if (existingUser == null) {
155 | return new ResponseContext().status(Response.Status.NOT_FOUND).entity("User not found");
156 | }
157 |
158 | userData.deleteUser(existingUser.getUsername());
159 | userData.addUser(user);
160 |
161 | return new ResponseContext()
162 | .contentType(Util.getMediaType(request))
163 | .entity(user);
164 | }
165 |
166 | public ResponseContext updateUser(final RequestContext request, final String updatedUser, final Long id, final String username,
167 | final String firstName, final String lastName, final String email,
168 | final String password, final String phone, final Integer userStatus) {
169 | final User user = UserData.createUser(id, username, firstName, lastName, email, phone, userStatus);
170 | return updateUser(request, updatedUser, user);
171 | }
172 | }
173 |
174 |
--------------------------------------------------------------------------------
/src/main/java/io/swagger/petstore/data/OrderData.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2018 SmartBear Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.swagger.petstore.data;
18 |
19 | import io.swagger.petstore.model.Order;
20 |
21 | import java.util.*;
22 |
23 | public class OrderData {
24 | private static List
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.swagger.petstore.data;
18 |
19 | import io.swagger.petstore.model.Category;
20 | import io.swagger.petstore.model.Pet;
21 | import io.swagger.petstore.model.Tag;
22 |
23 | import java.util.ArrayList;
24 | import java.util.Arrays;
25 | import java.util.List;
26 |
27 | public class PetData {
28 | private static List
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.swagger.petstore.data;
18 |
19 | import io.swagger.petstore.model.User;
20 |
21 | import java.util.ArrayList;
22 | import java.util.List;
23 |
24 | public class UserData {
25 | private static List
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.swagger.petstore.exception;
18 |
19 | public class ApiException extends Exception {
20 | private int code;
21 |
22 | public ApiException(final int code, final String msg) {
23 | super(msg);
24 | this.code = code;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/io/swagger/petstore/exception/NotFoundException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2018 SmartBear Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.swagger.petstore.exception;
18 |
19 | public class NotFoundException extends ApiException {
20 | private int code;
21 |
22 | public NotFoundException(int code, String msg) {
23 | super(code, msg);
24 | this.code = code;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/io/swagger/petstore/model/ApiResponse.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2016 SmartBear Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.swagger.petstore.model;
18 |
19 | import javax.xml.bind.annotation.XmlTransient;
20 |
21 | @javax.xml.bind.annotation.XmlRootElement
22 | public class ApiResponse {
23 | public static final int ERROR = 1;
24 | public static final int WARNING = 2;
25 | public static final int INFO = 3;
26 | public static final int OK = 4;
27 | public static final int TOO_BUSY = 5;
28 |
29 | int code;
30 | String type;
31 | String message;
32 |
33 | public ApiResponse(){}
34 |
35 | public ApiResponse(int code, String message){
36 | this.code = code;
37 | switch(code){
38 | case ERROR:
39 | setType("error");
40 | break;
41 | case WARNING:
42 | setType("warning");
43 | break;
44 | case INFO:
45 | setType("info");
46 | break;
47 | case OK:
48 | setType("ok");
49 | break;
50 | case TOO_BUSY:
51 | setType("too busy");
52 | break;
53 | default:
54 | setType("unknown");
55 | break;
56 | }
57 | this.message = message;
58 | }
59 |
60 | @XmlTransient
61 | public int getCode() {
62 | return code;
63 | }
64 |
65 | public void setCode(int code) {
66 | this.code = code;
67 | }
68 |
69 | public String getType() {
70 | return type;
71 | }
72 |
73 | public void setType(String type) {
74 | this.type = type;
75 | }
76 |
77 | public String getMessage() {
78 | return message;
79 | }
80 |
81 | public void setMessage(String message) {
82 | this.message = message;
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/java/io/swagger/petstore/model/Category.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2018 SmartBear Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.swagger.petstore.model;
18 |
19 | import javax.xml.bind.annotation.XmlElement;
20 | import javax.xml.bind.annotation.XmlRootElement;
21 |
22 | @XmlRootElement(name = "Category")
23 | public class Category {
24 | private long id;
25 | private String name;
26 |
27 | @XmlElement(name = "id")
28 | public long getId() {
29 | return id;
30 | }
31 |
32 | public void setId(long id) {
33 | this.id = id;
34 | }
35 |
36 | @XmlElement(name = "name")
37 | public String getName() {
38 | return name;
39 | }
40 |
41 | public void setName(String name) {
42 | this.name = name;
43 | }
44 | }
--------------------------------------------------------------------------------
/src/main/java/io/swagger/petstore/model/Order.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2018 SmartBear Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.swagger.petstore.model;
18 |
19 | import io.swagger.v3.oas.annotations.media.Schema;
20 |
21 | import javax.xml.bind.annotation.XmlElement;
22 | import javax.xml.bind.annotation.XmlRootElement;
23 | import java.util.Date;
24 |
25 | @XmlRootElement(name = "Order")
26 | public class Order {
27 | private long id;
28 | private long petId;
29 | private int quantity;
30 | private Date shipDate;
31 | private String status;
32 | private boolean complete;
33 |
34 | @XmlElement(name = "id")
35 | public long getId() {
36 | return id;
37 | }
38 |
39 | public void setId(long id) {
40 | this.id = id;
41 | }
42 |
43 | public boolean isComplete() {
44 | return complete;
45 | }
46 |
47 | public void setComplete(boolean complete) {
48 | this.complete = complete;
49 | }
50 |
51 |
52 | @XmlElement(name = "petId")
53 | public long getPetId() {
54 | return petId;
55 | }
56 |
57 | public void setPetId(long petId) {
58 | this.petId = petId;
59 | }
60 |
61 | @XmlElement(name = "quantity")
62 | public int getQuantity() {
63 | return quantity;
64 | }
65 |
66 | public void setQuantity(int quantity) {
67 | this.quantity = quantity;
68 | }
69 |
70 | @XmlElement(name = "status")
71 | @Schema(description = "Order Status", allowableValues = "placed, approved, delivered")
72 | public String getStatus() {
73 | return status;
74 | }
75 |
76 | public void setStatus(String status) {
77 | this.status = status;
78 | }
79 |
80 | @XmlElement(name = "shipDate")
81 | public Date getShipDate() {
82 | return shipDate;
83 | }
84 |
85 | public void setShipDate(Date shipDate) {
86 | this.shipDate = shipDate;
87 | }
88 | }
--------------------------------------------------------------------------------
/src/main/java/io/swagger/petstore/model/Pet.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2018 SmartBear Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.swagger.petstore.model;
18 |
19 | import io.swagger.v3.oas.annotations.media.Schema;
20 |
21 | import javax.xml.bind.annotation.XmlElement;
22 | import javax.xml.bind.annotation.XmlElementWrapper;
23 | import javax.xml.bind.annotation.XmlRootElement;
24 | import java.util.ArrayList;
25 | import java.util.List;
26 |
27 | @XmlRootElement(name = "Pet")
28 | public class Pet {
29 | private Long id;
30 | private Category category;
31 | private String name;
32 | private List