diff --git a/.gradle/6.8/executionHistory/executionHistory.bin b/.gradle/6.8/executionHistory/executionHistory.bin index 2b1750df8a906f384bac3c1fb159b021be4aaeb1..58c56719e69feaa017c2064de75d24c833bd55e2 100644 Binary files a/.gradle/6.8/executionHistory/executionHistory.bin and b/.gradle/6.8/executionHistory/executionHistory.bin differ diff --git a/.gradle/6.8/executionHistory/executionHistory.lock b/.gradle/6.8/executionHistory/executionHistory.lock index adf98ccd5eefe6617ce22f81a8d9f8a0fe002364..62dfc85bc4b89872cb2ad3e1aefa24693522d8a8 100644 Binary files a/.gradle/6.8/executionHistory/executionHistory.lock and b/.gradle/6.8/executionHistory/executionHistory.lock differ diff --git a/.gradle/6.8/fileHashes/fileHashes.bin b/.gradle/6.8/fileHashes/fileHashes.bin index 7627d32a8fcdbf45ec7f7debb787d6acca704950..9f57622cbb1b697da871e95db7550246ecbf3a49 100644 Binary files a/.gradle/6.8/fileHashes/fileHashes.bin and b/.gradle/6.8/fileHashes/fileHashes.bin differ diff --git a/.gradle/6.8/fileHashes/fileHashes.lock b/.gradle/6.8/fileHashes/fileHashes.lock index d3eec9ad5c561fc0e7be5935ac780bf539cd8b22..35fd05debb4ecdeaaeff59014933f889ad7461f5 100644 Binary files a/.gradle/6.8/fileHashes/fileHashes.lock and b/.gradle/6.8/fileHashes/fileHashes.lock differ diff --git a/.gradle/6.8/javaCompile/classAnalysis.bin b/.gradle/6.8/javaCompile/classAnalysis.bin index 62ef4e3ad5de2b867f612afe495c7f08db9eb6e5..c6b7537a9c2b40e457579d1cb996ec4fe7e081f4 100644 Binary files a/.gradle/6.8/javaCompile/classAnalysis.bin and b/.gradle/6.8/javaCompile/classAnalysis.bin differ diff --git a/.gradle/6.8/javaCompile/javaCompile.lock b/.gradle/6.8/javaCompile/javaCompile.lock index c304b9ac7c9960e869501e18bc24b8197e700e65..86eafb0daf0c66271f2ef0815673cc0b4ff1e76c 100644 Binary files a/.gradle/6.8/javaCompile/javaCompile.lock and b/.gradle/6.8/javaCompile/javaCompile.lock differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index c57f4cdfb03a44607efd70d7e772d9d4b84e777c..32df1e0d0b372ba2045dd4f4044f9b0a6c0ac778 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/build/classes/java/main/de/tudresden/inf/st/openapi/HttpURLConnectionExample.class b/build/classes/java/main/de/tudresden/inf/st/openapi/HttpURLConnectionExample.class new file mode 100644 index 0000000000000000000000000000000000000000..8b5a6bab51ac3826f49a716f9998d3edd65ac783 Binary files /dev/null and b/build/classes/java/main/de/tudresden/inf/st/openapi/HttpURLConnectionExample.class differ diff --git a/build/classes/java/main/de/tudresden/inf/st/openapi/OpenAPIMain.class b/build/classes/java/main/de/tudresden/inf/st/openapi/OpenAPIMain.class index 935127c238b8964ca08444c965ddc6e250a779ac..7639704adf63f312b64b0adf72af6678cc78d7ac 100644 Binary files a/build/classes/java/main/de/tudresden/inf/st/openapi/OpenAPIMain.class and b/build/classes/java/main/de/tudresden/inf/st/openapi/OpenAPIMain.class differ diff --git a/build/classes/java/test/openapi/OpenAPIMain_test.class b/build/classes/java/test/openapi/OpenAPIMain_test.class index fcf5409409bd4bf1659df1fc43a1435f4c278ae0..29ffda4416639b46e049b00d3c4e21e888615e05 100644 Binary files a/build/classes/java/test/openapi/OpenAPIMain_test.class and b/build/classes/java/test/openapi/OpenAPIMain_test.class differ diff --git a/build/reports/tests/test/classes/openapi.OpenAPIMain_test.html b/build/reports/tests/test/classes/openapi.OpenAPIMain_test.html index 105d4c434447ae620842c349cf8da1d0257392a1..76ceafc06639f00a78ac5ddd4137d6841a983ab7 100644 --- a/build/reports/tests/test/classes/openapi.OpenAPIMain_test.html +++ b/build/reports/tests/test/classes/openapi.OpenAPIMain_test.html @@ -41,7 +41,7 @@ </td> <td> <div class="infoBox" id="duration"> -<div class="counter">11.669s</div> +<div class="counter">21.339s</div> <p>duration</p> </div> </td> @@ -79,7 +79,7 @@ </thead> <tr> <td class="success">test()</td> -<td class="success">11.669s</td> +<td class="success">21.339s</td> <td class="success">passed</td> </tr> </table> @@ -199,7 +199,7 @@ Loading expression DSL file 'uspto.json'. <input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/> </label> </div>Generated by -<a href="http://www.gradle.org">Gradle 6.8</a> at 2021. 8. 29. 오전 2:06:22</p> +<a href="http://www.gradle.org">Gradle 6.8</a> at 2021. 8. 31. 오후 3:42:40</p> </div> </div> </body> diff --git a/build/reports/tests/test/index.html b/build/reports/tests/test/index.html index a7423a5482bda3860a2bae83924c24b22e08ec36..6e5070e8f738c3de9bb2172905a57d957ac6bee4 100644 --- a/build/reports/tests/test/index.html +++ b/build/reports/tests/test/index.html @@ -38,7 +38,7 @@ </td> <td> <div class="infoBox" id="duration"> -<div class="counter">11.669s</div> +<div class="counter">21.339s</div> <p>duration</p> </div> </td> @@ -85,7 +85,7 @@ <td>1</td> <td>0</td> <td>0</td> -<td>11.669s</td> +<td>21.339s</td> <td class="success">100%</td> </tr> </tbody> @@ -112,7 +112,7 @@ <td>1</td> <td>0</td> <td>0</td> -<td>11.669s</td> +<td>21.339s</td> <td class="success">100%</td> </tr> </tbody> @@ -126,7 +126,7 @@ <input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/> </label> </div>Generated by -<a href="http://www.gradle.org">Gradle 6.8</a> at 2021. 8. 29. 오전 2:06:22</p> +<a href="http://www.gradle.org">Gradle 6.8</a> at 2021. 8. 31. 오후 3:42:40</p> </div> </div> </body> diff --git a/build/reports/tests/test/packages/openapi.html b/build/reports/tests/test/packages/openapi.html index e83a32ec09a320ee719ae03a87065a76e32803c1..de5f998754c8b624a65500b75f228c5644fa2680 100644 --- a/build/reports/tests/test/packages/openapi.html +++ b/build/reports/tests/test/packages/openapi.html @@ -40,7 +40,7 @@ </td> <td> <div class="infoBox" id="duration"> -<div class="counter">11.669s</div> +<div class="counter">21.339s</div> <p>duration</p> </div> </td> @@ -83,7 +83,7 @@ <td>1</td> <td>0</td> <td>0</td> -<td>11.669s</td> +<td>21.339s</td> <td class="success">100%</td> </tr> </table> @@ -96,7 +96,7 @@ <input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/> </label> </div>Generated by -<a href="http://www.gradle.org">Gradle 6.8</a> at 2021. 8. 29. 오전 2:06:22</p> +<a href="http://www.gradle.org">Gradle 6.8</a> at 2021. 8. 31. 오후 3:42:40</p> </div> </div> </body> diff --git a/build/resources/main/petstore-v2.yaml b/build/resources/main/petstore-v2.yaml new file mode 100644 index 0000000000000000000000000000000000000000..9184e9c8064400d24261e3ae5929c33a714c0337 --- /dev/null +++ b/build/resources/main/petstore-v2.yaml @@ -0,0 +1,738 @@ +openapi: 3.0.0 +servers: + - url: 'http://petstore.swagger.io/v2' +info: + description: >- + This is a sample server Petstore server. For this sample, you can use the api key + `special-key` to test the authorization filters. + version: 1.0.0 + title: OpenAPI Petstore + license: + name: Apache-2.0 + url: 'https://www.apache.org/licenses/LICENSE-2.0.html' +tags: + - name: pet + description: Everything about your Pets + - name: store + description: Access to Petstore orders + - name: user + description: Operations about user +paths: + /pet: + post: + tags: + - pet + summary: Add a new pet to the store + description: '' + operationId: addPet + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + '405': + description: Invalid input + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + $ref: '#/components/requestBodies/Pet' + put: + tags: + - pet + summary: Update an existing pet + description: '' + operationId: updatePet + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid ID supplied + '404': + description: Pet not found + '405': + description: Validation exception + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + $ref: '#/components/requestBodies/Pet' + /pet/findByStatus: + get: + tags: + - pet + summary: Finds Pets by status + description: Multiple status values can be provided with comma separated strings + operationId: findPetsByStatus + parameters: + - name: status + in: query + description: Status values that need to be considered for filter + required: true + style: form + explode: false + deprecated: true + schema: + type: array + items: + type: string + enum: + - available + - pending + - sold + default: available + responses: + '200': + description: successful operation + content: + application/xml: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid status value + security: + - petstore_auth: + - 'read:pets' + /pet/findByTags: + get: + tags: + - pet + summary: Finds Pets by tags + description: >- + Multiple tags can be provided with comma separated strings. Use tag1, + tag2, tag3 for testing. + operationId: findPetsByTags + parameters: + - name: tags + in: query + description: Tags to filter by + required: true + style: form + explode: false + schema: + type: array + items: + type: string + responses: + '200': + description: successful operation + content: + application/xml: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid tag value + security: + - petstore_auth: + - 'read:pets' + deprecated: true + '/pet/{petId}': + get: + tags: + - pet + summary: Find pet by ID + description: Returns a single pet + operationId: getPetById + parameters: + - name: petId + in: path + description: ID of pet to return + required: true + schema: + type: integer + format: int64 + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid ID supplied + '404': + description: Pet not found + security: + - api_key: [] + post: + tags: + - pet + summary: Updates a pet in the store with form data + description: '' + operationId: updatePetWithForm + parameters: + - name: petId + in: path + description: ID of pet that needs to be updated + required: true + schema: + type: integer + format: int64 + responses: + '405': + description: Invalid input + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + content: + application/x-www-form-urlencoded: + schema: + type: object + properties: + name: + description: Updated name of the pet + type: string + status: + description: Updated status of the pet + type: string + delete: + tags: + - pet + summary: Deletes a pet + description: '' + operationId: deletePet + parameters: + - name: api_key + in: header + required: false + schema: + type: string + - name: petId + in: path + description: Pet id to delete + required: true + schema: + type: integer + format: int64 + responses: + '400': + description: Invalid pet value + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + '/pet/{petId}/uploadImage': + post: + tags: + - pet + summary: uploads an image + description: '' + operationId: uploadFile + parameters: + - name: petId + in: path + description: ID of pet to update + required: true + schema: + type: integer + format: int64 + responses: + '200': + description: successful operation + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponse' + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + content: + multipart/form-data: + schema: + type: object + properties: + additionalMetadata: + description: Additional data to pass to server + type: string + file: + description: file to upload + type: string + format: binary + /store/inventory: + get: + tags: + - store + summary: Returns pet inventories by status + description: Returns a map of status codes to quantities + operationId: getInventory + responses: + '200': + description: successful operation + content: + application/json: + schema: + type: object + additionalProperties: + type: integer + format: int32 + security: + - api_key: [] + /store/order: + post: + tags: + - store + summary: Place an order for a pet + description: '' + operationId: placeOrder + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Order' + application/json: + schema: + $ref: '#/components/schemas/Order' + '400': + description: Invalid Order + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Order' + description: order placed for purchasing the pet + required: true + '/store/order/{orderId}': + get: + tags: + - store + summary: Find purchase order by ID + description: >- + For valid response try integer IDs with value <= 5 or > 10. Other values + will generated exceptions + operationId: getOrderById + parameters: + - name: orderId + in: path + description: ID of pet that needs to be fetched + required: true + schema: + type: integer + format: int64 + minimum: 1 + maximum: 5 + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Order' + application/json: + schema: + $ref: '#/components/schemas/Order' + '400': + description: Invalid ID supplied + '404': + description: Order not found + delete: + tags: + - store + summary: Delete purchase order by ID + description: >- + For valid response try integer IDs with value < 1000. Anything above + 1000 or nonintegers will generate API errors + operationId: deleteOrder + parameters: + - name: orderId + in: path + description: ID of the order that needs to be deleted + required: true + schema: + type: string + responses: + '400': + description: Invalid ID supplied + '404': + description: Order not found + /user: + post: + tags: + - user + summary: Create user + description: This can only be done by the logged in user. + operationId: createUser + responses: + default: + description: successful operation + security: + - api_key: [] + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/User' + description: Created user object + required: true + /user/createWithArray: + post: + tags: + - user + summary: Creates list of users with given input array + description: '' + operationId: createUsersWithArrayInput + responses: + default: + description: successful operation + security: + - api_key: [] + requestBody: + $ref: '#/components/requestBodies/UserArray' + /user/createWithList: + post: + tags: + - user + summary: Creates list of users with given input array + description: '' + operationId: createUsersWithListInput + responses: + default: + description: successful operation + security: + - api_key: [] + requestBody: + $ref: '#/components/requestBodies/UserArray' + /user/login: + get: + tags: + - user + summary: Logs user into the system + description: '' + operationId: loginUser + parameters: + - name: username + in: query + description: The user name for login + required: true + schema: + type: string + pattern: '^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$' + - name: password + in: query + description: The password for login in clear text + required: true + schema: + type: string + responses: + '200': + description: successful operation + headers: + Set-Cookie: + description: >- + Cookie authentication key for use with the `api_key` + apiKey authentication. + schema: + type: string + example: AUTH_KEY=abcde12345; Path=/; HttpOnly + X-Rate-Limit: + description: calls per hour allowed by the user + schema: + type: integer + format: int32 + X-Expires-After: + description: date in UTC when token expires + schema: + type: string + format: date-time + content: + application/xml: + schema: + type: string + application/json: + schema: + type: string + '400': + description: Invalid username/password supplied + /user/logout: + get: + tags: + - user + summary: Logs out current logged in user session + description: '' + operationId: logoutUser + responses: + default: + description: successful operation + security: + - api_key: [] + '/user/{username}': + get: + tags: + - user + summary: Get user by user name + description: '' + operationId: getUserByName + parameters: + - name: username + in: path + description: The name that needs to be fetched. Use user1 for testing. + required: true + schema: + type: string + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/User' + application/json: + schema: + $ref: '#/components/schemas/User' + '400': + description: Invalid username supplied + '404': + description: User not found + put: + tags: + - user + summary: Updated user + description: This can only be done by the logged in user. + operationId: updateUser + parameters: + - name: username + in: path + description: name that need to be deleted + required: true + schema: + type: string + responses: + '400': + description: Invalid user supplied + '404': + description: User not found + security: + - api_key: [] + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/User' + description: Updated user object + required: true + delete: + tags: + - user + summary: Delete user + description: This can only be done by the logged in user. + operationId: deleteUser + parameters: + - name: username + in: path + description: The name that needs to be deleted + required: true + schema: + type: string + responses: + '400': + description: Invalid username supplied + '404': + description: User not found + security: + - api_key: [] +externalDocs: + description: Find out more about Swagger + url: 'http://swagger.io' +components: + requestBodies: + UserArray: + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/User' + description: List of user object + required: true + Pet: + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + application/xml: + schema: + $ref: '#/components/schemas/Pet' + description: Pet object that needs to be added to the store + required: true + securitySchemes: + petstore_auth: + type: oauth2 + flows: + implicit: + authorizationUrl: 'http://petstore.swagger.io/api/oauth/dialog' + scopes: + 'write:pets': modify pets in your account + 'read:pets': read your pets + api_key: + type: apiKey + name: api_key + in: header + schemas: + Order: + title: Pet Order + description: An order for a pets from the pet store + type: object + properties: + id: + type: integer + format: int64 + petId: + type: integer + format: int64 + quantity: + type: integer + format: int32 + shipDate: + type: string + format: date-time + status: + type: string + description: Order Status + enum: + - placed + - approved + - delivered + complete: + type: boolean + default: false + xml: + name: Order + Category: + title: Pet category + description: A category for a pet + type: object + properties: + id: + type: integer + format: int64 + name: + type: string + pattern: '^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$' + xml: + name: Category + User: + title: a User + description: A User who is purchasing from the pet store + type: object + properties: + id: + type: integer + format: int64 + username: + type: string + firstName: + type: string + lastName: + type: string + email: + type: string + password: + type: string + phone: + type: string + userStatus: + type: integer + format: int32 + description: User Status + xml: + name: User + Tag: + title: Pet Tag + description: A tag for a pet + type: object + properties: + id: + type: integer + format: int64 + name: + type: string + xml: + name: Tag + Pet: + title: a Pet + description: A pet for sale in the pet store + type: object + required: + - name + - photoUrls + properties: + id: + type: integer + format: int64 + category: + $ref: '#/components/schemas/Category' + name: + type: string + example: doggie + photoUrls: + type: array + xml: + name: photoUrl + wrapped: true + items: + type: string + tags: + type: array + xml: + name: tag + wrapped: true + items: + $ref: '#/components/schemas/Tag' + status: + type: string + description: pet status in the store + deprecated: true + enum: + - available + - pending + - sold + xml: + name: Pet + ApiResponse: + title: An uploaded response + description: Describes the result of uploading an image resource + type: object + properties: + code: + type: integer + format: int32 + type: + type: string + message: + type: string diff --git a/build/test-results/test/TEST-openapi.OpenAPIMain_test.xml b/build/test-results/test/TEST-openapi.OpenAPIMain_test.xml index b274e3c0690fe845728674439b5fabf77d6b7e66..03b9f211b28290a8a1a764fbddc2dec1cb01e84f 100644 --- a/build/test-results/test/TEST-openapi.OpenAPIMain_test.xml +++ b/build/test-results/test/TEST-openapi.OpenAPIMain_test.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> -<testsuite name="openapi.OpenAPIMain_test" tests="1" skipped="0" failures="0" errors="0" timestamp="2021-08-28T17:06:10" hostname="DESKTOP-RAH69DT" time="11.669"> +<testsuite name="openapi.OpenAPIMain_test" tests="1" skipped="0" failures="0" errors="0" timestamp="2021-08-31T06:42:18" hostname="DESKTOP-RAH69DT" time="21.339"> <properties/> - <testcase name="test()" classname="openapi.OpenAPIMain_test" time="11.669"/> + <testcase name="test()" classname="openapi.OpenAPIMain_test" time="21.339"/> <system-out><![CDATA[100 Loading expression DSL file '1password.com-events-1.0.0.json'. Loading expression DSL file '1password.local-connect-1.3.0.json'. diff --git a/build/test-results/test/binary/results.bin b/build/test-results/test/binary/results.bin index 1c65921d243caf39db375d7f986fd5487250d727..d16a5ed5807fe1b8415f089399f781b5c4eac081 100644 Binary files a/build/test-results/test/binary/results.bin and b/build/test-results/test/binary/results.bin differ diff --git a/pom.xml b/pom.xml index eadf29798d1e69b2bcc2391af12746a7b8810ed0..0052e677764ba3563b524fe0d1679f5b012a8dc7 100644 --- a/pom.xml +++ b/pom.xml @@ -49,6 +49,12 @@ <artifactId>jackson-dataformat-yaml</artifactId> <version>2.1.2</version> </dependency> + <dependency> + <groupId>org.openapi4j</groupId> + <artifactId>openapi-operation-validator</artifactId> + <version>1.0.7</version> + <scope>compile</scope> + </dependency> </dependencies> <properties> <maven.compiler.source>1.8</maven.compiler.source> diff --git a/src/main/java/de/tudresden/inf/st/openapi/HttpURLConnectionExample.java b/src/main/java/de/tudresden/inf/st/openapi/HttpURLConnectionExample.java new file mode 100644 index 0000000000000000000000000000000000000000..742084b72c1ab81a7f6f677396b4a74a6e1cee85 --- /dev/null +++ b/src/main/java/de/tudresden/inf/st/openapi/HttpURLConnectionExample.java @@ -0,0 +1,81 @@ +package de.tudresden.inf.st.openapi; + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import javax.net.ssl.HttpsURLConnection; + +public class HttpURLConnectionExample { + + private final String USER_AGENT = "Mozilla/5.0"; + + public static void main(String[] args) throws Exception { + + HttpURLConnectionExample http = new HttpURLConnectionExample(); + + System.out.println("Data call with GET"); + http.sendGet("https://www.naver.com"); + + System.out.println("Data call with POST"); + String urlParameters = "sn=C02G8416DRJM&cn=&locale=&caller=&num=12345"; + http.sendPost("https://www.google.co.kr/", urlParameters); + } + + // HTTP GET request + private void sendGet(String targetUrl) throws Exception { + + URL url = new URL(targetUrl); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + + con.setRequestMethod("GET"); // optional default is GET + con.setRequestProperty("User-Agent", USER_AGENT); // add request header + + int responseCode = con.getResponseCode(); + BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); + String inputLine; + StringBuffer response = new StringBuffer(); + + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + in.close(); + + // print result + System.out.println("HTTP status code : " + responseCode); + //System.out.println("HTTP body : " + response.toString()); + } + + // HTTP POST request + private void sendPost(String targetUrl, String parameters) throws Exception { + + URL url = new URL(targetUrl); + HttpsURLConnection con = (HttpsURLConnection) url.openConnection(); + + con.setRequestMethod("POST"); // HTTP POST + con.setRequestProperty("User-Agent", USER_AGENT); + con.setDoOutput(true); // POST + // Send post request + DataOutputStream wr = new DataOutputStream(con.getOutputStream()); + wr.writeBytes(parameters); + wr.flush(); + wr.close(); + + int responseCode = con.getResponseCode(); + BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); + String inputLine; + StringBuffer response = new StringBuffer(); + + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + in.close(); + + // print result + System.out.println("HTTP status code : " + responseCode); + //System.out.println("HTTP body : " + response.toString()); + + } +} \ No newline at end of file diff --git a/src/main/java/de/tudresden/inf/st/openapi/OpenAPIMain.java b/src/main/java/de/tudresden/inf/st/openapi/OpenAPIMain.java index 95114e34aa080753e324a0251bf73202b9fd4158..91eeecb7277d96b5324f79c49286984a4af587f0 100644 --- a/src/main/java/de/tudresden/inf/st/openapi/OpenAPIMain.java +++ b/src/main/java/de/tudresden/inf/st/openapi/OpenAPIMain.java @@ -62,6 +62,8 @@ public class OpenAPIMain { //writer.write(api3.toNode().toPrettyString()); //writer.close(); + + if (args.length > 0) { fileName = args[0]; } diff --git a/src/main/resources/petstore-v2.yaml b/src/main/resources/petstore-v2.yaml new file mode 100644 index 0000000000000000000000000000000000000000..9184e9c8064400d24261e3ae5929c33a714c0337 --- /dev/null +++ b/src/main/resources/petstore-v2.yaml @@ -0,0 +1,738 @@ +openapi: 3.0.0 +servers: + - url: 'http://petstore.swagger.io/v2' +info: + description: >- + This is a sample server Petstore server. For this sample, you can use the api key + `special-key` to test the authorization filters. + version: 1.0.0 + title: OpenAPI Petstore + license: + name: Apache-2.0 + url: 'https://www.apache.org/licenses/LICENSE-2.0.html' +tags: + - name: pet + description: Everything about your Pets + - name: store + description: Access to Petstore orders + - name: user + description: Operations about user +paths: + /pet: + post: + tags: + - pet + summary: Add a new pet to the store + description: '' + operationId: addPet + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + '405': + description: Invalid input + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + $ref: '#/components/requestBodies/Pet' + put: + tags: + - pet + summary: Update an existing pet + description: '' + operationId: updatePet + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid ID supplied + '404': + description: Pet not found + '405': + description: Validation exception + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + $ref: '#/components/requestBodies/Pet' + /pet/findByStatus: + get: + tags: + - pet + summary: Finds Pets by status + description: Multiple status values can be provided with comma separated strings + operationId: findPetsByStatus + parameters: + - name: status + in: query + description: Status values that need to be considered for filter + required: true + style: form + explode: false + deprecated: true + schema: + type: array + items: + type: string + enum: + - available + - pending + - sold + default: available + responses: + '200': + description: successful operation + content: + application/xml: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid status value + security: + - petstore_auth: + - 'read:pets' + /pet/findByTags: + get: + tags: + - pet + summary: Finds Pets by tags + description: >- + Multiple tags can be provided with comma separated strings. Use tag1, + tag2, tag3 for testing. + operationId: findPetsByTags + parameters: + - name: tags + in: query + description: Tags to filter by + required: true + style: form + explode: false + schema: + type: array + items: + type: string + responses: + '200': + description: successful operation + content: + application/xml: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid tag value + security: + - petstore_auth: + - 'read:pets' + deprecated: true + '/pet/{petId}': + get: + tags: + - pet + summary: Find pet by ID + description: Returns a single pet + operationId: getPetById + parameters: + - name: petId + in: path + description: ID of pet to return + required: true + schema: + type: integer + format: int64 + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid ID supplied + '404': + description: Pet not found + security: + - api_key: [] + post: + tags: + - pet + summary: Updates a pet in the store with form data + description: '' + operationId: updatePetWithForm + parameters: + - name: petId + in: path + description: ID of pet that needs to be updated + required: true + schema: + type: integer + format: int64 + responses: + '405': + description: Invalid input + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + content: + application/x-www-form-urlencoded: + schema: + type: object + properties: + name: + description: Updated name of the pet + type: string + status: + description: Updated status of the pet + type: string + delete: + tags: + - pet + summary: Deletes a pet + description: '' + operationId: deletePet + parameters: + - name: api_key + in: header + required: false + schema: + type: string + - name: petId + in: path + description: Pet id to delete + required: true + schema: + type: integer + format: int64 + responses: + '400': + description: Invalid pet value + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + '/pet/{petId}/uploadImage': + post: + tags: + - pet + summary: uploads an image + description: '' + operationId: uploadFile + parameters: + - name: petId + in: path + description: ID of pet to update + required: true + schema: + type: integer + format: int64 + responses: + '200': + description: successful operation + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponse' + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + content: + multipart/form-data: + schema: + type: object + properties: + additionalMetadata: + description: Additional data to pass to server + type: string + file: + description: file to upload + type: string + format: binary + /store/inventory: + get: + tags: + - store + summary: Returns pet inventories by status + description: Returns a map of status codes to quantities + operationId: getInventory + responses: + '200': + description: successful operation + content: + application/json: + schema: + type: object + additionalProperties: + type: integer + format: int32 + security: + - api_key: [] + /store/order: + post: + tags: + - store + summary: Place an order for a pet + description: '' + operationId: placeOrder + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Order' + application/json: + schema: + $ref: '#/components/schemas/Order' + '400': + description: Invalid Order + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Order' + description: order placed for purchasing the pet + required: true + '/store/order/{orderId}': + get: + tags: + - store + summary: Find purchase order by ID + description: >- + For valid response try integer IDs with value <= 5 or > 10. Other values + will generated exceptions + operationId: getOrderById + parameters: + - name: orderId + in: path + description: ID of pet that needs to be fetched + required: true + schema: + type: integer + format: int64 + minimum: 1 + maximum: 5 + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Order' + application/json: + schema: + $ref: '#/components/schemas/Order' + '400': + description: Invalid ID supplied + '404': + description: Order not found + delete: + tags: + - store + summary: Delete purchase order by ID + description: >- + For valid response try integer IDs with value < 1000. Anything above + 1000 or nonintegers will generate API errors + operationId: deleteOrder + parameters: + - name: orderId + in: path + description: ID of the order that needs to be deleted + required: true + schema: + type: string + responses: + '400': + description: Invalid ID supplied + '404': + description: Order not found + /user: + post: + tags: + - user + summary: Create user + description: This can only be done by the logged in user. + operationId: createUser + responses: + default: + description: successful operation + security: + - api_key: [] + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/User' + description: Created user object + required: true + /user/createWithArray: + post: + tags: + - user + summary: Creates list of users with given input array + description: '' + operationId: createUsersWithArrayInput + responses: + default: + description: successful operation + security: + - api_key: [] + requestBody: + $ref: '#/components/requestBodies/UserArray' + /user/createWithList: + post: + tags: + - user + summary: Creates list of users with given input array + description: '' + operationId: createUsersWithListInput + responses: + default: + description: successful operation + security: + - api_key: [] + requestBody: + $ref: '#/components/requestBodies/UserArray' + /user/login: + get: + tags: + - user + summary: Logs user into the system + description: '' + operationId: loginUser + parameters: + - name: username + in: query + description: The user name for login + required: true + schema: + type: string + pattern: '^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$' + - name: password + in: query + description: The password for login in clear text + required: true + schema: + type: string + responses: + '200': + description: successful operation + headers: + Set-Cookie: + description: >- + Cookie authentication key for use with the `api_key` + apiKey authentication. + schema: + type: string + example: AUTH_KEY=abcde12345; Path=/; HttpOnly + X-Rate-Limit: + description: calls per hour allowed by the user + schema: + type: integer + format: int32 + X-Expires-After: + description: date in UTC when token expires + schema: + type: string + format: date-time + content: + application/xml: + schema: + type: string + application/json: + schema: + type: string + '400': + description: Invalid username/password supplied + /user/logout: + get: + tags: + - user + summary: Logs out current logged in user session + description: '' + operationId: logoutUser + responses: + default: + description: successful operation + security: + - api_key: [] + '/user/{username}': + get: + tags: + - user + summary: Get user by user name + description: '' + operationId: getUserByName + parameters: + - name: username + in: path + description: The name that needs to be fetched. Use user1 for testing. + required: true + schema: + type: string + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/User' + application/json: + schema: + $ref: '#/components/schemas/User' + '400': + description: Invalid username supplied + '404': + description: User not found + put: + tags: + - user + summary: Updated user + description: This can only be done by the logged in user. + operationId: updateUser + parameters: + - name: username + in: path + description: name that need to be deleted + required: true + schema: + type: string + responses: + '400': + description: Invalid user supplied + '404': + description: User not found + security: + - api_key: [] + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/User' + description: Updated user object + required: true + delete: + tags: + - user + summary: Delete user + description: This can only be done by the logged in user. + operationId: deleteUser + parameters: + - name: username + in: path + description: The name that needs to be deleted + required: true + schema: + type: string + responses: + '400': + description: Invalid username supplied + '404': + description: User not found + security: + - api_key: [] +externalDocs: + description: Find out more about Swagger + url: 'http://swagger.io' +components: + requestBodies: + UserArray: + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/User' + description: List of user object + required: true + Pet: + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + application/xml: + schema: + $ref: '#/components/schemas/Pet' + description: Pet object that needs to be added to the store + required: true + securitySchemes: + petstore_auth: + type: oauth2 + flows: + implicit: + authorizationUrl: 'http://petstore.swagger.io/api/oauth/dialog' + scopes: + 'write:pets': modify pets in your account + 'read:pets': read your pets + api_key: + type: apiKey + name: api_key + in: header + schemas: + Order: + title: Pet Order + description: An order for a pets from the pet store + type: object + properties: + id: + type: integer + format: int64 + petId: + type: integer + format: int64 + quantity: + type: integer + format: int32 + shipDate: + type: string + format: date-time + status: + type: string + description: Order Status + enum: + - placed + - approved + - delivered + complete: + type: boolean + default: false + xml: + name: Order + Category: + title: Pet category + description: A category for a pet + type: object + properties: + id: + type: integer + format: int64 + name: + type: string + pattern: '^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$' + xml: + name: Category + User: + title: a User + description: A User who is purchasing from the pet store + type: object + properties: + id: + type: integer + format: int64 + username: + type: string + firstName: + type: string + lastName: + type: string + email: + type: string + password: + type: string + phone: + type: string + userStatus: + type: integer + format: int32 + description: User Status + xml: + name: User + Tag: + title: Pet Tag + description: A tag for a pet + type: object + properties: + id: + type: integer + format: int64 + name: + type: string + xml: + name: Tag + Pet: + title: a Pet + description: A pet for sale in the pet store + type: object + required: + - name + - photoUrls + properties: + id: + type: integer + format: int64 + category: + $ref: '#/components/schemas/Category' + name: + type: string + example: doggie + photoUrls: + type: array + xml: + name: photoUrl + wrapped: true + items: + type: string + tags: + type: array + xml: + name: tag + wrapped: true + items: + $ref: '#/components/schemas/Tag' + status: + type: string + description: pet status in the store + deprecated: true + enum: + - available + - pending + - sold + xml: + name: Pet + ApiResponse: + title: An uploaded response + description: Describes the result of uploading an image resource + type: object + properties: + code: + type: integer + format: int32 + type: + type: string + message: + type: string