├── .editorconfig ├── .gitignore ├── .travis.yml ├── LICENSE.txt ├── README.adoc ├── RELEASENOTES.adoc ├── build.gradle ├── gradle ├── publishing.gradle ├── security.gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src ├── main └── java │ └── io │ └── github │ └── robwin │ └── swagger │ └── test │ ├── AbstractContractValidator.java │ ├── ConsumerDrivenValidator.java │ ├── ContractValidator.java │ ├── DocumentationDrivenValidator.java │ ├── PropertyValidator.java │ ├── SchemaObjectResolver.java │ ├── SwaggerAssert.java │ ├── SwaggerAssertionConfig.java │ ├── SwaggerAssertionType.java │ └── SwaggerAssertions.java └── test ├── java └── io │ └── github │ └── robwin │ └── swagger │ ├── SwaggerConsumerDrivenAssertTest.java │ ├── SwaggerDocumentationDrivenAssertTest.java │ └── test │ └── AbstractContractValidatorTest.java └── resources ├── assertj-swagger-allOf.properties ├── assertj-swagger-info.properties ├── assertj-swagger-partial-impl.properties ├── assertj-swagger-path-prefix.properties ├── designed-swagger-with-less-response-defined.yaml ├── partial_impl_swagger.json ├── swagger-added-optional-parameter.json ├── swagger-added-required-parameter.json ├── swagger-allOf-composition-flat.json ├── swagger-allOf-composition.json ├── swagger-allOf-test-flat.json ├── swagger-allOf-test-inheritance-cycles.json ├── swagger-allOf-test-inheritance.json ├── swagger-bytearray-ref-wrong.json ├── swagger-bytearray-ref.json ├── swagger-bytearray-ref.yaml ├── swagger-bytearray-wrong.json ├── swagger-bytearray.json ├── swagger-bytearray.yaml ├── swagger-different-parameter-description.json ├── swagger-enum-ref-wrong.json ├── swagger-enum-ref.json ├── swagger-enum-ref.yaml ├── swagger-enum-wrong.json ├── swagger-enum.json ├── swagger-enum.yaml ├── swagger-extraresource.json ├── swagger-missing-required-field-object.json ├── swagger-name-changes.json ├── swagger-no-definitions.json ├── swagger-path-without-some-operations.json ├── swagger-pets-by-petId-without-get-and-post.json ├── swagger-requiredness-changes.json ├── swagger-singleresource-extramethod.json ├── swagger-singleresource-extraproperty.json ├── swagger-singleresource-partialmodel.json ├── swagger-singleresource.json ├── swagger-with-multi-types-parameters.json ├── swagger-with-path-prefixes-and-root-basepath.json ├── swagger.json ├── swagger.yaml ├── swagger_with_path_prefixes.json └── wrong_swagger.json /.editorconfig: -------------------------------------------------------------------------------- 1 | # This file is for unifying the coding style for different editors and IDEs 2 | # editorconfig.org 3 | 4 | root = true 5 | 6 | [*] 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | indent_style = space 12 | indent_size = 4 13 | max_line_length = 160 14 | 15 | [*.html] 16 | max_line_length = off 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | *.iml 3 | .gradle 4 | build 5 | out 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | dist: trusty 2 | language: java 3 | jdk: 4 | - oraclejdk8 5 | before_install: 6 | - chmod +x gradlew 7 | after_success: 8 | - ./gradlew jacocoTestReport coveralls 9 | - ./gradlew artifactoryPublish -PbintrayUsername="${BINTRAY_USER}" -PbintrayApiKey="${BINTRAY_KEY}" 10 | env: 11 | global: 12 | - secure: L++Z5NPJwlkOSipGFpDAilTx8rkiCBS16/nW2wI0QBO4tN0P2uz/k2CksgPxfUWDYPBX7Tq33fnE+D6AGzGbt+aY157TasAPOQorrvO+JhxT1O8Sg3PNx035fJLqXJ/6vaxln5Gg+o3gapRZeGr+QAtHi7CH2XNbvzKpAaR3qTRdFwi1lD+FQuCJJEOGXOFs9UvHMyuIkeTW31hAYxUwhTbdr/KekpHx413Xhm6NqeqqsK1u1Ppcwgvc7bKagCrWW5InYj55VYliV1jGEXqCZVQ7tFwcNhXGg6bFD0JQ0St7L8OOwdxzbxMSXKtmFU2rBKmfl4Ex6Qyjd7QIrA2cbhv9EX0e0c1vcXyCK2Cup1CDAc7FknXbr3xeEOjs6+F180VzhPbR32iTOw0Q3EiFHm9u5YXzsi/CxiZFj9JHxBzD6nyquADHbxD48oHbD/eZjx5zjR0pjakla/6gAv96dXuYPp7MZveslWNY6hobkcq/HnxgyNpR60IwcqLOk90LD2C4W7hS7mBrqsj9Rcc+im3F8Nxmfhmq30oMVHP5RLBGKvg8ADVF62SyN99zEVDRhoyDtn8c1SQxHmvAv1ZKKTz5vw8iVsdNKm6hkcFS/Dzf1Gqr/ZYnJC/5VpK44SmcoWjNQTHdHrvJb6rPfFDG8ECeNk6hrKxLvUfSx2+9xBY= 13 | - secure: BbuBcF8OETr195YQnhyJ2ISv3JzWGt0xpGtZHcbNVWXGvaPaRZfipNekrE67lsYkP4MrqHYs++ve9Ocx61NBc4/Gy2oxkRk6FPcp8qZ9YjyaByodvZ3RuSmGHuknbQJzYtEqRhfU00Q2ZDQWbhUnDOXm4hn5JTLZt3+bPyRNCygO95MnRK/yJOdC67Lltv4VhQLm8Oz71GmMmiA2t60eJeWcLaGXMssPCB89mGkukB1K0qMou4+u0qKJqwqmmlnUvE9rpFiWKUx3RHJoiMsnKWcMbKoamLg7wbhQC16oCRbp+G/RmjlgttJeXIB/dlu/6NFyrKgvfkJVV1cSmHUE4CUeC28Sn+WfAd4vNlbd/mL89aWCzBQUE9WxZHwoOBA4LKgO5nud+etw9fWfMVw7J3Ncr2pSZkW5G2OVSnHq46hAp3dbaDkksF9UkRJd1l1JSRBuAk6+Rlk7ghVMzFadtIFyeMd2om3g9BQDUL3e7dZRxQ5pp2FDZRpHBELKeyFgtZxCxemKAa3Lmo0J1xHQvjJ/nHEP7IxG5PGMbqnDc/7yWpjAMwY07o7zNIojkgnnTB9BITSSUSE2mcWDyBvlc2YifhDVqqfm0RgOlXHc4z2/gFwa6mZS18enAHDOyPg/koZDNd9PBVEvNz4dtMD9g3YSjgEYuNGQ5U27jtj8/vk= 14 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 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 | 203 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | = assertj-swagger 2 | :author: Robert Winkler 3 | :version: 0.9.0 4 | :hardbreaks: 5 | 6 | image:https://travis-ci.org/RobWin/assertj-swagger.svg["Build Status", link="https://travis-ci.org/RobWin/assertj-swagger"] image:https://coveralls.io/repos/RobWin/assertj-swagger/badge.svg?branch=master["Coverage Status", link="https://coveralls.io/r/RobWin/assertj-swagger"] image:https://api.bintray.com/packages/robwin/maven/assertj-swagger/images/download.svg[link="https://bintray.com/robwin/maven/assertj-swagger/_latestVersion"] image:http://img.shields.io/badge/license-ASF2-blue.svg["Apache License 2", link="http://www.apache.org/licenses/LICENSE-2.0.txt"] image:https://img.shields.io/badge/Twitter-rbrtwnklr-blue.svg["Twitter", link="https://twitter.com/rbrtwnklr"] 7 | 8 | == Overview 9 | 10 | assertj-swagger is a https://github.com/joel-costigliola/assertj-core[assertj] library which compares a contract-first https://github.com/swagger-api/swagger-spec[Swagger] YAML/JSON file with a code-first Swagger JSON output (e.g. from https://github.com/springfox/springfox[springfox] or https://github.com/swagger-api/swagger-core/wiki/Java-JAXRS-Quickstart[JAX-RS Swagger]). assertj-swagger allows to validate that the API implementation is in compliance with a contract specification for two test patterns: Documentation Driven Contracts and Consumer Driven Contracts. 11 | 12 | The Documentation Driven Contracts test pattern, useful for public APIs, validates using `#isEqualTo` and will validate that the design first documentation contract matches the implementation in its entirety. 13 | 14 | The Consumer Driven Contracts test pattern, useful for internal microservice APIs, validates using `#satisfiesContract` and will validate that the implementation provides, at minimum, the requirements of the design first consumer contract. This pattern allows for extension points in the API resources, resource methods, and models. 15 | 16 | The library supports the Swagger v2.0 specification. assertj-swagger compares Swagger objects like Paths, Parameters and Definitions. It does not compare __unimportant__ Swagger objects like info, descriptions or summaries. 17 | 18 | == Usage guide 19 | 20 | === Adding assertj-swagger to your project 21 | The project is published in JCenter and Maven Central. 22 | 23 | ==== Maven 24 | 25 | [source,xml, subs="specialcharacters,attributes"] 26 | ---- 27 | 28 | 29 | 30 | false 31 | 32 | central 33 | bintray 34 | http://jcenter.bintray.com 35 | 36 | 37 | 38 | 39 | io.github.robwin 40 | assertj-swagger 41 | {version} 42 | 43 | ---- 44 | 45 | ==== Gradle 46 | 47 | [source,groovy, subs="attributes"] 48 | ---- 49 | repositories { 50 | jcenter() 51 | } 52 | 53 | compile "io.github.robwin:assertj-swagger:{version}" 54 | ---- 55 | 56 | === Using assertj-swagger in an integration test 57 | 58 | Using assertj-swagger is simple. For example, if you are using https://github.com/spring-projects/spring-boot[Spring Boot] and https://github.com/springfox/springfox[springfox] or https://github.com/swagger-api/swagger-core/wiki/Java-JAXRS-Quickstart[JAX-RS Swagger], you can validate your Swagger JSON in an integration test. 59 | 60 | The following code sample shows how to validate an API using the Documentation Driven Contract test pattern: 61 | 62 | [source, java] 63 | ---- 64 | @RunWith(SpringJUnit4ClassRunner.class) 65 | @SpringApplicationConfiguration(classes = Application.class) 66 | @IntegrationTest 67 | @WebAppConfiguration 68 | public class AssertjSwaggerDocumentationDrivenTest { 69 | @Test 70 | public void validateThatImplementationMatchesDocumentationSpecification(){ 71 | String designFirstSwagger = SwaggerAssertTest.class.getResource("/swagger.yaml").getPath(); 72 | SwaggerAssertions.assertThat("http://localhost:8080/v2/api-docs") 73 | .isEqualTo(designFirstSwagger); 74 | } 75 | } 76 | ---- 77 | 78 | The following code sample shows how to validate an API using the Consumer Driven Contract test pattern: 79 | 80 | [source, java] 81 | ---- 82 | @RunWith(SpringJUnit4ClassRunner.class) 83 | @SpringApplicationConfiguration(classes = Application.class) 84 | @IntegrationTest 85 | @WebAppConfiguration 86 | public class AssertjSwaggerConsumerDrivenTest { 87 | @Test 88 | public void validateThatImplementationSatisfiesConsumerSpecification(){ 89 | String designFirstSwagger = SwaggerAssertTest.class.getResource("/swagger-consumer1.yaml").getPath(); 90 | SwaggerAssertions.assertThat("http://localhost:8080/v2/api-docs") 91 | .satisfiesContract(designFirstSwagger); 92 | } 93 | } 94 | ---- 95 | 96 | ==== Example output 97 | 98 | For Documentation Driven Contract tests, Assertj-swagger fails a test if it finds differences between the implementation and the specification. 99 | 100 | [source] 101 | ---- 102 | The following 4 assertions failed: 103 | 1) [Checking Paths] 104 | Expecting: 105 | <["/api/pet", "/api/pet/findByStatus", "/api/pet/findByTags", "/api/pet/{petId}", "/api/store/order", "/api/store/order/{orderId}", "/api/user", "/api/user/createWithArray", "/api/user/createWithList", "/api/user/login", "/api/user/logout", "/api/user/{username}"]> 106 | to contain only: 107 | <["/pets", "/pets/findByStatus", "/pets/findByTags", "/pets/{petId}", "/stores/order", "/stores/order/{orderId}", "/users", "/users/createWithArray", "/users/createWithList", "/users/login", "/users/logout", "/users/{username}"]> 108 | elements not found: 109 | <["/pets/findByTags", "/users/logout", "/users", "/stores/order", "/users/createWithArray", "/pets", "/users/createWithList", "/pets/findByStatus", "/pets/{petId}", "/users/{username}", "/stores/order/{orderId}", "/users/login"]> 110 | and elements not expected: 111 | <["/api/store/order", "/api/user", "/api/user/createWithList", "/api/pet", "/api/pet/findByTags", "/api/user/createWithArray", "/api/user/login", "/api/pet/{petId}", "/api/store/order/{orderId}", "/api/user/{username}", "/api/pet/findByStatus", "/api/user/logout"]> 112 | 113 | 2) [Checking properties of definition 'Order'] 114 | Expecting: 115 | <["complete", "id", "identifier", "petId", "quantity", "shipDate", "status"]> 116 | to contain only: 117 | <["id", "petId", "quantity", "shipDate", "status", "complete"]> 118 | elements not found: 119 | <[]> 120 | and elements not expected: 121 | <["identifier"]> 122 | 123 | 3) [Checking properties of definition 'User'] 124 | Expecting: 125 | <["email", "firstName", "id", "identifier", "lastName", "password", "phone", "userStatus", "username"]> 126 | to contain only: 127 | <["id", "username", "firstName", "lastName", "email", "password", "phone", "userStatus"]> 128 | elements not found: 129 | <[]> 130 | and elements not expected: 131 | <["identifier"]> 132 | 133 | 4) [Checking properties of definition 'Pet'] 134 | Expecting: 135 | <["category", "id", "identifier", "name", "photoUrls", "status", "tags"]> 136 | to contain only: 137 | <["id", "category", "name", "photoUrls", "tags", "status"]> 138 | elements not found: 139 | <[]> 140 | and elements not expected: 141 | <["identifier"]> 142 | ---- 143 | 144 | For Consumer Driven Contract tests, Assertj-swagger fails a test if it finds missing resources, methods, models, or properties in the implementation which are required by the consumer specification. 145 | 146 | [source] 147 | ---- 148 | The following 4 assertions failed: 149 | 1) [Checking Paths] 150 | Expecting: 151 | <["/pets", "/pets/findByStatus", "/pets/findByTags", "/pets/{petId}", "/stores/order", "/stores/order/{orderId}", "/users", "/users/createWithArray", "/users/createWithList", "/users/login", "/users/logout", "/users/{username}"]> 152 | to contain: 153 | <["/animals/{animalId}", "/pets", "/pets/findByStatus", "/pets/{petId}"]> 154 | but could not find: 155 | <["/animals/{animalId}"]> 156 | 157 | 2) [Checking Definitions] 158 | Expecting: 159 | <["User", "Category", "Pet", "Tag", "Order"]> 160 | to contain: 161 | <["Category", "Pet", "Animal", "Tag"]> 162 | but could not find: 163 | <["Animal"]> 164 | 165 | 3) [Checking properties of definition 'Pet'] 166 | Expecting: 167 | <["id", "category", "name", "photoUrls", "tags", "status"]> 168 | to contain: 169 | <["photoUrls", "extraProperty", "name", "id", "category", "tags", "status"]> 170 | but could not find: 171 | <["extraProperty"]> 172 | 173 | 4) [Checking property 'extraProperty' of definition 'Pet'] 174 | Expecting actual not to be null 175 | ---- 176 | 177 | === Using assertj-swagger in a unit test 178 | 179 | If you are using the https://github.com/spring-projects/spring-framework[spring-framework] and https://github.com/springfox/springfox[springfox], Spring's MVC Test framework can also be used to validate the Swagger JSON output against your contract-first Swagger specification. 180 | That way you can make sure that the implementation is in compliance with the design specification. 181 | 182 | The following code sample shows how to write a unit test using the Documentation Driven Contract test pattern: 183 | 184 | [source, java] 185 | ---- 186 | @Test 187 | public void validateThatImplementationFitsDesignSpecification() throws Exception { 188 | String designFirstDocumentationSwaggerLocation = Swagger2MarkupTest.class.getResource("/swagger.yaml").getPath(); 189 | 190 | MvcResult mvcResult = this.mockMvc.perform(get("/v2/api-docs") 191 | .accept(MediaType.APPLICATION_JSON)) 192 | .andExpect(status().isOk()) 193 | .andReturn(); 194 | 195 | String springfoxSwaggerJson = mvcResult.getResponse().getContentAsString(); 196 | SwaggerAssertions.assertThat(new SwaggerParser().parse(springfoxSwaggerJson)).isEqualTo(designFirstDocumentationSwaggerLocation); 197 | } 198 | ---- 199 | 200 | The following code sample shows how to write a unit test using the Consumer Driven Contract test pattern: 201 | 202 | [source, java] 203 | ---- 204 | @Test 205 | public void validateThatImplementationFitsDesignSpecification() throws Exception { 206 | String designFirstConsumerSwaggerLocation = Swagger2MarkupTest.class.getResource("/swagger-consumer1.yaml").getPath(); 207 | 208 | MvcResult mvcResult = this.mockMvc.perform(get("/v2/api-docs") 209 | .accept(MediaType.APPLICATION_JSON)) 210 | .andExpect(status().isOk()) 211 | .andReturn(); 212 | 213 | String springfoxSwaggerJson = mvcResult.getResponse().getContentAsString(); 214 | SwaggerAssertions.assertThat(new SwaggerParser().parse(springfoxSwaggerJson)).satisfiesContract(designFirstConsumerSwaggerLocation); 215 | } 216 | ---- 217 | 218 | === Customizing assertj-swagger's behaviour 219 | 220 | For most use cases, the default behaviour will be sufficient. However, you can override the default behaviour in various ways by placing a Java property file, `/assertj-swagger.properties`, at the root of your classpath. It is also possible to override the configuration in your tests; construct an instance of the `SwaggerAssert` class with a custom configuration if this is required. 221 | 222 | The following overrides are available: 223 | 224 | ==== Disable various types of checks which are enabled by default 225 | 226 | * `assertj.swagger.validateDefinitions=false`: disable all validation of definitions 227 | ** `assertj.swagger.validateProperties=false`: disable validation of properties of definitions 228 | *** `assertj.swagger.validateRefProperties=false`: disable validation of reference (`$ref`) properties of definitions 229 | *** `assertj.swagger.validateArrayProperties=false`: disable validation of array properties of definitions 230 | *** `assertj.swagger.validateByteArrayProperties=false`: disable validation of byte-array properties of definitions 231 | *** `assertj.swagger.validateStringProperties=false`: disable validation of string properties of definitions 232 | ** `assertj.swagger.validateModels=false`: disable validation of models 233 | * `assertj.swagger.validatePaths=false`: disable all validation of endpoint definitions 234 | * `assertj.swagger.validateResponseWithStrictlyMatch=false`: allow actual contract return extra return code 235 | 236 | ==== Enable various types of checks which are disabled by default 237 | 238 | The following settings are disabled by default, as they will cause schema comparisions to be too brittle for many users. They can be enabled if required. 239 | 240 | * `assertj.swagger.validateInfo=true`: enable comparison of the info section 241 | * `assertj.swagger.validateVersion=true`: enable comparison of the schema version numbers 242 | 243 | ==== Disable checks for certain paths or definitions in 'actual' schema 244 | 245 | This feature is useful in development situations, where you have written a contract-first schema by hand, and are validating a contract-last schema generated by a partially-implemented API. 246 | 247 | To ignore unimplemented endpoints, try something like: 248 | 249 | [source] 250 | ---- 251 | assertj.swagger.pathsToIgnoreInExpected=\ 252 | /v1/friends/{id},\ 253 | /v1/groups/{groupId} 254 | ---- 255 | 256 | To ignore unimplemented definitions, use something like: 257 | 258 | [source] 259 | ---- 260 | assertj.swagger.definitionsToIgnoreInExpected=\ 261 | Foo,\ 262 | Bar 263 | ---- 264 | 265 | To ignore unimplemented properties, use something like: 266 | 267 | [source] 268 | ---- 269 | assertj.swagger.propertiesToIgnoreInExpected=\ 270 | Foo.prop1,\ 271 | Bar.prop2 272 | ---- 273 | 274 | 275 | ==== Comparing expected and actual paths in schemas 276 | 277 | It is occasionally useful to be able to compare schemas, where due to limitations in tools and libraries, endpoint 278 | paths don't align. Specifying a `basePath` setting in your design-first schema here won't work -- it's only used by 279 | Swagger tooling to generate paths at runtime, and does *not* form part of the logical pathname of your endpoints. 280 | For instance, in your design-first schema, you may specify a set of endpoints and a `basePath`, while your generated 281 | schema (generated from, say, Springfox) has a common prefix prepended on the endpoint paths; e.g.: 282 | 283 | [source] 284 | ---- 285 | /pets/findByStatus ! design-first schema 286 | ---- 287 | 288 | and 289 | 290 | [source] 291 | ---- 292 | /v2/pets/findByStatus ! actual schema 293 | ---- 294 | 295 | To ensure that assertj-swagger is comparing like-with-like in this situation, you could use the following in your 296 | configuration file: 297 | 298 | [source] 299 | ---- 300 | assertj.swagger.pathsPrependExpected=/v2 301 | ---- 302 | 303 | 304 | == License 305 | 306 | Copyright 2015 Robert Winkler 307 | 308 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 309 | 310 | http://www.apache.org/licenses/LICENSE-2.0 311 | 312 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 313 | -------------------------------------------------------------------------------- /RELEASENOTES.adoc: -------------------------------------------------------------------------------- 1 | = Release Notes 2 | 3 | == Version 0.1.0 4 | * Initial version 5 | 6 | === Version 0.1.1 7 | * Added a Swagger 2.0 parser which parses a Swagger String into a Swagger model 8 | 9 | === Version 0.1.2 10 | * Updated swagger-parser from v1.0.6 to v1.0.8 11 | 12 | === Version 0.1.3 13 | * Updated swagger-parser from v1.0.8 to v1.0.16 14 | 15 | == Version 0.2.0 16 | * Updated swagger-parser from v1.0.16 to v1.0.17 17 | * PR #3: Added functionality to customize assertj-swagger's behaviour 18 | 19 | == Version 0.3.0 20 | * PR #6: Implemented configuration setting: 'pathsPrependExpected'; info and version comparison 21 | 22 | == Version 0.4.0 23 | * PR #7: Refactored to separate documentation driven from consumer driven 24 | 25 | == Version 0.5.0 26 | * PR #8: Make assertj-swagger "allOf"-aware 27 | 28 | == Version 0.6.0 29 | * PR #17: assertj > 2.4 breaks SoftAssertions 30 | 31 | == Version 0.7.0 32 | * Updated swagger-parser from v1.0.32 to v1.0.34 33 | * Updated assertj-core from v3.8.0 to v3.9.0 34 | * Fixed Issues: #24, #30, #28 and #26 35 | 36 | == Version 0.8.0 37 | * PR #35: Added new isEqualTo with auth for secured endpoints 38 | * PR #36: Added missing validation message for property types 39 | * PR #37: Added basePath to paths if no path prefix is configured 40 | 41 | === Version 0.8.1 42 | * PR #42: Updated assertJ to v3.9.1 43 | * PR #43: Fixed problem with validation of enum values 44 | * PR #44: Enabled configuration for loosely match responses 45 | * PR #45: Enhanced definition validation 46 | * PR #46: Avoid NPE if Definition does not contain properties 47 | * PR #47: Schema resolver avoid NPE 48 | * PR #48: Check definition instance before validating required properties 49 | * PR #49: Added validation for enums 50 | 51 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | mavenCentral() 5 | } 6 | dependencies { 7 | classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.0.1' 8 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' 9 | classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.4.18" 10 | classpath 'org.owasp:dependency-check-gradle:6.0.4' 11 | } 12 | } 13 | description = 'A Swagger assertion library' 14 | version = '0.8.1' 15 | group = 'io.github.robwin' 16 | 17 | apply plugin: 'java' 18 | apply plugin: 'maven-publish' 19 | apply plugin: 'jacoco' 20 | apply plugin: 'com.github.kt3k.coveralls' 21 | apply plugin: 'com.jfrog.bintray' 22 | apply plugin: "com.jfrog.artifactory" 23 | apply from: 'gradle/publishing.gradle' 24 | apply from: 'gradle/security.gradle' 25 | 26 | tasks.withType(JavaCompile) { 27 | sourceCompatibility = "1.8" 28 | targetCompatibility = "1.8" 29 | options.deprecation = true 30 | options.encoding = 'UTF-8' 31 | options.compilerArgs << "-Xlint:unchecked" 32 | } 33 | 34 | repositories { 35 | jcenter() 36 | mavenCentral() 37 | mavenLocal() 38 | } 39 | 40 | dependencies { 41 | compile "io.swagger:swagger-compat-spec-parser:1.0.54" 42 | compile "io.swagger:swagger-core:1.6.2" 43 | compile "com.google.guava:guava:30.1-android" 44 | compile "org.apache.httpcomponents:httpclient:4.5.13" 45 | compile "commons-collections:commons-collections:3.2.2" 46 | compile "org.slf4j:slf4j-api:1.7.12" 47 | compile "org.assertj:assertj-core:3.18.1" 48 | testCompile "junit:junit:4.11" 49 | testCompile "ch.qos.logback:logback-classic:1.1.2" 50 | 51 | } 52 | 53 | task sourcesJar(type: Jar, dependsOn: classes) { 54 | classifier = 'sources' 55 | from sourceSets.main.allSource 56 | } 57 | 58 | task javadocJar(type: Jar, dependsOn: javadoc) { 59 | classifier = 'javadoc' 60 | from javadoc.destinationDir 61 | } 62 | 63 | artifacts { 64 | archives sourcesJar 65 | archives javadocJar 66 | } 67 | 68 | artifactory { 69 | contextUrl = 'https://oss.jfrog.org' 70 | resolve { 71 | repository { 72 | repoKey = 'libs-release' 73 | } 74 | } 75 | publish { 76 | repository { 77 | repoKey = 'oss-snapshot-local' //The Artifactory repository key to publish to 78 | //when using oss.jfrog.org the credentials are from Bintray. For local build we expect them to be found in 79 | //~/.gradle/gradle.properties, otherwise to be set in the build server 80 | username = project.hasProperty('bintrayUsername') ? project.bintrayUsername : System.getenv('BINTRAY_USER') 81 | password = project.hasProperty('bintrayApiKey') ? project.bintrayApiKey : System.getenv('BINTRAY_KEY') 82 | } 83 | defaults { 84 | publications('mavenJava') 85 | } 86 | } 87 | if (System.properties['https.proxyHost']) { 88 | clientConfig.proxy.host = System.properties['https.proxyHost'] 89 | clientConfig.proxy.port = System.properties['https.proxyPort'].toInteger() 90 | } 91 | 92 | } 93 | 94 | jacocoTestReport { 95 | reports { 96 | xml.enabled = true // coveralls plugin depends on xml format report 97 | html.enabled = true 98 | } 99 | } 100 | 101 | tasks.coveralls { 102 | dependsOn 'check' 103 | } 104 | 105 | task wrapper(type: Wrapper) { 106 | gradleVersion = '3.5' 107 | } 108 | -------------------------------------------------------------------------------- /gradle/publishing.gradle: -------------------------------------------------------------------------------- 1 | import java.text.SimpleDateFormat 2 | 3 | Date buildTimeAndDate = new Date() 4 | ext { 5 | buildDate = new SimpleDateFormat('yyyy-MM-dd').format(buildTimeAndDate) 6 | buildTime = new SimpleDateFormat('HH:mm:ss.SSSZ').format(buildTimeAndDate) 7 | } 8 | 9 | def projectArtifactId = 'assertj-swagger' 10 | 11 | jar { 12 | manifest { 13 | attributes( 14 | 'Built-By': 'Robert Winkler', 15 | 'Created-By': System.properties['java.version'] + " (" + System.properties['java.vendor'] + " " + System.properties['java.vm.version'] + ")", 16 | 'Build-Date': project.buildDate, 17 | 'Build-Time': project.buildTime, 18 | 'Specification-Title': projectArtifactId, 19 | 'Specification-Version': project.version, 20 | 'Implementation-Title': projectArtifactId, 21 | 'Implementation-Version': project.version 22 | ) 23 | } 24 | } 25 | 26 | if (!project.hasProperty('bintrayUsername')) ext.bintrayUsername = '' 27 | if (!project.hasProperty('bintrayApiKey')) ext.bintrayApiKey = '' 28 | if (!project.hasProperty('gpgPassphrase')) ext.gpgPassphrase = '' 29 | if (!project.hasProperty('ossUser')) ext.ossUser = '' 30 | if (!project.hasProperty('ossPassword')) ext.ossPassword = '' 31 | 32 | bintray { 33 | user = project.bintrayUsername 34 | key = project.bintrayApiKey 35 | dryRun = false //Whether to run this as dry-run, without deploying 36 | publish = true //If version should be auto published after an upload 37 | publications = ['mavenJava'] 38 | pkg { 39 | repo = 'maven' 40 | name = 'assertj-swagger' 41 | websiteUrl = 'https://github.com/RobWin/assertj-swagger' 42 | issueTrackerUrl = 'https://github.com/RobWin/assertj-swagger/issues' 43 | vcsUrl = 'https://github.com/RobWin/assertj-swagger.git' 44 | desc = 'A Swagger test library.' 45 | licenses = ['Apache-2.0'] 46 | version { 47 | vcsTag = project.version 48 | gpg { 49 | sign = true //Determines whether to GPG sign the files. The default is false 50 | passphrase = project.gpgPassphrase //Optional. The passphrase for GPG signing' 51 | } 52 | mavenCentralSync { 53 | sync = true //Optional (true by default). Determines whether to sync the version to Maven Central. 54 | user = ossUser //OSS user token 55 | password = ossPassword //OSS user password 56 | } 57 | } 58 | } 59 | } 60 | 61 | publishing { 62 | publications { 63 | mavenJava(MavenPublication) { 64 | from components.java 65 | pom.withXml { 66 | def devs = ['RobWin': 'Robert Winkler'] 67 | def root = asNode() 68 | 69 | root.dependencies.'*'.findAll() { 70 | it.scope.text() == 'runtime' && project.configurations.compile.allDependencies.find { dep -> 71 | dep.name == it.artifactId.text() 72 | } 73 | }.each() { 74 | it.scope*.value = 'compile' 75 | } 76 | 77 | root.appendNode('name', 'assertj-swagger') 78 | root.appendNode('packaging', 'jar') 79 | root.appendNode('url', 'https://github.com/RobWin/assertj-swagger') 80 | root.appendNode('description', 'A Swagger to Markup (AsciiDoc and Markdown) converter.') 81 | 82 | def license = root.appendNode('licenses').appendNode('license') 83 | license.appendNode('name', 'Apache-2.0') 84 | license.appendNode('url', 'https://github.com/RobWin/assertj-swagger/blob/master/LICENSE.txt') 85 | license.appendNode('distribution', 'repo') 86 | 87 | root.appendNode('scm').appendNode('url', 'https://github.com/RobWin/assertj-swagger.git') 88 | 89 | def developers = root.appendNode('developers') 90 | devs.each { 91 | def d = developers.appendNode('developer') 92 | d.appendNode('id', it.key) 93 | d.appendNode('name', it.value) 94 | } 95 | } 96 | artifact sourcesJar 97 | artifact javadocJar 98 | } 99 | } 100 | } -------------------------------------------------------------------------------- /gradle/security.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'org.owasp.dependencycheck' 2 | 3 | check.dependsOn dependencyCheckAnalyze 4 | 5 | dependencyCheck { 6 | cveValidForHours = 8 7 | failBuildOnCVSS = 5 8 | analyzers { 9 | nexusEnabled = false 10 | pyDistributionEnabled = false 11 | pyPackageEnabled = false 12 | rubygemsEnabled = false 13 | cmakeEnabled = false 14 | autoconfEnabled = false 15 | composerEnabled = false 16 | nodeEnabled = false 17 | nuspecEnabled = false 18 | assemblyEnabled = false 19 | } 20 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobWin/assertj-swagger/0fb25230bca68a9c603d7ff35cf20fb2c0ac5ed1/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Feb 05 12:51:21 CET 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save ( ) { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'assertj-swagger' 2 | 3 | -------------------------------------------------------------------------------- /src/main/java/io/github/robwin/swagger/test/AbstractContractValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2018 Robert Winkler 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * 18 | */ 19 | package io.github.robwin.swagger.test; 20 | 21 | import io.swagger.models.Path; 22 | import io.swagger.models.Swagger; 23 | import org.apache.commons.lang3.StringUtils; 24 | 25 | import java.util.Map; 26 | import java.util.stream.Collectors; 27 | 28 | /** 29 | * Offers functionality shared across concrete validator implementations. 30 | */ 31 | public abstract class AbstractContractValidator implements ContractValidator { 32 | 33 | /** 34 | * Finds the expected paths considering both {@code pathsPrependExpected} in the config and {@code basePath} in the Swagger model. The configured value 35 | * takes precedence regardless of whether it happens to be the same value as the base path or not. If no prefix is configured the Swagger base path is added 36 | * to each actual path. 37 | * 38 | * @param expected Swagger model 39 | * @param assertionConfig assertion configuration 40 | * @return expected paths 41 | */ 42 | protected Map findExpectedPaths(Swagger expected, SwaggerAssertionConfig assertionConfig) { 43 | String pathsPrependExpected = assertionConfig.getPathsPrependExpected(); 44 | String basePath = expected.getBasePath(); 45 | if (StringUtils.isBlank(pathsPrependExpected) && isBlankOrSlash(basePath)) { 46 | return expected.getPaths(); // no path prefix configured and no basePath set, nothing to do 47 | } 48 | 49 | String pathPrefix = null; 50 | if (StringUtils.isNotBlank(pathsPrependExpected)) { 51 | pathPrefix = pathsPrependExpected; 52 | } else if (!isBlankOrSlash(basePath)) { 53 | pathPrefix = basePath; 54 | } 55 | 56 | final String finalPathPrefix = pathPrefix; 57 | return finalPathPrefix == null ? 58 | expected.getPaths() : 59 | getPathsWithPrefix(expected, finalPathPrefix); 60 | } 61 | 62 | /** 63 | * Gets the paths from the actual Swagger model. Each path is prefixed with the base path configured in the model. 64 | * 65 | * @param actual Swagger model 66 | * @return paths including base path 67 | */ 68 | protected Map getPathsIncludingBasePath(Swagger actual) { 69 | String basePath = actual.getBasePath(); 70 | return isBlankOrSlash(basePath) ? 71 | actual.getPaths() : 72 | getPathsWithPrefix(actual, basePath); 73 | } 74 | 75 | private Map getPathsWithPrefix(Swagger swagger, String prefix) { 76 | return swagger.getPaths().entrySet().stream().collect(Collectors.toMap( 77 | e -> prefix + e.getKey(), 78 | e -> e.getValue())); 79 | } 80 | 81 | private boolean isBlankOrSlash(String basePath) { 82 | return StringUtils.isBlank(basePath) || basePath.equals("/"); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/io/github/robwin/swagger/test/ContractValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2018 Robert Winkler 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * 18 | */ 19 | package io.github.robwin.swagger.test; 20 | 21 | import io.swagger.models.Swagger; 22 | 23 | public interface ContractValidator { 24 | void validateSwagger(Swagger expected, SchemaObjectResolver schemaObjectResolver); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/io/github/robwin/swagger/test/PropertyValidator.java: -------------------------------------------------------------------------------- 1 | package io.github.robwin.swagger.test; 2 | 3 | import io.swagger.models.properties.ArrayProperty; 4 | import io.swagger.models.properties.ByteArrayProperty; 5 | import io.swagger.models.properties.Property; 6 | import io.swagger.models.properties.RefProperty; 7 | import io.swagger.models.properties.StringProperty; 8 | import java.util.List; 9 | import org.apache.commons.collections.CollectionUtils; 10 | import org.assertj.core.api.SoftAssertions; 11 | 12 | public class PropertyValidator { 13 | 14 | /** 15 | * Basic properties that impacts swagger contract. 16 | */ 17 | private static final String[] BASIC_PROPERTIES = {"type", "format", "allowEmptyValue", "name", "required", 18 | "readOnly", "access", "vendorExtensions"}; 19 | 20 | private SwaggerAssertionConfig assertionConfig; 21 | private SoftAssertions softAssertions; 22 | 23 | public PropertyValidator(SwaggerAssertionConfig assertionConfig, SoftAssertions softAssertions) { 24 | this.assertionConfig = assertionConfig; 25 | this.softAssertions = softAssertions; 26 | } 27 | 28 | void validateProperty(Property actualProperty, Property expectedProperty, String message) { 29 | if (expectedProperty == null || !isAssertionEnabled(SwaggerAssertionType.PROPERTIES)) { 30 | return; 31 | } 32 | 33 | // TODO Validate Property schema 34 | if (shouldValidateRefProperty(expectedProperty)) { 35 | validateBasicPropertyFeatures(actualProperty, expectedProperty, message); 36 | // TODO improve validation by verifying property based on RefProperty type 37 | } else if (shouldValidateArrayProperty(expectedProperty)) { 38 | validateBasicPropertyFeatures(actualProperty, expectedProperty, message); 39 | // TODO improve validation by verifying property based on ArrayProperty type 40 | } else if (shouldValidateByteArrayProperty(expectedProperty)) { 41 | validateBasicPropertyFeatures(actualProperty, expectedProperty, message); 42 | // TODO improve validation by verifying property based on ByteArrayProperty type 43 | } else if (shouldValidateStringProperty(expectedProperty)) { 44 | StringProperty expectedStringProperty = (StringProperty) expectedProperty; 45 | validateBasicPropertyFeatures(actualProperty, expectedProperty, message); 46 | if (isPropertyOfEnumType(actualProperty)) { 47 | StringProperty actualStringProperty = (StringProperty) actualProperty; 48 | validateEnumPropertyFeatures(actualStringProperty, expectedStringProperty); 49 | } 50 | } else { 51 | validateBasicPropertyFeatures(actualProperty, expectedProperty, message); 52 | } 53 | } 54 | 55 | private boolean shouldValidateRefProperty(Property expectedProperty) { 56 | return RefProperty.class.isAssignableFrom(expectedProperty.getClass()) && isAssertionEnabled( 57 | SwaggerAssertionType.REF_PROPERTIES); 58 | } 59 | 60 | private boolean shouldValidateArrayProperty(Property expectedProperty) { 61 | return ArrayProperty.class.isAssignableFrom(expectedProperty.getClass()) && isAssertionEnabled( 62 | SwaggerAssertionType.ARRAY_PROPERTIES); 63 | } 64 | 65 | private boolean shouldValidateByteArrayProperty(Property expectedProperty) { 66 | return ByteArrayProperty.class.isAssignableFrom(expectedProperty.getClass()) && isAssertionEnabled( 67 | SwaggerAssertionType.BYTE_ARRAY_PROPERTIES); 68 | } 69 | 70 | private boolean shouldValidateStringProperty(Property expectedProperty) { 71 | return StringProperty.class.isAssignableFrom(expectedProperty.getClass()) && isAssertionEnabled( 72 | SwaggerAssertionType.STRING_PROPERTIES); 73 | } 74 | 75 | private boolean isAssertionEnabled(final SwaggerAssertionType assertionType) { 76 | return assertionConfig.swaggerAssertionEnabled(assertionType); 77 | } 78 | 79 | private void validateBasicPropertyFeatures(Property actualProperty, Property expectedProperty, String message) { 80 | softAssertions.assertThat(actualProperty).as(message).isExactlyInstanceOf(expectedProperty.getClass()); 81 | softAssertions.assertThat(actualProperty).as(message) 82 | .isEqualToComparingOnlyGivenFields(expectedProperty, BASIC_PROPERTIES); 83 | } 84 | 85 | private boolean isPropertyOfEnumType(Property property) { 86 | return property != null && StringProperty.class.isAssignableFrom(property.getClass()) 87 | && CollectionUtils.isNotEmpty(((StringProperty) property).getEnum()); 88 | } 89 | 90 | private void validateEnumPropertyFeatures(StringProperty actualStringProperty, 91 | StringProperty expectedStringProperty) { 92 | List expectedEnums = expectedStringProperty.getEnum(); 93 | if (CollectionUtils.isNotEmpty(expectedEnums)) { 94 | softAssertions.assertThat(actualStringProperty.getEnum()).hasSameElementsAs(expectedEnums); 95 | } else { 96 | softAssertions.assertThat(actualStringProperty.getEnum()).isNullOrEmpty(); 97 | } 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/io/github/robwin/swagger/test/SchemaObjectResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2018 Robert Winkler 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * 18 | */ 19 | package io.github.robwin.swagger.test; 20 | 21 | import io.swagger.models.ComposedModel; 22 | import io.swagger.models.Model; 23 | import io.swagger.models.Operation; 24 | import io.swagger.models.RefModel; 25 | import io.swagger.models.Swagger; 26 | import io.swagger.models.properties.Property; 27 | 28 | import java.util.Collections; 29 | import java.util.HashMap; 30 | import java.util.HashSet; 31 | import java.util.List; 32 | import java.util.Map; 33 | import java.util.Set; 34 | 35 | 36 | /** 37 | * Provide a means to retrieve values from various objects in the schema. Provides a means of falling back to 'global' 38 | * settings if they're not defined locally in a definition or path object. Also permits resolving local 39 | * {@code $ref}-erences and types making use of {@code allOf}-style inheritance. 40 | */ 41 | class SchemaObjectResolver { 42 | 43 | private Swagger expected; 44 | private Swagger actual; 45 | 46 | SchemaObjectResolver(Swagger expected, Swagger actual) { 47 | this.expected = expected; 48 | this.actual = actual; 49 | } 50 | 51 | List getExpectedConsumes(Operation op) { 52 | return getListWithFallback(op.getConsumes(), expected.getConsumes()); 53 | } 54 | 55 | List getActualConsumes(Operation op) { 56 | return getListWithFallback(op.getConsumes(), actual.getConsumes()); 57 | } 58 | 59 | List getExpectedProduces(Operation op) { 60 | return getListWithFallback(op.getProduces(), expected.getProduces()); 61 | } 62 | 63 | List getActualProduces(Operation op) { 64 | return getListWithFallback(op.getProduces(), actual.getProduces()); 65 | } 66 | 67 | Map resolvePropertiesFromExpected(Model definition) { 68 | return resolveProperties(definition, expected, new HashSet()); 69 | } 70 | 71 | Map resolvePropertiesFromActual(Model definition) { 72 | return resolveProperties(definition, actual, new HashSet()); 73 | } 74 | 75 | private Map resolveProperties(Model definition, Swagger owningSchema, Set seenRefs) { 76 | Map result; 77 | 78 | // if the definition does not contain any property, then the model will return null instead of an empty map 79 | final Map definitionProperties = definition.getProperties() != null ? definition.getProperties() : Collections.emptyMap(); 80 | 81 | if (definition instanceof RefModel) { 82 | // Don't navigate ref-def cycles infinitely 83 | final RefModel refDef = (RefModel) definition; 84 | 85 | if (seenRefs.contains(refDef.getSimpleRef())) { 86 | return Collections.emptyMap(); 87 | } else { 88 | seenRefs.add(refDef.getSimpleRef()); 89 | } 90 | result = resolveProperties(findDefinition(owningSchema.getDefinitions(), refDef), owningSchema, seenRefs); 91 | } else if (definition instanceof ComposedModel) { 92 | Map allProperties = new HashMap<>(); 93 | if (definitionProperties != null) { 94 | allProperties.putAll(definitionProperties); 95 | } 96 | for (final Model childDefinition : ((ComposedModel) definition).getAllOf()) { 97 | allProperties.putAll(resolveProperties(childDefinition, owningSchema, seenRefs)); 98 | } 99 | result = allProperties; 100 | } else { 101 | result = definitionProperties; 102 | } 103 | 104 | return result; 105 | } 106 | 107 | private Model findDefinition(Map defs, RefModel refModel) { 108 | return defs.get(refModel.getSimpleRef()); 109 | } 110 | 111 | private List getListWithFallback(List localDefn, List globalDefn) { 112 | final List result; 113 | if (localDefn != null && !localDefn.isEmpty()) { 114 | result = localDefn; 115 | } else if (globalDefn != null) { 116 | result = globalDefn; 117 | } else { 118 | result = Collections.emptyList(); 119 | } 120 | return result; 121 | } 122 | 123 | } 124 | 125 | -------------------------------------------------------------------------------- /src/main/java/io/github/robwin/swagger/test/SwaggerAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2018 Robert Winkler 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * 18 | */ 19 | package io.github.robwin.swagger.test; 20 | 21 | import io.swagger.models.Swagger; 22 | import io.swagger.models.auth.AuthorizationValue; 23 | import io.swagger.parser.SwaggerParser; 24 | import org.assertj.core.api.AbstractAssert; 25 | 26 | import java.io.IOException; 27 | import java.io.InputStream; 28 | import java.util.List; 29 | import java.util.Properties; 30 | 31 | 32 | /** 33 | * Assertion methods for {@code Swagger}. 34 | *

35 | * To create a new instance of this class, invoke {@link io.github.robwin.swagger.test.SwaggerAssertions#assertThat(Swagger)}. 36 | *

37 | * 38 | * @author Robert Winkler 39 | */ 40 | 41 | public class SwaggerAssert extends AbstractAssert { 42 | 43 | private static final String ASSERTION_ENABLED_CONFIG_PATH = "/assertj-swagger.properties"; 44 | private DocumentationDrivenValidator documentationDrivenValidator; 45 | private ConsumerDrivenValidator consumerDrivenValidator; 46 | 47 | 48 | public SwaggerAssert(Swagger actual) { 49 | super(actual, SwaggerAssert.class); 50 | documentationDrivenValidator = new DocumentationDrivenValidator(actual, loadSwaggerAssertionFlagsConfiguration(ASSERTION_ENABLED_CONFIG_PATH)); 51 | consumerDrivenValidator = new ConsumerDrivenValidator(actual, loadSwaggerAssertionFlagsConfiguration(ASSERTION_ENABLED_CONFIG_PATH)); 52 | } 53 | 54 | public SwaggerAssert(Swagger actual, SwaggerAssertionConfig assertionConfig) { 55 | super(actual, SwaggerAssert.class); 56 | documentationDrivenValidator = new DocumentationDrivenValidator(actual, assertionConfig); 57 | consumerDrivenValidator = new ConsumerDrivenValidator(actual, assertionConfig); 58 | } 59 | 60 | public SwaggerAssert(Swagger actual, String configurationResourceLocation) { 61 | super(actual, SwaggerAssert.class); 62 | documentationDrivenValidator = new DocumentationDrivenValidator(actual, loadSwaggerAssertionFlagsConfiguration(configurationResourceLocation)); 63 | consumerDrivenValidator = new ConsumerDrivenValidator(actual, loadSwaggerAssertionFlagsConfiguration(configurationResourceLocation)); 64 | } 65 | 66 | /** 67 | * Verifies that the actual value is equal to the given one. 68 | * 69 | * @param expected the given value to compare the actual value to. 70 | * @return {@code this} assertion object. 71 | * @throws AssertionError if the actual value is not equal to the given one or if the actual value is {@code null}.. 72 | */ 73 | public SwaggerAssert isEqualTo(Swagger expected) { 74 | SchemaObjectResolver schemaObjectResolver = new SchemaObjectResolver(expected, actual); 75 | documentationDrivenValidator.validateSwagger(expected, schemaObjectResolver); 76 | return myself; 77 | } 78 | 79 | /** 80 | * Verifies that the actual value is equal to the given one. 81 | * 82 | * @param expectedLocation the location of the given value to compare the actual value to. 83 | * @return {@code this} assertion object. 84 | * @throws AssertionError if the actual value is not equal to the given one or if the actual value is {@code null}.. 85 | */ 86 | public SwaggerAssert isEqualTo(String expectedLocation) { 87 | return isEqualTo(new SwaggerParser().read(expectedLocation)); 88 | } 89 | 90 | /** 91 | * Verifies that the actual value is equal to the given one. 92 | * 93 | * @param expectedLocation the location of the given value to compare the actual value to. 94 | * @param auths List of io.swagger.models.auth.AuthorizationValue for access to protected locations. 95 | * @return {@code this} assertion object. 96 | * @throws AssertionError if the actual value is not equal to the given one or if the actual value is {@code null}.. 97 | */ 98 | public SwaggerAssert isEqualTo(String expectedLocation, List auths) { 99 | return isEqualTo(new SwaggerParser().read(expectedLocation, auths, true)); 100 | } 101 | 102 | /** 103 | * Verifies that the actual value is equal to the given one. 104 | * 105 | * @param expected the given value to compare the actual value to. 106 | * @return {@code this} assertion object. 107 | * @throws AssertionError if the actual value is not equal to the given one or if the actual value is {@code null}.. 108 | */ 109 | public SwaggerAssert satisfiesContract(Swagger expected) { 110 | SchemaObjectResolver schemaObjectResolver = new SchemaObjectResolver(expected, actual); 111 | consumerDrivenValidator.validateSwagger(expected, schemaObjectResolver); 112 | return myself; 113 | } 114 | 115 | /** 116 | * Verifies that the actual value is equal to the given one. 117 | * 118 | * @param expectedLocation the location of the given value to compare the actual value to. 119 | * @return {@code this} assertion object. 120 | * @throws AssertionError if the actual value is not equal to the given one or if the actual value is {@code null}.. 121 | */ 122 | public SwaggerAssert satisfiesContract(String expectedLocation) { 123 | return satisfiesContract(new SwaggerParser().read(expectedLocation)); 124 | } 125 | 126 | /** 127 | * Verifies that the actual value is equal to the given one. 128 | * 129 | * @param expectedLocation the location of the given value to compare the actual value to. 130 | * @param auths List of io.swagger.models.auth.AuthorizationValue for access to protected locations. 131 | * @return {@code this} assertion object. 132 | * @throws AssertionError if the actual value is not equal to the given one or if the actual value is {@code null}.. 133 | */ 134 | public SwaggerAssert satisfiesContract(String expectedLocation, List auths) { 135 | return satisfiesContract(new SwaggerParser().read(expectedLocation, auths, true)); 136 | } 137 | 138 | private SwaggerAssertionConfig loadSwaggerAssertionFlagsConfiguration(String configurationResourceLocation) { 139 | final Properties props = new Properties(); 140 | try (InputStream is = this.getClass().getResourceAsStream(configurationResourceLocation)) { 141 | if (is != null) { 142 | props.load(is); 143 | } 144 | } catch (final IOException ioe) { 145 | // eat it. 146 | } 147 | 148 | return new SwaggerAssertionConfig(props); 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /src/main/java/io/github/robwin/swagger/test/SwaggerAssertionConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2018 Robert Winkler 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * 18 | */ 19 | package io.github.robwin.swagger.test; 20 | 21 | import org.apache.commons.lang3.StringUtils; 22 | 23 | import java.util.Arrays; 24 | import java.util.Collections; 25 | import java.util.HashMap; 26 | import java.util.HashSet; 27 | import java.util.Map; 28 | import java.util.Properties; 29 | import java.util.Set; 30 | 31 | public class SwaggerAssertionConfig { 32 | 33 | private static final String PREFIX = "assertj.swagger."; 34 | private static final String IGNORE_MISSING_PATHS = "pathsToIgnoreInExpected"; 35 | private static final String IGNORE_MISSING_DEFINITIONS = "definitionsToIgnoreInExpected"; 36 | private static final String IGNORE_MISSING_PROPERTIES = "propertiesToIgnoreInExpected"; 37 | private static final String PATHS_PREPEND_EXPECTED = "pathsPrependExpected"; 38 | 39 | private Map swaggerAssertionFlags = new HashMap<>(); 40 | 41 | private Set pathsToIgnoreInExpected = Collections.emptySet(); 42 | 43 | private Set propertiesToIgnoreInExpected = Collections.emptySet(); 44 | 45 | private Set definitionsToIgnoreInExpected = Collections.emptySet(); 46 | 47 | private String pathsPrependExpected; 48 | 49 | 50 | /** 51 | * Construct a {@link SwaggerAssertionConfig}. 52 | */ 53 | public SwaggerAssertionConfig() { 54 | final SwaggerAssertionType[] assertionTypes = SwaggerAssertionType.values(); 55 | for (final SwaggerAssertionType assertionType : assertionTypes) { 56 | swaggerAssertionFlags.put(assertionType, assertionType.isEnabledByDefault()); 57 | } 58 | } 59 | 60 | /** 61 | * Construct a {@link SwaggerAssertionConfig}. All checks are enabled by default, and overridden by the supplied 62 | * properties. 63 | * @param props properties. Typically sourced from root of classpath 64 | */ 65 | public SwaggerAssertionConfig(final Properties props) { 66 | this(); 67 | final SwaggerAssertionType[] assertionTypes = SwaggerAssertionType.values(); 68 | for (final SwaggerAssertionType assertionType : assertionTypes) { 69 | final String value = props.getProperty(PREFIX + assertionType.getBarePropertyName()); 70 | if (value != null) { 71 | swaggerAssertionFlags.put(assertionType, Boolean.TRUE.toString().equals(value)); 72 | } else { 73 | swaggerAssertionFlags.put(assertionType, assertionType.isEnabledByDefault()); 74 | } 75 | } 76 | 77 | final String ignoreMissingPathsStr = props.getProperty(PREFIX + IGNORE_MISSING_PATHS); 78 | if (!StringUtils.isBlank(ignoreMissingPathsStr)) { 79 | pathsToIgnoreInExpected = splitCommaDelimStrIntoSet(ignoreMissingPathsStr); 80 | } 81 | 82 | final String ignoreMissingDefinitionsStr = props.getProperty(PREFIX + IGNORE_MISSING_DEFINITIONS); 83 | if (!StringUtils.isBlank(ignoreMissingDefinitionsStr)) { 84 | definitionsToIgnoreInExpected = splitCommaDelimStrIntoSet(ignoreMissingDefinitionsStr); 85 | } 86 | 87 | final String ignoreMissingPropertiesStr = props.getProperty(PREFIX + IGNORE_MISSING_PROPERTIES); 88 | if (!StringUtils.isBlank(ignoreMissingPropertiesStr)) { 89 | propertiesToIgnoreInExpected = splitCommaDelimStrIntoSet(ignoreMissingPropertiesStr); 90 | } 91 | 92 | pathsPrependExpected = props.getProperty(PREFIX + PATHS_PREPEND_EXPECTED); 93 | } 94 | 95 | public boolean swaggerAssertionEnabled(SwaggerAssertionType assertionType) { 96 | final Boolean flag = swaggerAssertionFlags.get(assertionType); 97 | return flag != null ? flag : assertionType.isEnabledByDefault(); 98 | } 99 | 100 | public Set getPathsToIgnoreInExpected() { 101 | return pathsToIgnoreInExpected; 102 | } 103 | 104 | public Set getDefinitionsToIgnoreInExpected() { 105 | return definitionsToIgnoreInExpected; 106 | } 107 | 108 | public Set getPropertiesToIgnoreInExpected() { 109 | return propertiesToIgnoreInExpected; 110 | } 111 | 112 | public String getPathsPrependExpected() { 113 | return pathsPrependExpected; 114 | } 115 | 116 | private Set splitCommaDelimStrIntoSet(String str) { 117 | final String[] strs = str.split("\\s*,\\s*"); 118 | return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(strs))); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/main/java/io/github/robwin/swagger/test/SwaggerAssertionType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2018 Robert Winkler 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * 18 | */ 19 | package io.github.robwin.swagger.test; 20 | 21 | /** 22 | * Flags to enable or disable various assertion types are either a coarse- or fine-grained level. 23 | */ 24 | public enum SwaggerAssertionType { 25 | 26 | INFO("validateInfo", false), 27 | VERSION("validateVersion", false), 28 | 29 | DEFINITIONS("validateDefinitions", true), 30 | PROPERTIES("validateProperties", true), 31 | REF_PROPERTIES("validateRefProperties", true), 32 | ARRAY_PROPERTIES("validateArrayProperties", true), 33 | BYTE_ARRAY_PROPERTIES("validateByteArrayProperties", true), 34 | STRING_PROPERTIES("validateStringProperties", true), 35 | MODELS("validateModels", true), 36 | PATHS("validatePaths", true), 37 | STRICT_VALIDATION_ON_PATH("validateResponseWithStrictlyMatch", true); 38 | 39 | private String suffix; 40 | private boolean enabledByDefault; 41 | 42 | SwaggerAssertionType(final String assertionType, final boolean defaultValue) { 43 | this.suffix = assertionType; 44 | this.enabledByDefault = defaultValue; 45 | } 46 | 47 | public String getBarePropertyName() { 48 | return suffix; 49 | } 50 | 51 | public boolean isEnabledByDefault() { 52 | return enabledByDefault; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/io/github/robwin/swagger/test/SwaggerAssertions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2018 Robert Winkler 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * 18 | */ 19 | package io.github.robwin.swagger.test; 20 | 21 | import io.swagger.models.Swagger; 22 | import io.swagger.parser.SwaggerParser; 23 | import org.apache.commons.lang3.Validate; 24 | 25 | /** 26 | * Entry point for assertion methods for different data types. Each method in this class is a static factory for the 27 | * type-specific assertion objects. The purpose of this class is to make test code more readable. 28 | * 29 | * @author Robert Winkler 30 | */ 31 | public class SwaggerAssertions { 32 | 33 | /** 34 | * Creates a new instance of {@link SwaggerAssert}. 35 | * 36 | * @param actual the the actual Swagger value. 37 | * @return the created assertion object. 38 | */ 39 | public static SwaggerAssert assertThat(Swagger actual) { 40 | Validate.notNull(actual, "actual must not be null!"); 41 | return new SwaggerAssert(actual); 42 | } 43 | 44 | 45 | /** 46 | * Creates a new instance of {@link SwaggerAssert}. 47 | * 48 | * @param actualLocation the location the actual Swagger value. 49 | * @return the created assertion object. 50 | */ 51 | public static SwaggerAssert assertThat(String actualLocation) { 52 | Validate.notNull(actualLocation, "actualLocation must not be null!"); 53 | return new SwaggerAssert(new SwaggerParser().read(actualLocation)); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/io/github/robwin/swagger/SwaggerConsumerDrivenAssertTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2018 Robert Winkler 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * 18 | */ 19 | package io.github.robwin.swagger; 20 | 21 | import io.github.robwin.swagger.test.SwaggerAssert; 22 | import io.github.robwin.swagger.test.SwaggerAssertions; 23 | import io.swagger.parser.SwaggerParser; 24 | import org.apache.commons.lang3.Validate; 25 | import org.junit.Test; 26 | 27 | import java.io.File; 28 | 29 | public class SwaggerConsumerDrivenAssertTest { 30 | 31 | @Test 32 | public void shouldFindNoDifferences() { 33 | File implFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger.json").getFile()); 34 | File designFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger.yaml").getFile()); 35 | SwaggerAssertions.assertThat(implFirstSwaggerLocation.getAbsolutePath()).satisfiesContract(designFirstSwaggerLocation.getAbsolutePath()); 36 | } 37 | 38 | @Test 39 | public void shouldtolerateOptionalParameter() { 40 | File implFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-added-optional-parameter.json").getFile()); 41 | File designFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger.yaml").getFile()); 42 | SwaggerAssertions.assertThat(implFirstSwaggerLocation.getAbsolutePath()).satisfiesContract(designFirstSwaggerLocation.getAbsolutePath()); 43 | } 44 | 45 | @Test(expected = AssertionError.class) 46 | public void shouldNotTolerateRequiredParameter() { 47 | File implFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-added-required-parameter.json").getPath()); 48 | File designFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger.yaml").getPath()); 49 | SwaggerAssertions.assertThat(implFirstSwaggerLocation.getAbsolutePath()).satisfiesContract(designFirstSwaggerLocation.getAbsolutePath()); 50 | } 51 | 52 | @Test(expected = AssertionError.class) 53 | public void shouldFindDifferencesInImplementation() { 54 | File implFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/wrong_swagger.json").getPath()); 55 | File designFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger.yaml").getPath()); 56 | SwaggerAssertions.assertThat(implFirstSwaggerLocation.getAbsolutePath()).satisfiesContract(designFirstSwaggerLocation.getAbsolutePath()); 57 | } 58 | 59 | @Test(expected = AssertionError.class) 60 | public void shouldFindDifferencesInInfo() { 61 | // Otherwise-good comparison will fail here, because 'info.title' is different 62 | File implFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger.json").getPath()); 63 | File designFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger.yaml").getPath()); 64 | new SwaggerAssert(new SwaggerParser().read(implFirstSwaggerLocation.getAbsolutePath()), "/assertj-swagger-info.properties") 65 | .satisfiesContract(designFirstSwaggerLocation.getAbsolutePath()); 66 | } 67 | 68 | @Test(expected = AssertionError.class) 69 | public void shouldFindMissingPropertyInPartialModel() { 70 | File implFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger.json").getPath()); 71 | File designFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-singleresource-extraproperty.json").getPath()); 72 | 73 | Validate.notNull(implFirstSwaggerLocation.getAbsolutePath(), "actualLocation must not be null!"); 74 | SwaggerAssertions.assertThat(implFirstSwaggerLocation.getAbsolutePath()).satisfiesContract(designFirstSwaggerLocation.getAbsolutePath()); 75 | } 76 | 77 | @Test(expected = AssertionError.class) 78 | public void shouldFindMissingMethodInPartialModel() { 79 | File implFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger.json").getPath()); 80 | File designFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-singleresource-extramethod.json").getPath()); 81 | 82 | Validate.notNull(implFirstSwaggerLocation.getAbsolutePath(), "actualLocation must not be null!"); 83 | SwaggerAssertions.assertThat(implFirstSwaggerLocation.getAbsolutePath()).satisfiesContract(designFirstSwaggerLocation.getAbsolutePath()); 84 | } 85 | 86 | @Test(expected = AssertionError.class) 87 | public void shouldFindMissingResourceInPartialModel() { 88 | File implFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger.json").getPath()); 89 | File designFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-extraresource.json").getPath()); 90 | 91 | Validate.notNull(implFirstSwaggerLocation.getAbsolutePath(), "actualLocation must not be null!"); 92 | SwaggerAssertions.assertThat(implFirstSwaggerLocation.getAbsolutePath()).satisfiesContract(designFirstSwaggerLocation.getAbsolutePath()); 93 | } 94 | 95 | @Test 96 | public void shouldHandleConsumerContractSingleResource() { 97 | File implFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger.json").getPath()); 98 | File designFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-singleresource.json").getPath()); 99 | 100 | Validate.notNull(implFirstSwaggerLocation.getAbsolutePath(), "actualLocation must not be null!"); 101 | SwaggerAssertions.assertThat(implFirstSwaggerLocation.getAbsolutePath()).satisfiesContract(designFirstSwaggerLocation.getAbsolutePath()); 102 | } 103 | 104 | @Test 105 | public void shouldHandleConsumerContractPartialModel() { 106 | File implFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger.json").getPath()); 107 | File designFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-singleresource-partialmodel.json").getPath()); 108 | 109 | Validate.notNull(implFirstSwaggerLocation.getAbsolutePath(), "actualLocation must not be null!"); 110 | SwaggerAssertions.assertThat(implFirstSwaggerLocation.getAbsolutePath()).satisfiesContract(designFirstSwaggerLocation.getAbsolutePath()); 111 | } 112 | 113 | @Test 114 | public void shouldHandleExpectedPathsWithPrefix() { 115 | File implFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger_with_path_prefixes.json").getPath()); 116 | File designFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger.yaml").getPath()); 117 | 118 | Validate.notNull(implFirstSwaggerLocation.getAbsolutePath(), "actualLocation must not be null!"); 119 | new SwaggerAssert(new SwaggerParser().read(implFirstSwaggerLocation.getAbsolutePath()), "/assertj-swagger-path-prefix.properties") 120 | .satisfiesContract(designFirstSwaggerLocation.getAbsolutePath()); 121 | } 122 | 123 | @Test 124 | public void shouldHandleDefinitionsUsingAllOf() { 125 | File implFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-allOf-test-flat.json").getPath()); 126 | File designFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-allOf-test-inheritance.json").getPath()); 127 | 128 | Validate.notNull(implFirstSwaggerLocation.getAbsolutePath(), "actualLocation must not be null!"); 129 | new SwaggerAssert(new SwaggerParser().read(implFirstSwaggerLocation.getAbsolutePath()), "/assertj-swagger-allOf.properties") 130 | .satisfiesContract(designFirstSwaggerLocation.getAbsolutePath()); 131 | } 132 | 133 | @Test 134 | public void shouldHandleDefinitionsUsingAllOfIncludingCycles() { 135 | File implFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-allOf-test-flat.json").getPath()); 136 | File designFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-allOf-test-inheritance-cycles.json").getPath()); 137 | 138 | Validate.notNull(implFirstSwaggerLocation.getAbsolutePath(), "actualLocation must not be null!"); 139 | new SwaggerAssert(new SwaggerParser().read(implFirstSwaggerLocation.getAbsolutePath()), "/assertj-swagger-allOf.properties") 140 | .satisfiesContract(designFirstSwaggerLocation.getAbsolutePath()); 141 | } 142 | 143 | @Test 144 | public void shouldntFailWhenDesignHasNoDefinitionsButImplHasDefinitions() { 145 | // not using swagger.json to avoid test failure because of issue 26 (where design api-doc is not allowed to have less operations under the same path) 146 | File implFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-pets-by-petId-without-get-and-post.json").getPath()); 147 | File designFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-no-definitions.json").getPath()); 148 | SwaggerAssertions.assertThat(implFirstSwaggerLocation.getAbsolutePath()) 149 | .satisfiesContract(designFirstSwaggerLocation.getAbsolutePath()); 150 | } 151 | 152 | @Test(expected = AssertionError.class) 153 | public void shouldFindDifferentRequiredFieldsForObjectDefinition() { 154 | File implFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-missing-required-field-object.json").getPath()); 155 | File designFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger.yaml").getPath()); 156 | SwaggerAssertions.assertThat(implFirstSwaggerLocation.getAbsolutePath()).satisfiesContract(designFirstSwaggerLocation.getAbsolutePath()); 157 | } 158 | 159 | @Test 160 | public void shouldPassTestForIdenticalParametersSetContainsParameterWithDifferentTypes() { 161 | File swaggerFile = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-with-multi-types-parameters.json").getPath()); 162 | SwaggerAssertions.assertThat(swaggerFile.getAbsolutePath()).satisfiesContract(swaggerFile.getAbsolutePath()); 163 | 164 | } 165 | 166 | @Test 167 | public void shouldntFailWhenImplHasMoreOperationsOfSamePath() { 168 | File implFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger.json").getPath()); 169 | File designFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-path-without-some-operations.json").getPath()); 170 | SwaggerAssertions.assertThat(implFirstSwaggerLocation.getAbsolutePath()) 171 | .satisfiesContract(designFirstSwaggerLocation.getAbsolutePath()); 172 | } 173 | 174 | @Test 175 | public void shouldPassWhenParameterDescriptionIsDifferent() { 176 | File implFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger.json").getPath()); 177 | File designFirstSwaggerLocation = new File(SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-different-parameter-description.json").getPath()); 178 | SwaggerAssertions.assertThat(implFirstSwaggerLocation.getAbsolutePath()) 179 | .satisfiesContract(designFirstSwaggerLocation.getAbsolutePath()); 180 | } 181 | } 182 | -------------------------------------------------------------------------------- /src/test/java/io/github/robwin/swagger/SwaggerDocumentationDrivenAssertTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2018 Robert Winkler 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * 18 | */ 19 | package io.github.robwin.swagger; 20 | 21 | import java.io.File; 22 | import java.io.FileReader; 23 | import java.io.IOException; 24 | import java.nio.file.Files; 25 | import java.nio.file.Paths; 26 | import java.util.Properties; 27 | 28 | import io.github.robwin.swagger.test.SwaggerAssert; 29 | import io.github.robwin.swagger.test.SwaggerAssertionConfig; 30 | import io.github.robwin.swagger.test.SwaggerAssertions; 31 | import io.swagger.parser.SwaggerParser; 32 | import org.apache.commons.lang3.Validate; 33 | import org.junit.After; 34 | import org.junit.Test; 35 | 36 | public class SwaggerDocumentationDrivenAssertTest { 37 | 38 | private static final String SWAGGER_CONFIG_LOCATION = "assertj-swagger.properties"; 39 | private static final File SWAGGER_CONFIG = new File(SWAGGER_CONFIG_LOCATION); 40 | 41 | @After 42 | public void tearDown() { 43 | SWAGGER_CONFIG.deleteOnExit(); 44 | } 45 | 46 | @Test 47 | public void shouldFindNoDifferences() { 48 | File implFirstSwaggerLocation = new File( 49 | SwaggerDocumentationDrivenAssertTest.class.getResource("/swagger.json").getFile()); 50 | File designFirstSwaggerLocation = new File( 51 | SwaggerDocumentationDrivenAssertTest.class.getResource("/swagger.yaml").getFile()); 52 | SwaggerAssertions.assertThat(implFirstSwaggerLocation.getAbsolutePath()) 53 | .isEqualTo(designFirstSwaggerLocation.getAbsolutePath()); 54 | } 55 | 56 | @Test(expected = AssertionError.class) 57 | public void shouldFindDifferencesInImplementation() { 58 | File implFirstSwaggerLocation = new File( 59 | SwaggerDocumentationDrivenAssertTest.class.getResource("/wrong_swagger.json").getPath()); 60 | File designFirstSwaggerLocation = new File( 61 | SwaggerDocumentationDrivenAssertTest.class.getResource("/swagger.yaml").getPath()); 62 | SwaggerAssertions.assertThat(implFirstSwaggerLocation.getAbsolutePath()) 63 | .isEqualTo(designFirstSwaggerLocation.getAbsolutePath()); 64 | } 65 | 66 | @Test(expected = AssertionError.class) 67 | public void shouldFindDifferencesInParameterNaming() { 68 | File implFirstSwaggerLocation = new File( 69 | SwaggerDocumentationDrivenAssertTest.class.getResource("/swagger-name-changes.json").getPath()); 70 | File designFirstSwaggerLocation = new File( 71 | SwaggerDocumentationDrivenAssertTest.class.getResource("/swagger.yaml").getPath()); 72 | SwaggerAssertions.assertThat(implFirstSwaggerLocation.getAbsolutePath()) 73 | .isEqualTo(designFirstSwaggerLocation.getAbsolutePath()); 74 | } 75 | 76 | @Test(expected = AssertionError.class) 77 | public void shouldFindDifferencesInRequiredness() { 78 | File implFirstSwaggerLocation = new File( 79 | SwaggerDocumentationDrivenAssertTest.class.getResource("/swagger-requiredness-changes.json").getPath()); 80 | File designFirstSwaggerLocation = new File( 81 | SwaggerDocumentationDrivenAssertTest.class.getResource("/swagger.yaml").getPath()); 82 | SwaggerAssertions.assertThat(implFirstSwaggerLocation.getAbsolutePath()) 83 | .isEqualTo(designFirstSwaggerLocation.getAbsolutePath()); 84 | } 85 | 86 | @Test(expected = AssertionError.class) 87 | public void shouldFindDifferencesInInfo() { 88 | // Otherwise-good comparison will fail here, because 'info.title' is different 89 | File implFirstSwaggerLocation = new File( 90 | SwaggerDocumentationDrivenAssertTest.class.getResource("/swagger.json").getPath()); 91 | File designFirstSwaggerLocation = new File( 92 | SwaggerDocumentationDrivenAssertTest.class.getResource("/swagger.yaml").getPath()); 93 | new SwaggerAssert(new SwaggerParser().read(implFirstSwaggerLocation.getAbsolutePath()), 94 | "/assertj-swagger-info.properties") 95 | .isEqualTo(designFirstSwaggerLocation.getAbsolutePath()); 96 | } 97 | 98 | @Test 99 | public void shouldHandlePartiallyImplementedApi() { 100 | File implFirstSwaggerLocation = new File( 101 | SwaggerDocumentationDrivenAssertTest.class.getResource("/partial_impl_swagger.json").getPath()); 102 | File designFirstSwaggerLocation = new File( 103 | SwaggerDocumentationDrivenAssertTest.class.getResource("/swagger.yaml").getPath()); 104 | 105 | Validate.notNull(implFirstSwaggerLocation.getAbsolutePath(), "actualLocation must not be null!"); 106 | new SwaggerAssert(new SwaggerParser().read(implFirstSwaggerLocation.getAbsolutePath()), 107 | "/assertj-swagger-partial-impl.properties") 108 | .isEqualTo(designFirstSwaggerLocation.getAbsolutePath()); 109 | } 110 | 111 | @Test 112 | public void shouldHandleExpectedPathsWithPrefix() { 113 | File implFirstSwaggerLocation = new File( 114 | SwaggerDocumentationDrivenAssertTest.class.getResource("/swagger_with_path_prefixes.json").getPath()); 115 | File designFirstSwaggerLocation = new File( 116 | SwaggerDocumentationDrivenAssertTest.class.getResource("/swagger.yaml").getPath()); 117 | 118 | Validate.notNull(implFirstSwaggerLocation.getAbsolutePath(), "actualLocation must not be null!"); 119 | new SwaggerAssert(new SwaggerParser().read(implFirstSwaggerLocation.getAbsolutePath()), 120 | "/assertj-swagger-path-prefix.properties") 121 | .isEqualTo(designFirstSwaggerLocation.getAbsolutePath()); 122 | } 123 | 124 | @Test 125 | public void shouldHandleDefinitionsUsingAllOf() { 126 | File implFirstSwaggerLocation = new File( 127 | SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-allOf-test-flat.json").getPath()); 128 | File designFirstSwaggerLocation = new File( 129 | SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-allOf-test-inheritance.json").getPath()); 130 | 131 | Validate.notNull(implFirstSwaggerLocation.getAbsolutePath(), "actualLocation must not be null!"); 132 | new SwaggerAssert(new SwaggerParser().read(implFirstSwaggerLocation.getAbsolutePath()), 133 | "/assertj-swagger-allOf.properties") 134 | .isEqualTo(designFirstSwaggerLocation.getAbsolutePath()); 135 | } 136 | 137 | @Test 138 | public void shouldHandleDefinitionsUsingAllOfIncludingCycles() { 139 | File implFirstSwaggerLocation = new File( 140 | SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-allOf-test-flat.json").getPath()); 141 | File designFirstSwaggerLocation = new File( 142 | SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-allOf-test-inheritance-cycles.json").getPath()); 143 | 144 | Validate.notNull(implFirstSwaggerLocation.getAbsolutePath(), "actualLocation must not be null!"); 145 | new SwaggerAssert(new SwaggerParser().read(implFirstSwaggerLocation.getAbsolutePath()), 146 | "/assertj-swagger-allOf.properties") 147 | .isEqualTo(designFirstSwaggerLocation.getAbsolutePath()); 148 | } 149 | 150 | @Test 151 | public void shouldHandleDefinitionsUsingAllOfForComposition() { 152 | File implFirstSwaggerLocation = new File( 153 | SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-allOf-composition-flat.json").getPath()); 154 | File designFirstSwaggerLocation = new File( 155 | SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-allOf-composition.json").getPath()); 156 | 157 | Validate.notNull(implFirstSwaggerLocation.getAbsolutePath(), "actualLocation must not be null!"); 158 | new SwaggerAssert(new SwaggerParser().read(implFirstSwaggerLocation.getAbsolutePath())) 159 | .isEqualTo(designFirstSwaggerLocation.getAbsolutePath()); 160 | } 161 | 162 | @Test(expected = AssertionError.class) 163 | public void shouldFindDifferentRequiredFieldsForObjectDefinition() { 164 | File implFirstSwaggerLocation = new File( 165 | SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-missing-required-field-object.json").getPath()); 166 | File designFirstSwaggerLocation = new File( 167 | SwaggerConsumerDrivenAssertTest.class.getResource("/swagger.yaml").getPath()); 168 | 169 | Validate.notNull(implFirstSwaggerLocation.getAbsolutePath(), "actualLocation must not be null!"); 170 | new SwaggerAssert(new SwaggerParser().read(implFirstSwaggerLocation.getAbsolutePath())) 171 | .isEqualTo(designFirstSwaggerLocation.getAbsolutePath()); 172 | } 173 | 174 | @Test 175 | public void shouldHandleByteArrayValues() { 176 | File implFirstSwaggerLocation = new File( 177 | SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-bytearray.json").getPath()); 178 | File designFirstSwaggerLocation = new File( 179 | SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-bytearray.yaml").getPath()); 180 | 181 | Validate.notNull(implFirstSwaggerLocation.getAbsolutePath(), "actualLocation must not be null!"); 182 | new SwaggerAssert(new SwaggerParser().read(implFirstSwaggerLocation.getAbsolutePath())) 183 | .isEqualTo(designFirstSwaggerLocation.getAbsolutePath()); 184 | } 185 | 186 | @Test(expected = AssertionError.class) 187 | public void shouldFindDifferentByteArrayValues() { 188 | File implFirstSwaggerLocation = new File( 189 | SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-bytearray-wrong.json").getPath()); 190 | File designFirstSwaggerLocation = new File( 191 | SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-bytearray.yaml").getPath()); 192 | 193 | Validate.notNull(implFirstSwaggerLocation.getAbsolutePath(), "actualLocation must not be null!"); 194 | new SwaggerAssert(new SwaggerParser().read(implFirstSwaggerLocation.getAbsolutePath())) 195 | .isEqualTo(designFirstSwaggerLocation.getAbsolutePath()); 196 | } 197 | 198 | @Test 199 | public void shouldRefHandleByteArrayValues() { 200 | File implFirstSwaggerLocation = new File( 201 | SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-bytearray-ref.json").getPath()); 202 | File designFirstSwaggerLocation = new File( 203 | SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-bytearray-ref.yaml").getPath()); 204 | 205 | Validate.notNull(implFirstSwaggerLocation.getAbsolutePath(), "actualLocation must not be null!"); 206 | new SwaggerAssert(new SwaggerParser().read(implFirstSwaggerLocation.getAbsolutePath())) 207 | .isEqualTo(designFirstSwaggerLocation.getAbsolutePath()); 208 | } 209 | 210 | @Test(expected = AssertionError.class) 211 | public void shouldFindDifferentRefByteArrayValues() { 212 | File implFirstSwaggerLocation = new File( 213 | SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-bytearray-ref-wrong.json").getPath()); 214 | File designFirstSwaggerLocation = new File( 215 | SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-bytearray-ref.yaml").getPath()); 216 | 217 | Validate.notNull(implFirstSwaggerLocation.getAbsolutePath(), "actualLocation must not be null!"); 218 | new SwaggerAssert(new SwaggerParser().read(implFirstSwaggerLocation.getAbsolutePath())) 219 | .isEqualTo(designFirstSwaggerLocation.getAbsolutePath()); 220 | } 221 | 222 | @Test 223 | public void shouldHandleEnumValues() { 224 | File implFirstSwaggerLocation = new File( 225 | SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-enum.json").getPath()); 226 | File designFirstSwaggerLocation = new File( 227 | SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-enum.yaml").getPath()); 228 | 229 | Validate.notNull(implFirstSwaggerLocation.getAbsolutePath(), "actualLocation must not be null!"); 230 | new SwaggerAssert(new SwaggerParser().read(implFirstSwaggerLocation.getAbsolutePath())) 231 | .isEqualTo(designFirstSwaggerLocation.getAbsolutePath()); 232 | } 233 | 234 | @Test(expected = AssertionError.class) 235 | public void shouldFindDifferentEnumValues() { 236 | File implFirstSwaggerLocation = new File( 237 | SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-enum-wrong.json").getPath()); 238 | File designFirstSwaggerLocation = new File( 239 | SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-enum.yaml").getPath()); 240 | 241 | Validate.notNull(implFirstSwaggerLocation.getAbsolutePath(), "actualLocation must not be null!"); 242 | new SwaggerAssert(new SwaggerParser().read(implFirstSwaggerLocation.getAbsolutePath())) 243 | .isEqualTo(designFirstSwaggerLocation.getAbsolutePath()); 244 | } 245 | 246 | @Test 247 | public void shouldAllowConfigurationToLooselyMatchResponse() throws IOException { 248 | File implFirstSwaggerLocation = new File( 249 | SwaggerConsumerDrivenAssertTest.class.getResource("/swagger.json").getPath()); 250 | File designFirstSwaggerLocation = new File( 251 | SwaggerConsumerDrivenAssertTest.class.getResource("/designed-swagger-with-less-response-defined.yaml") 252 | .getPath()); 253 | configureSwaggerAssertion(); 254 | 255 | SwaggerAssertionConfig config = getConfig(); 256 | 257 | SwaggerAssert swaggerAssert = new SwaggerAssert( 258 | new SwaggerParser().read(implFirstSwaggerLocation.getAbsolutePath()), config); 259 | swaggerAssert.isEqualTo(designFirstSwaggerLocation.getAbsolutePath()); 260 | } 261 | 262 | private SwaggerAssertionConfig getConfig() throws IOException { 263 | Properties props = new Properties(); 264 | props.load(new FileReader(SWAGGER_CONFIG)); 265 | return new SwaggerAssertionConfig(props); 266 | } 267 | 268 | private void configureSwaggerAssertion() throws IOException { 269 | Files.write(Paths.get(SWAGGER_CONFIG_LOCATION), toConfiguration().getBytes()); 270 | } 271 | 272 | private String toConfiguration() { 273 | return "assertj.swagger.validateResponseWithStrictlyMatch=false"; 274 | } 275 | 276 | @Test 277 | public void shouldHandleRefEnumValues() { 278 | File implFirstSwaggerLocation = new File( 279 | SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-enum-ref.json").getPath()); 280 | File designFirstSwaggerLocation = new File( 281 | SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-enum-ref.yaml").getPath()); 282 | 283 | Validate.notNull(implFirstSwaggerLocation.getAbsolutePath(), "actualLocation must not be null!"); 284 | new SwaggerAssert(new SwaggerParser().read(implFirstSwaggerLocation.getAbsolutePath())) 285 | .isEqualTo(designFirstSwaggerLocation.getAbsolutePath()); 286 | } 287 | 288 | @Test(expected = AssertionError.class) 289 | public void shouldFindDifferentRefEnumValues() { 290 | File implFirstSwaggerLocation = new File( 291 | SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-enum-ref-wrong.json").getPath()); 292 | File designFirstSwaggerLocation = new File( 293 | SwaggerConsumerDrivenAssertTest.class.getResource("/swagger-enum-ref.yaml").getPath()); 294 | 295 | Validate.notNull(implFirstSwaggerLocation.getAbsolutePath(), "actualLocation must not be null!"); 296 | new SwaggerAssert(new SwaggerParser().read(implFirstSwaggerLocation.getAbsolutePath())) 297 | .isEqualTo(designFirstSwaggerLocation.getAbsolutePath()); 298 | } 299 | } 300 | -------------------------------------------------------------------------------- /src/test/java/io/github/robwin/swagger/test/AbstractContractValidatorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2018 Robert Winkler 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | * 18 | */ 19 | package io.github.robwin.swagger.test; 20 | 21 | import io.swagger.models.Path; 22 | import io.swagger.models.Swagger; 23 | import io.swagger.parser.SwaggerParser; 24 | import org.junit.Test; 25 | import org.junit.experimental.runners.Enclosed; 26 | import org.junit.runner.RunWith; 27 | 28 | import java.io.File; 29 | import java.util.Map; 30 | import java.util.Properties; 31 | 32 | import static org.hamcrest.CoreMatchers.*; 33 | import static org.junit.Assert.assertThat; 34 | 35 | /** 36 | * Tests AbstractContractValidator. 37 | */ 38 | @RunWith(Enclosed.class) 39 | public class AbstractContractValidatorTest { 40 | private static Swagger buildSwaggerFrom(String filename) { 41 | File swaggerFile = new File(AbstractContractValidatorTest.class.getResource(filename).getPath()); 42 | return new SwaggerParser().read(swaggerFile.getAbsolutePath()); 43 | } 44 | 45 | /** 46 | * Tests getPathsIncludingBasePath(). 47 | */ 48 | public static class GetPathsIncludingBasePath { 49 | @Test 50 | public void shouldReturnPlainPathsIfNoBasePathSet() { 51 | // given 52 | Swagger swagger = buildSwaggerFrom("/swagger_with_path_prefixes.json"); 53 | // when 54 | Map paths = new DummyValidator().getPathsIncludingBasePath(swagger); 55 | // then 56 | paths.entrySet().forEach(e -> assertThat(e.getKey(), startsWith("/v2"))); 57 | } 58 | 59 | @Test 60 | public void shouldReturnPathsPrefixedIfBasePathSet() { 61 | // given 62 | Swagger swagger = buildSwaggerFrom("/swagger.json"); 63 | // when 64 | Map paths = new DummyValidator().getPathsIncludingBasePath(swagger); 65 | // then 66 | paths.entrySet().forEach(e -> assertThat(e.getKey(), startsWith(swagger.getBasePath()))); 67 | } 68 | 69 | @Test 70 | public void shouldNotAddRootBasePathToPaths() { 71 | // given basePath: / 72 | Swagger swagger = buildSwaggerFrom("/swagger-with-path-prefixes-and-root-basepath.json"); 73 | // when 74 | Map paths = new DummyValidator().getPathsIncludingBasePath(swagger); 75 | // then 76 | paths.entrySet().forEach(e -> assertThat(e.getKey(), startsWith("/v2"))); 77 | } 78 | } 79 | 80 | /** 81 | * Tests findExpectedPaths(). 82 | */ 83 | public static class FindExpectedPaths { 84 | @Test 85 | public void shouldReturnPlainPathsIfNoBasePathSetAndNoPrefixConfigured() { 86 | // given 87 | Swagger swagger = buildSwaggerFrom("/swagger_with_path_prefixes.json"); 88 | SwaggerAssertionConfig swaggerAssertionConfig = new SwaggerAssertionConfig(new Properties()); 89 | // when 90 | Map paths = new DummyValidator().findExpectedPaths(swagger, swaggerAssertionConfig); 91 | // then 92 | paths.entrySet().forEach(e -> assertThat(e.getKey(), startsWith("/v2"))); 93 | } 94 | 95 | @Test 96 | public void shouldReturnPathsPrefixedIfBasePathSet() { 97 | // given 98 | Swagger swagger = buildSwaggerFrom("/swagger.json"); 99 | SwaggerAssertionConfig swaggerAssertionConfig = new SwaggerAssertionConfig(new Properties()); 100 | // when 101 | Map paths = new DummyValidator().findExpectedPaths(swagger, swaggerAssertionConfig); 102 | // then 103 | paths.entrySet().forEach(e -> assertThat(e.getKey(), startsWith(swagger.getBasePath()))); 104 | } 105 | 106 | @Test 107 | public void shouldReturnPathsPrefixedIfPrefixConfigured() { 108 | // given 109 | Swagger swagger = buildSwaggerFrom("/swagger.json"); 110 | Properties properties = new Properties(); 111 | String configuredPathPrefix = "/foo"; 112 | properties.put("assertj.swagger.pathsPrependExpected", configuredPathPrefix); 113 | SwaggerAssertionConfig swaggerAssertionConfig = new SwaggerAssertionConfig(properties); 114 | // when 115 | Map paths = new DummyValidator().findExpectedPaths(swagger, swaggerAssertionConfig); 116 | // then configured prefix takes precedence over base path 117 | paths.entrySet().forEach(e -> { 118 | assertThat(e.getKey(), startsWith(configuredPathPrefix)); 119 | assertThat(e.getKey(), not(containsString(swagger.getBasePath()))); 120 | }); 121 | } 122 | } 123 | 124 | private static class DummyValidator extends AbstractContractValidator { 125 | @Override 126 | public void validateSwagger(Swagger expected, SchemaObjectResolver schemaObjectResolver) { 127 | 128 | } 129 | } 130 | 131 | } 132 | -------------------------------------------------------------------------------- /src/test/resources/assertj-swagger-allOf.properties: -------------------------------------------------------------------------------- 1 | assertj.swagger.validateModels=false 2 | assertj.swagger.definitionsToIgnoreInExpected=AbstractOrder,Order1,Order2,OrderBase 3 | -------------------------------------------------------------------------------- /src/test/resources/assertj-swagger-info.properties: -------------------------------------------------------------------------------- 1 | assertj.swagger.validateInfo=true 2 | -------------------------------------------------------------------------------- /src/test/resources/assertj-swagger-partial-impl.properties: -------------------------------------------------------------------------------- 1 | assertj.swagger.definitionsToIgnoreInExpected=User 2 | assertj.swagger.propertiesToIgnoreInExpected=Pet.photoUrls 3 | assertj.swagger.pathsToIgnoreInExpected=\ 4 | /v2/users,\ 5 | /v2/users/createWithArray,\ 6 | /v2/users/createWithList,\ 7 | /v2/users/login,\ 8 | /v2/users/logout,\ 9 | /v2/users/{username} 10 | -------------------------------------------------------------------------------- /src/test/resources/assertj-swagger-path-prefix.properties: -------------------------------------------------------------------------------- 1 | assertj.swagger.pathsPrependExpected=/v2 -------------------------------------------------------------------------------- /src/test/resources/designed-swagger-with-less-response-defined.yaml: -------------------------------------------------------------------------------- 1 | swagger: "2.0" 2 | info: 3 | description: | 4 | This is a sample server Petstore server. 5 | 6 | [Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net. 7 | 8 | For this sample, you can use the api key `special-key` to test the authorization filters 9 | version: "1.0.0" 10 | title: Swagger Petstore 11 | termsOfService: http://helloreverb.com/terms/ 12 | contact: 13 | name: apiteam@wordnik.com 14 | license: 15 | name: Apache 2.0 16 | url: http://www.apache.org/licenses/LICENSE-2.0.html 17 | host: petstore.swagger.wordnik.com 18 | basePath: /v2 19 | schemes: 20 | - http 21 | paths: 22 | /pets: 23 | post: 24 | tags: 25 | - pet 26 | summary: Add a new pet to the store 27 | description: "" 28 | operationId: addPet 29 | consumes: 30 | - application/json 31 | - application/xml 32 | produces: 33 | - application/json 34 | - application/xml 35 | parameters: 36 | - in: body 37 | name: body 38 | description: Pet object that needs to be added to the store 39 | required: false 40 | schema: 41 | $ref: "#/definitions/Pet" 42 | responses: 43 | "405": 44 | description: Invalid input 45 | security: 46 | - petstore_auth: 47 | - write_pets 48 | - read_pets 49 | put: 50 | tags: 51 | - pet 52 | summary: Update an existing pet 53 | description: "" 54 | operationId: updatePet 55 | consumes: 56 | - application/json 57 | - application/xml 58 | produces: 59 | - application/json 60 | - application/xml 61 | parameters: 62 | - in: body 63 | name: body 64 | description: Pet object that needs to be added to the store 65 | required: false 66 | schema: 67 | $ref: "#/definitions/Pet" 68 | responses: 69 | "405": 70 | description: Validation exception 71 | security: 72 | - petstore_auth: 73 | - write_pets 74 | - read_pets 75 | /pets/findByStatus: 76 | get: 77 | tags: 78 | - pet 79 | summary: Finds Pets by status 80 | description: Multiple status values can be provided with comma seperated strings 81 | operationId: findPetsByStatus 82 | produces: 83 | - application/json 84 | - application/xml 85 | parameters: 86 | - in: query 87 | name: status 88 | description: Status values that need to be considered for filter 89 | required: false 90 | type: array 91 | items: 92 | type: string 93 | collectionFormat: multi 94 | responses: 95 | "200": 96 | description: successful operation 97 | schema: 98 | type: array 99 | items: 100 | $ref: "#/definitions/Pet" 101 | "400": 102 | description: Invalid status value 103 | security: 104 | - petstore_auth: 105 | - write_pets 106 | - read_pets 107 | /pets/findByTags: 108 | get: 109 | tags: 110 | - pet 111 | summary: Finds Pets by tags 112 | description: Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. 113 | operationId: findPetsByTags 114 | produces: 115 | - application/json 116 | - application/xml 117 | parameters: 118 | - in: query 119 | name: tags 120 | description: Tags to filter by 121 | required: false 122 | type: array 123 | items: 124 | type: string 125 | collectionFormat: multi 126 | responses: 127 | "200": 128 | description: successful operation 129 | schema: 130 | type: array 131 | items: 132 | $ref: "#/definitions/Pet" 133 | "400": 134 | description: Invalid tag value 135 | security: 136 | - petstore_auth: 137 | - write_pets 138 | - read_pets 139 | /pets/{petId}: 140 | get: 141 | tags: 142 | - pet 143 | summary: Find pet by ID 144 | description: Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions 145 | operationId: getPetById 146 | produces: 147 | - application/json 148 | - application/xml 149 | parameters: 150 | - in: path 151 | name: petId 152 | description: ID of pet that needs to be fetched 153 | required: true 154 | type: integer 155 | format: int64 156 | responses: 157 | "404": 158 | description: Pet not found 159 | "200": 160 | description: successful operation 161 | schema: 162 | $ref: "#/definitions/Pet" 163 | "400": 164 | description: Invalid ID supplied 165 | security: 166 | - api_key: [] 167 | - petstore_auth: 168 | - write_pets 169 | - read_pets 170 | post: 171 | tags: 172 | - pet 173 | summary: Updates a pet in the store with form data 174 | description: "" 175 | operationId: updatePetWithForm 176 | consumes: 177 | - application/x-www-form-urlencoded 178 | produces: 179 | - application/json 180 | - application/xml 181 | parameters: 182 | - in: path 183 | name: petId 184 | description: ID of pet that needs to be updated 185 | required: true 186 | type: string 187 | - in: formData 188 | name: name 189 | description: Updated name of the pet 190 | required: true 191 | type: string 192 | - in: formData 193 | name: status 194 | description: Updated status of the pet 195 | required: true 196 | type: string 197 | responses: 198 | "405": 199 | description: Invalid input 200 | security: 201 | - petstore_auth: 202 | - write_pets 203 | - read_pets 204 | delete: 205 | tags: 206 | - pet 207 | summary: Deletes a pet 208 | description: "" 209 | operationId: deletePet 210 | produces: 211 | - application/json 212 | - application/xml 213 | parameters: 214 | - in: header 215 | name: api_key 216 | description: "" 217 | required: true 218 | type: string 219 | - in: path 220 | name: petId 221 | description: Pet id to delete 222 | required: true 223 | type: integer 224 | format: int64 225 | responses: 226 | "400": 227 | description: Invalid pet value 228 | security: 229 | - petstore_auth: 230 | - write_pets 231 | - read_pets 232 | /stores/order: 233 | post: 234 | tags: 235 | - store 236 | summary: Place an order for a pet 237 | description: "" 238 | operationId: placeOrder 239 | produces: 240 | - application/json 241 | - application/xml 242 | parameters: 243 | - in: body 244 | name: body 245 | description: order placed for purchasing the pet 246 | required: false 247 | schema: 248 | $ref: "#/definitions/Order" 249 | responses: 250 | "200": 251 | description: successful operation 252 | schema: 253 | $ref: "#/definitions/Order" 254 | "400": 255 | description: Invalid Order 256 | /stores/order/{orderId}: 257 | get: 258 | tags: 259 | - store 260 | summary: Find purchase order by ID 261 | description: For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions 262 | operationId: getOrderById 263 | produces: 264 | - application/json 265 | - application/xml 266 | parameters: 267 | - in: path 268 | name: orderId 269 | description: ID of pet that needs to be fetched 270 | required: true 271 | type: string 272 | responses: 273 | "404": 274 | description: Order not found 275 | "200": 276 | description: successful operation 277 | schema: 278 | $ref: "#/definitions/Order" 279 | "400": 280 | description: Invalid ID supplied 281 | delete: 282 | tags: 283 | - store 284 | summary: Delete purchase order by ID 285 | description: For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors 286 | operationId: deleteOrder 287 | produces: 288 | - application/json 289 | - application/xml 290 | parameters: 291 | - in: path 292 | name: orderId 293 | description: ID of the order that needs to be deleted 294 | required: true 295 | type: string 296 | responses: 297 | "404": 298 | description: Order not found 299 | "400": 300 | description: Invalid ID supplied 301 | /users: 302 | post: 303 | tags: 304 | - user 305 | summary: Create user 306 | description: This can only be done by the logged in user. 307 | operationId: createUser 308 | produces: 309 | - application/json 310 | - application/xml 311 | parameters: 312 | - in: body 313 | name: body 314 | description: Created user object 315 | required: false 316 | schema: 317 | $ref: "#/definitions/User" 318 | responses: 319 | default: 320 | description: successful operation 321 | /users/createWithArray: 322 | post: 323 | tags: 324 | - user 325 | summary: Creates list of users with given input array 326 | description: "" 327 | operationId: createUsersWithArrayInput 328 | produces: 329 | - application/json 330 | - application/xml 331 | parameters: 332 | - in: body 333 | name: body 334 | description: List of user object 335 | required: false 336 | schema: 337 | type: array 338 | items: 339 | $ref: "#/definitions/User" 340 | responses: 341 | default: 342 | description: successful operation 343 | /users/createWithList: 344 | post: 345 | tags: 346 | - user 347 | summary: Creates list of users with given input array 348 | description: "" 349 | operationId: createUsersWithListInput 350 | produces: 351 | - application/json 352 | - application/xml 353 | parameters: 354 | - in: body 355 | name: body 356 | description: List of user object 357 | required: false 358 | schema: 359 | type: array 360 | items: 361 | $ref: "#/definitions/User" 362 | responses: 363 | default: 364 | description: successful operation 365 | /users/login: 366 | get: 367 | tags: 368 | - user 369 | summary: Logs user into the system 370 | description: "" 371 | operationId: loginUser 372 | produces: 373 | - application/json 374 | - application/xml 375 | parameters: 376 | - in: query 377 | name: username 378 | description: The user name for login 379 | required: false 380 | type: string 381 | - in: query 382 | name: password 383 | description: The password for login in clear text 384 | required: false 385 | type: string 386 | responses: 387 | "200": 388 | description: successful operation 389 | schema: 390 | type: string 391 | "400": 392 | description: Invalid username/password supplied 393 | /users/logout: 394 | get: 395 | tags: 396 | - user 397 | summary: Logs out current logged in user session 398 | description: "" 399 | operationId: logoutUser 400 | produces: 401 | - application/json 402 | - application/xml 403 | responses: 404 | default: 405 | description: successful operation 406 | /users/{username}: 407 | get: 408 | tags: 409 | - user 410 | summary: Get user by user name 411 | description: "" 412 | operationId: getUserByName 413 | produces: 414 | - application/json 415 | - application/xml 416 | parameters: 417 | - in: path 418 | name: username 419 | description: The name that needs to be fetched. Use user1 for testing. 420 | required: true 421 | type: string 422 | responses: 423 | "404": 424 | description: User not found 425 | "200": 426 | description: successful operation 427 | schema: 428 | $ref: "#/definitions/User" 429 | "400": 430 | description: Invalid username supplied 431 | put: 432 | tags: 433 | - user 434 | summary: Updated user 435 | description: This can only be done by the logged in user. 436 | operationId: updateUser 437 | produces: 438 | - application/json 439 | - application/xml 440 | parameters: 441 | - in: path 442 | name: username 443 | description: name that need to be deleted 444 | required: true 445 | type: string 446 | - in: body 447 | name: body 448 | description: Updated user object 449 | required: false 450 | schema: 451 | $ref: "#/definitions/User" 452 | responses: 453 | "404": 454 | description: User not found 455 | "400": 456 | description: Invalid user supplied 457 | delete: 458 | tags: 459 | - user 460 | summary: Delete user 461 | description: This can only be done by the logged in user. 462 | operationId: deleteUser 463 | produces: 464 | - application/json 465 | - application/xml 466 | parameters: 467 | - in: path 468 | name: username 469 | description: The name that needs to be deleted 470 | required: true 471 | type: string 472 | responses: 473 | "404": 474 | description: User not found 475 | "400": 476 | description: Invalid username supplied 477 | securityDefinitions: 478 | api_key: 479 | type: apiKey 480 | name: api_key 481 | in: header 482 | petstore_auth: 483 | type: oauth2 484 | authorizationUrl: http://petstore.swagger.wordnik.com/api/oauth/dialog 485 | flow: implicit 486 | scopes: 487 | write_pets: modify pets in your account 488 | read_pets: read your pets 489 | definitions: 490 | User: 491 | properties: 492 | id: 493 | type: integer 494 | format: int64 495 | username: 496 | type: string 497 | firstName: 498 | type: string 499 | lastName: 500 | type: string 501 | email: 502 | type: string 503 | password: 504 | type: string 505 | phone: 506 | type: string 507 | userStatus: 508 | type: integer 509 | format: int32 510 | description: User Status 511 | Category: 512 | properties: 513 | id: 514 | type: integer 515 | format: int64 516 | name: 517 | type: string 518 | Pet: 519 | description: Test test 520 | required: 521 | - name 522 | - photoUrls 523 | properties: 524 | id: 525 | type: integer 526 | format: int64 527 | category: 528 | $ref: "#/definitions/Category" 529 | name: 530 | type: string 531 | example: doggie 532 | photoUrls: 533 | type: array 534 | items: 535 | type: string 536 | tags: 537 | type: array 538 | items: 539 | $ref: "#/definitions/Tag" 540 | status: 541 | type: string 542 | description: pet status in the store 543 | Tag: 544 | properties: 545 | id: 546 | type: integer 547 | format: int64 548 | name: 549 | type: string 550 | Order: 551 | properties: 552 | id: 553 | type: integer 554 | format: int64 555 | petId: 556 | type: integer 557 | format: int64 558 | quantity: 559 | type: integer 560 | format: int32 561 | shipDate: 562 | type: string 563 | format: date-time 564 | status: 565 | type: string 566 | description: Order Status 567 | complete: 568 | type: boolean 569 | -------------------------------------------------------------------------------- /src/test/resources/swagger-allOf-composition-flat.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "version": "1.0.0", 5 | "title": "Swagger Petstore API" 6 | }, 7 | "paths": { 8 | }, 9 | "definitions": { 10 | "Id": { 11 | "type": "object", 12 | "properties": { 13 | "id": { 14 | "type": "integer", 15 | "format": "int64" 16 | } 17 | } 18 | }, 19 | "AuditLog": { 20 | "type": "object", 21 | "properties": { 22 | "created": { 23 | "type": "string", 24 | "format": "date-time" 25 | }, 26 | "modified": { 27 | "type": "string", 28 | "format": "date-time" 29 | } 30 | } 31 | }, 32 | "Item": { 33 | "type": "object", 34 | "properties": { 35 | "id": { 36 | "type": "integer", 37 | "format": "int64" 38 | }, 39 | "created": { 40 | "type": "string", 41 | "format": "date-time" 42 | }, 43 | "modified": { 44 | "type": "string", 45 | "format": "date-time" 46 | }, 47 | "status": { 48 | "type": "string" 49 | } 50 | } 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /src/test/resources/swagger-allOf-composition.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "version": "1.0.0", 5 | "title": "Swagger Petstore API" 6 | }, 7 | "paths": { 8 | }, 9 | "definitions": { 10 | "Id": { 11 | "type": "object", 12 | "properties": { 13 | "id": { 14 | "type": "integer", 15 | "format": "int64" 16 | } 17 | } 18 | }, 19 | "AuditLog": { 20 | "type": "object", 21 | "properties": { 22 | "created": { 23 | "type": "string", 24 | "format": "date-time" 25 | }, 26 | "modified": { 27 | "type": "string", 28 | "format": "date-time" 29 | } 30 | } 31 | }, 32 | "Item": { 33 | "type": "object", 34 | "allOf": [ 35 | { 36 | "$ref": "#/definitions/Id" 37 | }, 38 | { 39 | "$ref": "#/definitions/AuditLog" 40 | }, 41 | { 42 | "properties": { 43 | "status": { 44 | "type": "string" 45 | } 46 | } 47 | } 48 | ] 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /src/test/resources/swagger-allOf-test-flat.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "version": "1.0.0", 5 | "title": "Swagger Petstore API" 6 | }, 7 | "paths": { 8 | }, 9 | "definitions": { 10 | "Order": { 11 | "type": "object", 12 | "properties": { 13 | "id": { 14 | "type": "integer", 15 | "format": "int64" 16 | }, 17 | "petId": { 18 | "type": "integer", 19 | "format": "int64" 20 | }, 21 | "quantity": { 22 | "type": "integer", 23 | "format": "int32" 24 | }, 25 | "shipDate": { 26 | "type": "string", 27 | "format": "date-time" 28 | }, 29 | "status": { 30 | "type": "string", 31 | "description": "Order Status" 32 | }, 33 | "complete": { 34 | "type": "boolean" 35 | } 36 | }, 37 | "required": [ 38 | "id" 39 | ] 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /src/test/resources/swagger-allOf-test-inheritance-cycles.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "version": "1.0.0", 5 | "title": "Swagger Petstore API" 6 | }, 7 | "paths": { 8 | }, 9 | "definitions": { 10 | "AbstractOrder": { 11 | "properties": { 12 | "id": { 13 | "type": "integer", 14 | "format": "int64" 15 | } 16 | }, 17 | "required": [ 18 | "id" 19 | ] 20 | }, 21 | "Order": { 22 | "type": "object", 23 | "allOf": [ 24 | { 25 | "$ref": "#/definitions/AbstractOrder" 26 | }, 27 | { 28 | "$ref": "#/definitions/Order1" 29 | } 30 | ] 31 | }, 32 | "Order1": { 33 | "allOf": [ 34 | { 35 | "$ref": "#/definitions/Order2" 36 | }, 37 | { 38 | "properties": { 39 | "petId": { 40 | "type": "integer", 41 | "format": "int64" 42 | } 43 | } 44 | } 45 | ] 46 | }, 47 | "Order2": { 48 | "allOf": [ 49 | { 50 | "$ref": "#/definitions/Order1" 51 | }, 52 | { 53 | "properties": { 54 | "quantity": { 55 | "type": "integer", 56 | "format": "int32" 57 | }, 58 | "shipDate": { 59 | "type": "string", 60 | "format": "date-time" 61 | }, 62 | "status": { 63 | "type": "string", 64 | "description": "Order Status" 65 | }, 66 | "complete": { 67 | "type": "boolean" 68 | } 69 | } 70 | } 71 | ] 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /src/test/resources/swagger-allOf-test-inheritance.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "version": "1.0.0", 5 | "title": "Swagger Petstore API" 6 | }, 7 | "paths": { 8 | }, 9 | "definitions": { 10 | "AbstractOrder": { 11 | "properties": { 12 | "id": { 13 | "type": "integer", 14 | "format": "int64" 15 | } 16 | }, 17 | "required": [ 18 | "id" 19 | ] 20 | }, 21 | "OrderBase": { 22 | "type": "object", 23 | "allOf": [ 24 | { 25 | "$ref": "#/definitions/AbstractOrder" 26 | }, 27 | { 28 | "properties": { 29 | "petId": { 30 | "type": "integer", 31 | "format": "int64" 32 | }, 33 | "quantity": { 34 | "type": "integer", 35 | "format": "int32" 36 | }, 37 | "shipDate": { 38 | "type": "string", 39 | "format": "date-time" 40 | }, 41 | "status": { 42 | "type": "string", 43 | "description": "Order Status" 44 | }, 45 | "complete": { 46 | "type": "boolean" 47 | } 48 | } 49 | } 50 | ] 51 | }, 52 | "Order": { 53 | "allOf": [ 54 | { 55 | "$ref": "#/definitions/OrderBase" 56 | }, 57 | { 58 | "type": "object" 59 | } 60 | ] 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/test/resources/swagger-bytearray-ref-wrong.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "description": "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample, you can use the api key `special-key` to test the authorization filters\n", 5 | "version": "1.0.0", 6 | "title": "Swagger Petstore", 7 | "termsOfService": "http://helloreverb.com/terms/", 8 | "contact": { 9 | "name": "apiteam@wordnik.com" 10 | }, 11 | "license": { 12 | "name": "Apache 2.0", 13 | "url": "http://www.apache.org/licenses/LICENSE-2.0.html" 14 | } 15 | }, 16 | "host": "petstore.swagger.wordnik.com", 17 | "basePath": "/v2", 18 | "schemes": [ 19 | "http" 20 | ], 21 | "paths": { 22 | "/documents/{id}": { 23 | "get": { 24 | "tags": [ 25 | "Documents" 26 | ], 27 | "summary": "Get document by id", 28 | "description": "", 29 | "operationId": "getDocumentById", 30 | "produces": [ 31 | "application/json", 32 | "application/xml" 33 | ], 34 | "parameters": [ 35 | { 36 | "in": "path", 37 | "name": "id", 38 | "description": "The document that needs to be fetched.", 39 | "required": true, 40 | "type": "string" 41 | } 42 | ], 43 | "responses": { 44 | "200": { 45 | "description": "successful operation", 46 | "schema": { 47 | "$ref": "#/definitions/Document" 48 | } 49 | }, 50 | "400": { 51 | "description": "Invalid request" 52 | }, 53 | "404": { 54 | "description": "Document not found" 55 | } 56 | } 57 | } 58 | } 59 | }, 60 | "definitions": { 61 | "Document": { 62 | "properties": { 63 | "id": { 64 | "type": "integer", 65 | "format": "int64" 66 | }, 67 | "name": { 68 | "type": "string" 69 | }, 70 | "content": { 71 | "$ref": "#/definitions/DocumentContent" 72 | } 73 | } 74 | }, 75 | "DocumentContent": { 76 | "description": "Document content", 77 | "type": "string" 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/test/resources/swagger-bytearray-ref.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "description": "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample, you can use the api key `special-key` to test the authorization filters\n", 5 | "version": "1.0.0", 6 | "title": "Swagger Petstore", 7 | "termsOfService": "http://helloreverb.com/terms/", 8 | "contact": { 9 | "name": "apiteam@wordnik.com" 10 | }, 11 | "license": { 12 | "name": "Apache 2.0", 13 | "url": "http://www.apache.org/licenses/LICENSE-2.0.html" 14 | } 15 | }, 16 | "host": "petstore.swagger.wordnik.com", 17 | "basePath": "/v2", 18 | "schemes": [ 19 | "http" 20 | ], 21 | "paths": { 22 | "/documents/{id}": { 23 | "get": { 24 | "tags": [ 25 | "Documents" 26 | ], 27 | "summary": "Get document by id", 28 | "description": "", 29 | "operationId": "getDocumentById", 30 | "produces": [ 31 | "application/json", 32 | "application/xml" 33 | ], 34 | "parameters": [ 35 | { 36 | "in": "path", 37 | "name": "id", 38 | "description": "The document that needs to be fetched.", 39 | "required": true, 40 | "type": "string" 41 | } 42 | ], 43 | "responses": { 44 | "200": { 45 | "description": "successful operation", 46 | "schema": { 47 | "$ref": "#/definitions/Document" 48 | } 49 | }, 50 | "400": { 51 | "description": "Invalid request" 52 | }, 53 | "404": { 54 | "description": "Document not found" 55 | } 56 | } 57 | } 58 | } 59 | }, 60 | "definitions": { 61 | "Document": { 62 | "properties": { 63 | "id": { 64 | "type": "integer", 65 | "format": "int64" 66 | }, 67 | "name": { 68 | "type": "string" 69 | }, 70 | "content": { 71 | "$ref": "#/definitions/DocumentContent" 72 | } 73 | } 74 | }, 75 | "DocumentContent": { 76 | "description": "Document content", 77 | "type": "string", 78 | "format": "byte" 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/test/resources/swagger-bytearray-ref.yaml: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "description": "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample, you can use the api key `special-key` to test the authorization filters\n", 5 | "version": "1.0.0", 6 | "title": "Swagger Petstore", 7 | "termsOfService": "http://helloreverb.com/terms/", 8 | "contact": { 9 | "name": "apiteam@wordnik.com" 10 | }, 11 | "license": { 12 | "name": "Apache 2.0", 13 | "url": "http://www.apache.org/licenses/LICENSE-2.0.html" 14 | } 15 | }, 16 | "host": "petstore.swagger.wordnik.com", 17 | "basePath": "/v2", 18 | "schemes": [ 19 | "http" 20 | ], 21 | "paths": { 22 | "/documents/{id}": { 23 | "get": { 24 | "tags": [ 25 | "Documents" 26 | ], 27 | "summary": "Get document by id", 28 | "description": "", 29 | "operationId": "getDocumentById", 30 | "produces": [ 31 | "application/json", 32 | "application/xml" 33 | ], 34 | "parameters": [ 35 | { 36 | "in": "path", 37 | "name": "id", 38 | "description": "The document that needs to be fetched.", 39 | "required": true, 40 | "type": "string" 41 | } 42 | ], 43 | "responses": { 44 | "200": { 45 | "description": "successful operation", 46 | "schema": { 47 | "$ref": "#/definitions/Document" 48 | } 49 | }, 50 | "400": { 51 | "description": "Invalid request" 52 | }, 53 | "404": { 54 | "description": "Document not found" 55 | } 56 | } 57 | } 58 | } 59 | }, 60 | "definitions": { 61 | "Document": { 62 | "properties": { 63 | "id": { 64 | "type": "integer", 65 | "format": "int64" 66 | }, 67 | "name": { 68 | "type": "string" 69 | }, 70 | "content": { 71 | "$ref": "#/definitions/DocumentContent" 72 | } 73 | } 74 | }, 75 | "DocumentContent": { 76 | "description": "Document content", 77 | "type": "string", 78 | "format": "byte" 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/test/resources/swagger-bytearray-wrong.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "description": "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample, you can use the api key `special-key` to test the authorization filters\n", 5 | "version": "1.0.0", 6 | "title": "Swagger Petstore", 7 | "termsOfService": "http://helloreverb.com/terms/", 8 | "contact": { 9 | "name": "apiteam@wordnik.com" 10 | }, 11 | "license": { 12 | "name": "Apache 2.0", 13 | "url": "http://www.apache.org/licenses/LICENSE-2.0.html" 14 | } 15 | }, 16 | "host": "petstore.swagger.wordnik.com", 17 | "basePath": "/v2", 18 | "schemes": [ 19 | "http" 20 | ], 21 | "paths": { 22 | "/documents/{id}": { 23 | "get": { 24 | "tags": [ 25 | "Documents" 26 | ], 27 | "summary": "Get document by id", 28 | "description": "", 29 | "operationId": "getDocumentById", 30 | "produces": [ 31 | "application/json", 32 | "application/xml" 33 | ], 34 | "parameters": [ 35 | { 36 | "in": "path", 37 | "name": "id", 38 | "description": "The document that needs to be fetched.", 39 | "required": true, 40 | "type": "string" 41 | } 42 | ], 43 | "responses": { 44 | "200": { 45 | "description": "successful operation", 46 | "schema": { 47 | "$ref": "#/definitions/Document" 48 | } 49 | }, 50 | "400": { 51 | "description": "Invalid request" 52 | }, 53 | "404": { 54 | "description": "Document not found" 55 | } 56 | } 57 | } 58 | } 59 | }, 60 | "definitions": { 61 | "Document": { 62 | "properties": { 63 | "id": { 64 | "type": "integer", 65 | "format": "int64" 66 | }, 67 | "name": { 68 | "type": "string" 69 | }, 70 | "content": { 71 | "description": "Document content", 72 | "type": "string" 73 | } 74 | } 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/test/resources/swagger-bytearray.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "description": "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample, you can use the api key `special-key` to test the authorization filters\n", 5 | "version": "1.0.0", 6 | "title": "Swagger Petstore", 7 | "termsOfService": "http://helloreverb.com/terms/", 8 | "contact": { 9 | "name": "apiteam@wordnik.com" 10 | }, 11 | "license": { 12 | "name": "Apache 2.0", 13 | "url": "http://www.apache.org/licenses/LICENSE-2.0.html" 14 | } 15 | }, 16 | "host": "petstore.swagger.wordnik.com", 17 | "basePath": "/v2", 18 | "schemes": [ 19 | "http" 20 | ], 21 | "paths": { 22 | "/documents/{id}": { 23 | "get": { 24 | "tags": [ 25 | "Documents" 26 | ], 27 | "summary": "Get document by id", 28 | "description": "", 29 | "operationId": "getDocumentById", 30 | "produces": [ 31 | "application/json", 32 | "application/xml" 33 | ], 34 | "parameters": [ 35 | { 36 | "in": "path", 37 | "name": "id", 38 | "description": "The document that needs to be fetched.", 39 | "required": true, 40 | "type": "string" 41 | } 42 | ], 43 | "responses": { 44 | "200": { 45 | "description": "successful operation", 46 | "schema": { 47 | "$ref": "#/definitions/Document" 48 | } 49 | }, 50 | "400": { 51 | "description": "Invalid request" 52 | }, 53 | "404": { 54 | "description": "Document not found" 55 | } 56 | } 57 | } 58 | } 59 | }, 60 | "definitions": { 61 | "Document": { 62 | "properties": { 63 | "id": { 64 | "type": "integer", 65 | "format": "int64" 66 | }, 67 | "name": { 68 | "type": "string" 69 | }, 70 | "content": { 71 | "description": "Document content", 72 | "type": "string", 73 | "format": "byte" 74 | } 75 | } 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/test/resources/swagger-bytearray.yaml: -------------------------------------------------------------------------------- 1 | swagger: "2.0" 2 | info: 3 | description: | 4 | This is a sample server Petstore server. 5 | 6 | [Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net. 7 | 8 | For this sample, you can use the api key `special-key` to test the authorization filters 9 | version: "1.0.0" 10 | title: Swagger Petstore 11 | termsOfService: http://helloreverb.com/terms/ 12 | contact: 13 | name: apiteam@wordnik.com 14 | license: 15 | name: Apache 2.0 16 | url: http://www.apache.org/licenses/LICENSE-2.0.html 17 | host: petstore.swagger.wordnik.com 18 | basePath: /v2 19 | schemes: 20 | - http 21 | paths: 22 | /documents/{id}: 23 | get: 24 | tags: 25 | - Documents 26 | summary: Get document by id 27 | description: "" 28 | operationId: getDocumentById 29 | produces: 30 | - application/json 31 | - application/xml 32 | parameters: 33 | - in: path 34 | name: id 35 | description: The document that needs to be fetched. 36 | required: true 37 | type: string 38 | responses: 39 | "404": 40 | description: Document not found 41 | "200": 42 | description: successful operation 43 | schema: 44 | $ref: "#/definitions/Document" 45 | "400": 46 | description: Invalid request 47 | definitions: 48 | Document: 49 | properties: 50 | id: 51 | type: integer 52 | format: int64 53 | name: 54 | type: string 55 | content: 56 | description: 'Document content' 57 | type: string 58 | format: byte 59 | -------------------------------------------------------------------------------- /src/test/resources/swagger-enum-ref-wrong.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "description": "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample, you can use the api key `special-key` to test the authorization filters\n", 5 | "version": "1.0.0", 6 | "title": "Swagger Petstore", 7 | "termsOfService": "http://helloreverb.com/terms/", 8 | "contact": { 9 | "name": "apiteam@wordnik.com" 10 | }, 11 | "license": { 12 | "name": "Apache 2.0", 13 | "url": "http://www.apache.org/licenses/LICENSE-2.0.html" 14 | } 15 | }, 16 | "host": "petstore.swagger.wordnik.com", 17 | "basePath": "/v2", 18 | "schemes": [ 19 | "http" 20 | ], 21 | "paths": { 22 | "/users/{username}": { 23 | "get": { 24 | "tags": [ 25 | "user" 26 | ], 27 | "summary": "Get user by user name", 28 | "description": "", 29 | "operationId": "getUserByName", 30 | "produces": [ 31 | "application/json", 32 | "application/xml" 33 | ], 34 | "parameters": [ 35 | { 36 | "in": "path", 37 | "name": "username", 38 | "description": "The name that needs to be fetched. Use user1 for testing.", 39 | "required": true, 40 | "type": "string" 41 | } 42 | ], 43 | "responses": { 44 | "200": { 45 | "description": "successful operation", 46 | "schema": { 47 | "$ref": "#/definitions/User" 48 | } 49 | }, 50 | "400": { 51 | "description": "Invalid username supplied" 52 | }, 53 | "404": { 54 | "description": "User not found" 55 | } 56 | } 57 | } 58 | } 59 | }, 60 | "definitions": { 61 | "User": { 62 | "properties": { 63 | "id": { 64 | "type": "integer", 65 | "format": "int64" 66 | }, 67 | "username": { 68 | "type": "string" 69 | }, 70 | "role": { 71 | "$ref": "#/definitions/Role" 72 | } 73 | } 74 | }, 75 | "Role": { 76 | "description": "type: string enum: [ADMIN, USER, AUDITOR_WRONG]", 77 | "type": "string", 78 | "enum": [ 79 | "ADMIN", 80 | "USER", 81 | "AUDITOR_WRONG" 82 | ] 83 | } 84 | } 85 | } -------------------------------------------------------------------------------- /src/test/resources/swagger-enum-ref.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "description": "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample, you can use the api key `special-key` to test the authorization filters\n", 5 | "version": "1.0.0", 6 | "title": "Swagger Petstore", 7 | "termsOfService": "http://helloreverb.com/terms/", 8 | "contact": { 9 | "name": "apiteam@wordnik.com" 10 | }, 11 | "license": { 12 | "name": "Apache 2.0", 13 | "url": "http://www.apache.org/licenses/LICENSE-2.0.html" 14 | } 15 | }, 16 | "host": "petstore.swagger.wordnik.com", 17 | "basePath": "/v2", 18 | "schemes": [ 19 | "http" 20 | ], 21 | "paths": { 22 | "/users/{username}": { 23 | "get": { 24 | "tags": [ 25 | "user" 26 | ], 27 | "summary": "Get user by user name", 28 | "description": "", 29 | "operationId": "getUserByName", 30 | "produces": [ 31 | "application/json", 32 | "application/xml" 33 | ], 34 | "parameters": [ 35 | { 36 | "in": "path", 37 | "name": "username", 38 | "description": "The name that needs to be fetched. Use user1 for testing.", 39 | "required": true, 40 | "type": "string" 41 | } 42 | ], 43 | "responses": { 44 | "200": { 45 | "description": "successful operation", 46 | "schema": { 47 | "$ref": "#/definitions/User" 48 | } 49 | }, 50 | "400": { 51 | "description": "Invalid username supplied" 52 | }, 53 | "404": { 54 | "description": "User not found" 55 | } 56 | } 57 | } 58 | } 59 | }, 60 | "definitions": { 61 | "User": { 62 | "properties": { 63 | "id": { 64 | "type": "integer", 65 | "format": "int64" 66 | }, 67 | "username": { 68 | "type": "string" 69 | }, 70 | "role": { 71 | "$ref": "#/definitions/Role" 72 | } 73 | } 74 | }, 75 | "Role": { 76 | "description": "type: string enum: [ADMIN, USER, AUDITOR]", 77 | "type": "string", 78 | "enum": [ 79 | "ADMIN", 80 | "USER", 81 | "AUDITOR" 82 | ] 83 | } 84 | } 85 | } -------------------------------------------------------------------------------- /src/test/resources/swagger-enum-ref.yaml: -------------------------------------------------------------------------------- 1 | swagger: "2.0" 2 | info: 3 | description: | 4 | This is a sample server Petstore server. 5 | 6 | [Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net. 7 | 8 | For this sample, you can use the api key `special-key` to test the authorization filters 9 | version: "1.0.0" 10 | title: Swagger Petstore 11 | termsOfService: http://helloreverb.com/terms/ 12 | contact: 13 | name: apiteam@wordnik.com 14 | license: 15 | name: Apache 2.0 16 | url: http://www.apache.org/licenses/LICENSE-2.0.html 17 | host: petstore.swagger.wordnik.com 18 | basePath: /v2 19 | schemes: 20 | - http 21 | paths: 22 | /users/{username}: 23 | get: 24 | tags: 25 | - user 26 | summary: Get user by user name 27 | description: "" 28 | operationId: getUserByName 29 | produces: 30 | - application/json 31 | - application/xml 32 | parameters: 33 | - in: path 34 | name: username 35 | description: The name that needs to be fetched. Use user1 for testing. 36 | required: true 37 | type: string 38 | responses: 39 | "404": 40 | description: User not found 41 | "200": 42 | description: successful operation 43 | schema: 44 | $ref: "#/definitions/User" 45 | "400": 46 | description: Invalid username supplied 47 | definitions: 48 | User: 49 | properties: 50 | id: 51 | type: integer 52 | format: int64 53 | username: 54 | type: string 55 | role: 56 | $ref: '#/definitions/Role' 57 | Role: 58 | description: 'type: string enum: [ADMIN, USER, AUDITOR]' 59 | type: string 60 | enum: 61 | - ADMIN 62 | - USER 63 | - AUDITOR 64 | 65 | -------------------------------------------------------------------------------- /src/test/resources/swagger-no-definitions.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "description": "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample, you can use the api key `special-key` to test the authorization filters\n", 5 | "version": "1.0.0", 6 | "title": "Swagger Petstore API", 7 | "termsOfService": "http://helloreverb.com/terms/", 8 | "contact": { 9 | "name": "apiteam@wordnik.com" 10 | }, 11 | "license": { 12 | "name": "Apache 2.0", 13 | "url": "http://www.apache.org/licenses/LICENSE-2.0.html" 14 | } 15 | }, 16 | "host": "petstore.swagger.wordnik.com", 17 | "basePath": "/v2", 18 | "schemes": [ 19 | "http" 20 | ], 21 | "paths": { 22 | "/pets/{petId}": { 23 | "delete": { 24 | "tags": [ 25 | "pet" 26 | ], 27 | "summary": "Deletes a pet", 28 | "description": "", 29 | "operationId": "deletePet", 30 | "produces": [ 31 | "application/json", 32 | "application/xml" 33 | ], 34 | "parameters": [ 35 | { 36 | "in": "header", 37 | "name": "api_key", 38 | "description": "", 39 | "required": true, 40 | "type": "string" 41 | }, 42 | { 43 | "in": "path", 44 | "name": "petId", 45 | "description": "Pet id to delete", 46 | "required": true, 47 | "type": "integer", 48 | "format": "int64" 49 | } 50 | ], 51 | "responses": { 52 | "400": { 53 | "description": "Invalid pet value" 54 | } 55 | }, 56 | "security": [ 57 | { 58 | "petstore_auth": [ 59 | "write_pets", 60 | "read_pets" 61 | ] 62 | } 63 | ] 64 | } 65 | } 66 | }, 67 | "securityDefinitions": { 68 | "api_key": { 69 | "type": "apiKey", 70 | "name": "api_key", 71 | "in": "header" 72 | }, 73 | "petstore_auth": { 74 | "type": "oauth2", 75 | "authorizationUrl": "http://petstore.swagger.wordnik.com/api/oauth/dialog", 76 | "flow": "implicit", 77 | "scopes": { 78 | "write_pets": "modify pets in your account", 79 | "read_pets": "read your pets" 80 | } 81 | } 82 | }, 83 | "definitions": { 84 | } 85 | } -------------------------------------------------------------------------------- /src/test/resources/swagger-path-without-some-operations.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "description": "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample, you can use the api key `special-key` to test the authorization filters\n", 5 | "version": "1.0.0", 6 | "title": "Swagger Petstore API", 7 | "termsOfService": "http://helloreverb.com/terms/", 8 | "contact": { 9 | "name": "apiteam@wordnik.com" 10 | }, 11 | "license": { 12 | "name": "Apache 2.0", 13 | "url": "http://www.apache.org/licenses/LICENSE-2.0.html" 14 | } 15 | }, 16 | "host": "petstore.swagger.wordnik.com", 17 | "basePath": "/v2", 18 | "schemes": [ 19 | "http" 20 | ], 21 | "paths": { 22 | "/pets/{petId}": { 23 | "get": { 24 | "tags": [ 25 | "pet" 26 | ], 27 | "summary": "Find pet by ID", 28 | "description": "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions", 29 | "operationId": "getPetById", 30 | "produces": [ 31 | "application/json", 32 | "application/xml" 33 | ], 34 | "parameters": [ 35 | { 36 | "in": "path", 37 | "name": "petId", 38 | "description": "ID of pet that needs to be fetched", 39 | "required": true, 40 | "type": "integer", 41 | "format": "int64" 42 | } 43 | ], 44 | "responses": { 45 | "200": { 46 | "description": "successful operation", 47 | "schema": { 48 | "$ref": "#/definitions/Pet" 49 | } 50 | }, 51 | "400": { 52 | "description": "Invalid ID supplied" 53 | }, 54 | "404": { 55 | "description": "Pet not found" 56 | } 57 | }, 58 | "security": [ 59 | { 60 | "api_key": [] 61 | }, 62 | { 63 | "petstore_auth": [ 64 | "write_pets", 65 | "read_pets" 66 | ] 67 | } 68 | ] 69 | } 70 | } 71 | }, 72 | "securityDefinitions": { 73 | "api_key": { 74 | "type": "apiKey", 75 | "name": "api_key", 76 | "in": "header" 77 | }, 78 | "petstore_auth": { 79 | "type": "oauth2", 80 | "authorizationUrl": "http://petstore.swagger.wordnik.com/api/oauth/dialog", 81 | "flow": "implicit", 82 | "scopes": { 83 | "write_pets": "modify pets in your account", 84 | "read_pets": "read your pets" 85 | } 86 | } 87 | }, 88 | "definitions": { 89 | "User": { 90 | "properties": { 91 | "id": { 92 | "type": "integer", 93 | "format": "int64" 94 | }, 95 | "username": { 96 | "type": "string" 97 | }, 98 | "firstName": { 99 | "type": "string" 100 | }, 101 | "lastName": { 102 | "type": "string" 103 | }, 104 | "email": { 105 | "type": "string" 106 | }, 107 | "password": { 108 | "type": "string" 109 | }, 110 | "phone": { 111 | "type": "string" 112 | }, 113 | "userStatus": { 114 | "type": "integer", 115 | "format": "int32", 116 | "description": "User Status" 117 | } 118 | } 119 | }, 120 | "Category": { 121 | "properties": { 122 | "id": { 123 | "type": "integer", 124 | "format": "int64" 125 | }, 126 | "name": { 127 | "type": "string" 128 | } 129 | } 130 | }, 131 | "Pet": { 132 | "description": "Test description", 133 | "required": [ 134 | "name", 135 | "photoUrls" 136 | ], 137 | "properties": { 138 | "id": { 139 | "type": "integer", 140 | "format": "int64" 141 | }, 142 | "category": { 143 | "$ref": "#/definitions/Category" 144 | }, 145 | "name": { 146 | "type": "string", 147 | "example": "doggie" 148 | }, 149 | "photoUrls": { 150 | "type": "array", 151 | "items": { 152 | "type": "string" 153 | } 154 | }, 155 | "tags": { 156 | "type": "array", 157 | "items": { 158 | "$ref": "#/definitions/Tag" 159 | } 160 | }, 161 | "status": { 162 | "type": "string", 163 | "description": "pet status in the store" 164 | } 165 | } 166 | }, 167 | "Tag": { 168 | "properties": { 169 | "id": { 170 | "type": "integer", 171 | "format": "int64" 172 | }, 173 | "name": { 174 | "type": "string" 175 | } 176 | } 177 | }, 178 | "Order": { 179 | "properties": { 180 | "id": { 181 | "type": "integer", 182 | "format": "int64" 183 | }, 184 | "petId": { 185 | "type": "integer", 186 | "format": "int64" 187 | }, 188 | "quantity": { 189 | "type": "integer", 190 | "format": "int32" 191 | }, 192 | "shipDate": { 193 | "type": "string", 194 | "format": "date-time" 195 | }, 196 | "status": { 197 | "type": "string", 198 | "description": "Order Status" 199 | }, 200 | "complete": { 201 | "type": "boolean" 202 | } 203 | } 204 | } 205 | } 206 | } 207 | -------------------------------------------------------------------------------- /src/test/resources/swagger-singleresource-extramethod.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "description": "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample, you can use the api key `special-key` to test the authorization filters\n", 5 | "version": "1.0.0", 6 | "title": "Swagger Petstore API", 7 | "termsOfService": "http://helloreverb.com/terms/", 8 | "contact": { 9 | "name": "apiteam@wordnik.com" 10 | }, 11 | "license": { 12 | "name": "Apache 2.0", 13 | "url": "http://www.apache.org/licenses/LICENSE-2.0.html" 14 | } 15 | }, 16 | "host": "petstore.swagger.wordnik.com", 17 | "basePath": "/v2", 18 | "schemes": [ 19 | "http" 20 | ], 21 | "paths": { 22 | "/pets": { 23 | "post": { 24 | "tags": [ 25 | "pet" 26 | ], 27 | "summary": "Add a new pet to the store", 28 | "description": "", 29 | "operationId": "addPet", 30 | "consumes": [ 31 | "application/json" 32 | ], 33 | "produces": [ 34 | "application/json" 35 | ], 36 | "parameters": [ 37 | { 38 | "in": "body", 39 | "name": "body", 40 | "description": "Pet object that needs to be added to the store", 41 | "required": false, 42 | "schema": { 43 | "$ref": "#/definitions/Pet" 44 | } 45 | } 46 | ], 47 | "responses": { 48 | "405": { 49 | "description": "Invalid input" 50 | } 51 | }, 52 | "security": [ 53 | { 54 | "petstore_auth": [ 55 | "write_pets", 56 | "read_pets" 57 | ] 58 | } 59 | ] 60 | }, 61 | "put": { 62 | "tags": [ 63 | "pet" 64 | ], 65 | "summary": "Update an existing pet", 66 | "description": "", 67 | "operationId": "updatePet", 68 | "consumes": [ 69 | "application/json", 70 | "application/xml" 71 | ], 72 | "produces": [ 73 | "application/json", 74 | "application/xml" 75 | ], 76 | "parameters": [ 77 | { 78 | "in": "body", 79 | "name": "body", 80 | "description": "Pet object that needs to be added to the store", 81 | "required": false, 82 | "schema": { 83 | "$ref": "#/definitions/Pet" 84 | } 85 | } 86 | ], 87 | "responses": { 88 | "400": { 89 | "description": "Invalid ID supplied" 90 | }, 91 | "404": { 92 | "description": "Pet not found" 93 | }, 94 | "405": { 95 | "description": "Validation exception" 96 | } 97 | }, 98 | "security": [ 99 | { 100 | "petstore_auth": [ 101 | "write_pets", 102 | "read_pets" 103 | ] 104 | } 105 | ] 106 | } 107 | }, 108 | "/pets/findByStatus": { 109 | "get": { 110 | "tags": [ 111 | "pet" 112 | ], 113 | "summary": "Finds Pets by status", 114 | "description": "Multiple status values can be provided with comma seperated strings", 115 | "operationId": "findPetsByStatus", 116 | "produces": [ 117 | "application/json" 118 | ], 119 | "parameters": [ 120 | { 121 | "in": "query", 122 | "name": "status", 123 | "description": "Status values that need to be considered for filter", 124 | "required": false, 125 | "type": "array", 126 | "items": { 127 | "type": "string" 128 | }, 129 | "collectionFormat": "multi" 130 | } 131 | ], 132 | "responses": { 133 | "200": { 134 | "description": "successful operation", 135 | "schema": { 136 | "type": "array", 137 | "items": { 138 | "$ref": "#/definitions/Pet" 139 | } 140 | } 141 | }, 142 | "400": { 143 | "description": "Invalid status value" 144 | } 145 | }, 146 | "security": [ 147 | { 148 | "petstore_auth": [ 149 | "write_pets", 150 | "read_pets" 151 | ] 152 | } 153 | ] 154 | } 155 | }, 156 | "/pets/findByTag": { 157 | "get": { 158 | "tags": [ 159 | "pet" 160 | ], 161 | "summary": "Finds Pets by tag", 162 | "description": "Resource method that does not exist in implementation", 163 | "operationId": "findPetsByStatus", 164 | "produces": [ 165 | "application/json" 166 | ], 167 | "parameters": [ 168 | { 169 | "in": "query", 170 | "name": "tag", 171 | "description": "Tag values that need to be considered for filter", 172 | "required": false, 173 | "type": "array", 174 | "items": { 175 | "type": "string" 176 | }, 177 | "collectionFormat": "multi" 178 | } 179 | ], 180 | "responses": { 181 | "200": { 182 | "description": "successful operation", 183 | "schema": { 184 | "type": "array", 185 | "items": { 186 | "$ref": "#/definitions/Pet" 187 | } 188 | } 189 | }, 190 | "400": { 191 | "description": "Invalid tag value" 192 | } 193 | }, 194 | "security": [ 195 | { 196 | "petstore_auth": [ 197 | "write_pets", 198 | "read_pets" 199 | ] 200 | } 201 | ] 202 | } 203 | }, 204 | "/pets/{petId}": { 205 | "get": { 206 | "tags": [ 207 | "pet" 208 | ], 209 | "summary": "Find pet by ID", 210 | "description": "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions", 211 | "operationId": "getPetById", 212 | "produces": [ 213 | "application/json" 214 | ], 215 | "parameters": [ 216 | { 217 | "in": "path", 218 | "name": "petId", 219 | "description": "ID of pet that needs to be fetched", 220 | "required": true, 221 | "type": "integer", 222 | "format": "int64" 223 | } 224 | ], 225 | "responses": { 226 | "200": { 227 | "description": "successful operation", 228 | "schema": { 229 | "$ref": "#/definitions/Pet" 230 | } 231 | }, 232 | "400": { 233 | "description": "Invalid ID supplied" 234 | }, 235 | "404": { 236 | "description": "Pet not found" 237 | } 238 | }, 239 | "security": [ 240 | { 241 | "api_key": [] 242 | }, 243 | { 244 | "petstore_auth": [ 245 | "write_pets", 246 | "read_pets" 247 | ] 248 | } 249 | ] 250 | }, 251 | "post": { 252 | "tags": [ 253 | "pet" 254 | ], 255 | "summary": "Updates a pet in the store with form data", 256 | "description": "", 257 | "operationId": "updatePetWithForm", 258 | "consumes": [ 259 | "application/x-www-form-urlencoded" 260 | ], 261 | "produces": [ 262 | "application/json" 263 | ], 264 | "parameters": [ 265 | { 266 | "in": "path", 267 | "name": "petId", 268 | "description": "ID of pet that needs to be updated", 269 | "required": true, 270 | "type": "string" 271 | }, 272 | { 273 | "in": "formData", 274 | "name": "name", 275 | "description": "Updated name of the pet", 276 | "required": true, 277 | "type": "string" 278 | }, 279 | { 280 | "in": "formData", 281 | "name": "status", 282 | "description": "Updated status of the pet", 283 | "required": true, 284 | "type": "string" 285 | } 286 | ], 287 | "responses": { 288 | "405": { 289 | "description": "Invalid input" 290 | } 291 | }, 292 | "security": [ 293 | { 294 | "petstore_auth": [ 295 | "write_pets", 296 | "read_pets" 297 | ] 298 | } 299 | ] 300 | }, 301 | "delete": { 302 | "tags": [ 303 | "pet" 304 | ], 305 | "summary": "Deletes a pet", 306 | "description": "", 307 | "operationId": "deletePet", 308 | "produces": [ 309 | "application/json", 310 | "application/xml" 311 | ], 312 | "parameters": [ 313 | { 314 | "in": "header", 315 | "name": "api_key", 316 | "description": "", 317 | "required": true, 318 | "type": "string" 319 | }, 320 | { 321 | "in": "path", 322 | "name": "petId", 323 | "description": "Pet id to delete", 324 | "required": true, 325 | "type": "integer", 326 | "format": "int64" 327 | } 328 | ], 329 | "responses": { 330 | "400": { 331 | "description": "Invalid pet value" 332 | } 333 | }, 334 | "security": [ 335 | { 336 | "petstore_auth": [ 337 | "write_pets", 338 | "read_pets" 339 | ] 340 | } 341 | ] 342 | } 343 | } 344 | }, 345 | "securityDefinitions": { 346 | "api_key": { 347 | "type": "apiKey", 348 | "name": "api_key", 349 | "in": "header" 350 | }, 351 | "petstore_auth": { 352 | "type": "oauth2", 353 | "authorizationUrl": "http://petstore.swagger.wordnik.com/api/oauth/dialog", 354 | "flow": "implicit", 355 | "scopes": { 356 | "write_pets": "modify pets in your account", 357 | "read_pets": "read your pets" 358 | } 359 | } 360 | }, 361 | "definitions": { 362 | "Category": { 363 | "properties": { 364 | "id": { 365 | "type": "integer", 366 | "format": "int64" 367 | }, 368 | "name": { 369 | "type": "string" 370 | } 371 | } 372 | }, 373 | "Pet": { 374 | "description": "Test description", 375 | "required": [ 376 | "name", 377 | "photoUrls" 378 | ], 379 | "properties": { 380 | "id": { 381 | "type": "integer", 382 | "format": "int64" 383 | }, 384 | "category": { 385 | "$ref": "#/definitions/Category" 386 | }, 387 | "name": { 388 | "type": "string", 389 | "example": "doggie" 390 | }, 391 | "photoUrls": { 392 | "type": "array", 393 | "items": { 394 | "type": "string" 395 | } 396 | }, 397 | "status": { 398 | "type": "string", 399 | "description": "pet status in the store" 400 | } 401 | } 402 | } 403 | } 404 | } 405 | -------------------------------------------------------------------------------- /src/test/resources/swagger-singleresource-extraproperty.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "description": "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample, you can use the api key `special-key` to test the authorization filters\n", 5 | "version": "1.0.0", 6 | "title": "Swagger Petstore API", 7 | "termsOfService": "http://helloreverb.com/terms/", 8 | "contact": { 9 | "name": "apiteam@wordnik.com" 10 | }, 11 | "license": { 12 | "name": "Apache 2.0", 13 | "url": "http://www.apache.org/licenses/LICENSE-2.0.html" 14 | } 15 | }, 16 | "host": "petstore.swagger.wordnik.com", 17 | "basePath": "/v2", 18 | "schemes": [ 19 | "http" 20 | ], 21 | "paths": { 22 | "/pets": { 23 | "post": { 24 | "tags": [ 25 | "pet" 26 | ], 27 | "summary": "Add a new pet to the store", 28 | "description": "", 29 | "operationId": "addPet", 30 | "consumes": [ 31 | "application/json" 32 | ], 33 | "produces": [ 34 | "application/json" 35 | ], 36 | "parameters": [ 37 | { 38 | "in": "body", 39 | "name": "body", 40 | "description": "Pet object that needs to be added to the store", 41 | "required": false, 42 | "schema": { 43 | "$ref": "#/definitions/Pet" 44 | } 45 | } 46 | ], 47 | "responses": { 48 | "405": { 49 | "description": "Invalid input" 50 | } 51 | }, 52 | "security": [ 53 | { 54 | "petstore_auth": [ 55 | "write_pets", 56 | "read_pets" 57 | ] 58 | } 59 | ] 60 | }, 61 | "put": { 62 | "tags": [ 63 | "pet" 64 | ], 65 | "summary": "Update an existing pet", 66 | "description": "", 67 | "operationId": "updatePet", 68 | "consumes": [ 69 | "application/json", 70 | "application/xml" 71 | ], 72 | "produces": [ 73 | "application/json", 74 | "application/xml" 75 | ], 76 | "parameters": [ 77 | { 78 | "in": "body", 79 | "name": "body", 80 | "description": "Pet object that needs to be added to the store", 81 | "required": false, 82 | "schema": { 83 | "$ref": "#/definitions/Pet" 84 | } 85 | } 86 | ], 87 | "responses": { 88 | "400": { 89 | "description": "Invalid ID supplied" 90 | }, 91 | "404": { 92 | "description": "Pet not found" 93 | }, 94 | "405": { 95 | "description": "Validation exception" 96 | } 97 | }, 98 | "security": [ 99 | { 100 | "petstore_auth": [ 101 | "write_pets", 102 | "read_pets" 103 | ] 104 | } 105 | ] 106 | } 107 | }, 108 | "/pets/findByStatus": { 109 | "get": { 110 | "tags": [ 111 | "pet" 112 | ], 113 | "summary": "Finds Pets by status", 114 | "description": "Multiple status values can be provided with comma seperated strings", 115 | "operationId": "findPetsByStatus", 116 | "produces": [ 117 | "application/json" 118 | ], 119 | "parameters": [ 120 | { 121 | "in": "query", 122 | "name": "status", 123 | "description": "Status values that need to be considered for filter", 124 | "required": false, 125 | "type": "array", 126 | "items": { 127 | "type": "string" 128 | }, 129 | "collectionFormat": "multi" 130 | } 131 | ], 132 | "responses": { 133 | "200": { 134 | "description": "successful operation", 135 | "schema": { 136 | "type": "array", 137 | "items": { 138 | "$ref": "#/definitions/Pet" 139 | } 140 | } 141 | }, 142 | "400": { 143 | "description": "Invalid status value" 144 | } 145 | }, 146 | "security": [ 147 | { 148 | "petstore_auth": [ 149 | "write_pets", 150 | "read_pets" 151 | ] 152 | } 153 | ] 154 | } 155 | }, 156 | "/pets/{petId}": { 157 | "get": { 158 | "tags": [ 159 | "pet" 160 | ], 161 | "summary": "Find pet by ID", 162 | "description": "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions", 163 | "operationId": "getPetById", 164 | "produces": [ 165 | "application/json" 166 | ], 167 | "parameters": [ 168 | { 169 | "in": "path", 170 | "name": "petId", 171 | "description": "ID of pet that needs to be fetched", 172 | "required": true, 173 | "type": "integer", 174 | "format": "int64" 175 | } 176 | ], 177 | "responses": { 178 | "200": { 179 | "description": "successful operation", 180 | "schema": { 181 | "$ref": "#/definitions/Pet" 182 | } 183 | }, 184 | "400": { 185 | "description": "Invalid ID supplied" 186 | }, 187 | "404": { 188 | "description": "Pet not found" 189 | } 190 | }, 191 | "security": [ 192 | { 193 | "api_key": [] 194 | }, 195 | { 196 | "petstore_auth": [ 197 | "write_pets", 198 | "read_pets" 199 | ] 200 | } 201 | ] 202 | }, 203 | "post": { 204 | "tags": [ 205 | "pet" 206 | ], 207 | "summary": "Updates a pet in the store with form data", 208 | "description": "", 209 | "operationId": "updatePetWithForm", 210 | "consumes": [ 211 | "application/x-www-form-urlencoded" 212 | ], 213 | "produces": [ 214 | "application/json" 215 | ], 216 | "parameters": [ 217 | { 218 | "in": "path", 219 | "name": "petId", 220 | "description": "ID of pet that needs to be updated", 221 | "required": true, 222 | "type": "string" 223 | }, 224 | { 225 | "in": "formData", 226 | "name": "name", 227 | "description": "Updated name of the pet", 228 | "required": true, 229 | "type": "string" 230 | }, 231 | { 232 | "in": "formData", 233 | "name": "status", 234 | "description": "Updated status of the pet", 235 | "required": true, 236 | "type": "string" 237 | } 238 | ], 239 | "responses": { 240 | "405": { 241 | "description": "Invalid input" 242 | } 243 | }, 244 | "security": [ 245 | { 246 | "petstore_auth": [ 247 | "write_pets", 248 | "read_pets" 249 | ] 250 | } 251 | ] 252 | }, 253 | "delete": { 254 | "tags": [ 255 | "pet" 256 | ], 257 | "summary": "Deletes a pet", 258 | "description": "", 259 | "operationId": "deletePet", 260 | "produces": [ 261 | "application/json", 262 | "application/xml" 263 | ], 264 | "parameters": [ 265 | { 266 | "in": "header", 267 | "name": "api_key", 268 | "description": "", 269 | "required": true, 270 | "type": "string" 271 | }, 272 | { 273 | "in": "path", 274 | "name": "petId", 275 | "description": "Pet id to delete", 276 | "required": true, 277 | "type": "integer", 278 | "format": "int64" 279 | } 280 | ], 281 | "responses": { 282 | "400": { 283 | "description": "Invalid pet value" 284 | } 285 | }, 286 | "security": [ 287 | { 288 | "petstore_auth": [ 289 | "write_pets", 290 | "read_pets" 291 | ] 292 | } 293 | ] 294 | } 295 | } 296 | }, 297 | "securityDefinitions": { 298 | "api_key": { 299 | "type": "apiKey", 300 | "name": "api_key", 301 | "in": "header" 302 | }, 303 | "petstore_auth": { 304 | "type": "oauth2", 305 | "authorizationUrl": "http://petstore.swagger.wordnik.com/api/oauth/dialog", 306 | "flow": "implicit", 307 | "scopes": { 308 | "write_pets": "modify pets in your account", 309 | "read_pets": "read your pets" 310 | } 311 | } 312 | }, 313 | "definitions": { 314 | "Category": { 315 | "properties": { 316 | "id": { 317 | "type": "integer", 318 | "format": "int64" 319 | }, 320 | "name": { 321 | "type": "string" 322 | } 323 | } 324 | }, 325 | "Pet": { 326 | "description": "Test description", 327 | "required": [ 328 | "name", 329 | "photoUrls" 330 | ], 331 | "properties": { 332 | "id": { 333 | "type": "integer", 334 | "format": "int64" 335 | }, 336 | "category": { 337 | "$ref": "#/definitions/Category" 338 | }, 339 | "name": { 340 | "type": "string", 341 | "example": "doggie" 342 | }, 343 | "photoUrls": { 344 | "type": "array", 345 | "items": { 346 | "type": "string" 347 | } 348 | }, 349 | "status": { 350 | "type": "string", 351 | "description": "pet status in the store" 352 | }, 353 | "extraProperty": { 354 | "type": "string", 355 | "description": "extra consumer property missing in implementation" 356 | } 357 | } 358 | } 359 | } 360 | } 361 | -------------------------------------------------------------------------------- /src/test/resources/swagger-singleresource-partialmodel.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "description": "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample, you can use the api key `special-key` to test the authorization filters\n", 5 | "version": "1.0.0", 6 | "title": "Swagger Petstore API", 7 | "termsOfService": "http://helloreverb.com/terms/", 8 | "contact": { 9 | "name": "apiteam@wordnik.com" 10 | }, 11 | "license": { 12 | "name": "Apache 2.0", 13 | "url": "http://www.apache.org/licenses/LICENSE-2.0.html" 14 | } 15 | }, 16 | "host": "petstore.swagger.wordnik.com", 17 | "basePath": "/v2", 18 | "schemes": [ 19 | "http" 20 | ], 21 | "paths": { 22 | "/pets": { 23 | "post": { 24 | "tags": [ 25 | "pet" 26 | ], 27 | "summary": "Add a new pet to the store", 28 | "description": "", 29 | "operationId": "addPet", 30 | "consumes": [ 31 | "application/json" 32 | ], 33 | "produces": [ 34 | "application/json" 35 | ], 36 | "parameters": [ 37 | { 38 | "in": "body", 39 | "name": "body", 40 | "description": "Pet object that needs to be added to the store", 41 | "required": false, 42 | "schema": { 43 | "$ref": "#/definitions/Pet" 44 | } 45 | } 46 | ], 47 | "responses": { 48 | "405": { 49 | "description": "Invalid input" 50 | } 51 | }, 52 | "security": [ 53 | { 54 | "petstore_auth": [ 55 | "write_pets", 56 | "read_pets" 57 | ] 58 | } 59 | ] 60 | }, 61 | "put": { 62 | "tags": [ 63 | "pet" 64 | ], 65 | "summary": "Update an existing pet", 66 | "description": "", 67 | "operationId": "updatePet", 68 | "consumes": [ 69 | "application/json", 70 | "application/xml" 71 | ], 72 | "produces": [ 73 | "application/json", 74 | "application/xml" 75 | ], 76 | "parameters": [ 77 | { 78 | "in": "body", 79 | "name": "body", 80 | "description": "Pet object that needs to be added to the store", 81 | "required": false, 82 | "schema": { 83 | "$ref": "#/definitions/Pet" 84 | } 85 | } 86 | ], 87 | "responses": { 88 | "400": { 89 | "description": "Invalid ID supplied" 90 | }, 91 | "404": { 92 | "description": "Pet not found" 93 | }, 94 | "405": { 95 | "description": "Validation exception" 96 | } 97 | }, 98 | "security": [ 99 | { 100 | "petstore_auth": [ 101 | "write_pets", 102 | "read_pets" 103 | ] 104 | } 105 | ] 106 | } 107 | }, 108 | "/pets/findByStatus": { 109 | "get": { 110 | "tags": [ 111 | "pet" 112 | ], 113 | "summary": "Finds Pets by status", 114 | "description": "Multiple status values can be provided with comma seperated strings", 115 | "operationId": "findPetsByStatus", 116 | "produces": [ 117 | "application/json" 118 | ], 119 | "parameters": [ 120 | { 121 | "in": "query", 122 | "name": "status", 123 | "description": "Status values that need to be considered for filter", 124 | "required": false, 125 | "type": "array", 126 | "items": { 127 | "type": "string" 128 | }, 129 | "collectionFormat": "multi" 130 | } 131 | ], 132 | "responses": { 133 | "200": { 134 | "description": "successful operation", 135 | "schema": { 136 | "type": "array", 137 | "items": { 138 | "$ref": "#/definitions/Pet" 139 | } 140 | } 141 | }, 142 | "400": { 143 | "description": "Invalid status value" 144 | } 145 | }, 146 | "security": [ 147 | { 148 | "petstore_auth": [ 149 | "write_pets", 150 | "read_pets" 151 | ] 152 | } 153 | ] 154 | } 155 | }, 156 | "/pets/{petId}": { 157 | "get": { 158 | "tags": [ 159 | "pet" 160 | ], 161 | "summary": "Find pet by ID", 162 | "description": "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions", 163 | "operationId": "getPetById", 164 | "produces": [ 165 | "application/json" 166 | ], 167 | "parameters": [ 168 | { 169 | "in": "path", 170 | "name": "petId", 171 | "description": "ID of pet that needs to be fetched", 172 | "required": true, 173 | "type": "integer", 174 | "format": "int64" 175 | } 176 | ], 177 | "responses": { 178 | "200": { 179 | "description": "successful operation", 180 | "schema": { 181 | "$ref": "#/definitions/Pet" 182 | } 183 | }, 184 | "400": { 185 | "description": "Invalid ID supplied" 186 | }, 187 | "404": { 188 | "description": "Pet not found" 189 | } 190 | }, 191 | "security": [ 192 | { 193 | "api_key": [] 194 | }, 195 | { 196 | "petstore_auth": [ 197 | "write_pets", 198 | "read_pets" 199 | ] 200 | } 201 | ] 202 | }, 203 | "post": { 204 | "tags": [ 205 | "pet" 206 | ], 207 | "summary": "Updates a pet in the store with form data", 208 | "description": "", 209 | "operationId": "updatePetWithForm", 210 | "consumes": [ 211 | "application/x-www-form-urlencoded" 212 | ], 213 | "produces": [ 214 | "application/json" 215 | ], 216 | "parameters": [ 217 | { 218 | "in": "path", 219 | "name": "petId", 220 | "description": "ID of pet that needs to be updated", 221 | "required": true, 222 | "type": "string" 223 | }, 224 | { 225 | "in": "formData", 226 | "name": "name", 227 | "description": "Updated name of the pet", 228 | "required": true, 229 | "type": "string" 230 | }, 231 | { 232 | "in": "formData", 233 | "name": "status", 234 | "description": "Updated status of the pet", 235 | "required": true, 236 | "type": "string" 237 | } 238 | ], 239 | "responses": { 240 | "405": { 241 | "description": "Invalid input" 242 | } 243 | }, 244 | "security": [ 245 | { 246 | "petstore_auth": [ 247 | "write_pets", 248 | "read_pets" 249 | ] 250 | } 251 | ] 252 | }, 253 | "delete": { 254 | "tags": [ 255 | "pet" 256 | ], 257 | "summary": "Deletes a pet", 258 | "description": "", 259 | "operationId": "deletePet", 260 | "produces": [ 261 | "application/json", 262 | "application/xml" 263 | ], 264 | "parameters": [ 265 | { 266 | "in": "header", 267 | "name": "api_key", 268 | "description": "", 269 | "required": true, 270 | "type": "string" 271 | }, 272 | { 273 | "in": "path", 274 | "name": "petId", 275 | "description": "Pet id to delete", 276 | "required": true, 277 | "type": "integer", 278 | "format": "int64" 279 | } 280 | ], 281 | "responses": { 282 | "400": { 283 | "description": "Invalid pet value" 284 | } 285 | }, 286 | "security": [ 287 | { 288 | "petstore_auth": [ 289 | "write_pets", 290 | "read_pets" 291 | ] 292 | } 293 | ] 294 | } 295 | } 296 | }, 297 | "securityDefinitions": { 298 | "api_key": { 299 | "type": "apiKey", 300 | "name": "api_key", 301 | "in": "header" 302 | }, 303 | "petstore_auth": { 304 | "type": "oauth2", 305 | "authorizationUrl": "http://petstore.swagger.wordnik.com/api/oauth/dialog", 306 | "flow": "implicit", 307 | "scopes": { 308 | "write_pets": "modify pets in your account", 309 | "read_pets": "read your pets" 310 | } 311 | } 312 | }, 313 | "definitions": { 314 | "Category": { 315 | "properties": { 316 | "id": { 317 | "type": "integer", 318 | "format": "int64" 319 | }, 320 | "name": { 321 | "type": "string" 322 | } 323 | } 324 | }, 325 | "Pet": { 326 | "description": "Test description", 327 | "required": [ 328 | "name", 329 | "photoUrls" 330 | ], 331 | "properties": { 332 | "id": { 333 | "type": "integer", 334 | "format": "int64" 335 | }, 336 | "category": { 337 | "$ref": "#/definitions/Category" 338 | }, 339 | "name": { 340 | "type": "string", 341 | "example": "doggie" 342 | }, 343 | "photoUrls": { 344 | "type": "array", 345 | "items": { 346 | "type": "string" 347 | } 348 | }, 349 | "status": { 350 | "type": "string", 351 | "description": "pet status in the store" 352 | } 353 | } 354 | } 355 | } 356 | } 357 | -------------------------------------------------------------------------------- /src/test/resources/swagger-singleresource.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "description": "This is a sample server Petstore server.\n\n[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net.\n\nFor this sample, you can use the api key `special-key` to test the authorization filters\n", 5 | "version": "1.0.0", 6 | "title": "Swagger Petstore API", 7 | "termsOfService": "http://helloreverb.com/terms/", 8 | "contact": { 9 | "name": "apiteam@wordnik.com" 10 | }, 11 | "license": { 12 | "name": "Apache 2.0", 13 | "url": "http://www.apache.org/licenses/LICENSE-2.0.html" 14 | } 15 | }, 16 | "host": "petstore.swagger.wordnik.com", 17 | "basePath": "/v2", 18 | "schemes": [ 19 | "http" 20 | ], 21 | "paths": { 22 | "/pets": { 23 | "post": { 24 | "tags": [ 25 | "pet" 26 | ], 27 | "summary": "Add a new pet to the store", 28 | "description": "", 29 | "operationId": "addPet", 30 | "consumes": [ 31 | "application/json" 32 | ], 33 | "produces": [ 34 | "application/json" 35 | ], 36 | "parameters": [ 37 | { 38 | "in": "body", 39 | "name": "body", 40 | "description": "Pet object that needs to be added to the store", 41 | "required": false, 42 | "schema": { 43 | "$ref": "#/definitions/Pet" 44 | } 45 | } 46 | ], 47 | "responses": { 48 | "405": { 49 | "description": "Invalid input" 50 | } 51 | }, 52 | "security": [ 53 | { 54 | "petstore_auth": [ 55 | "write_pets", 56 | "read_pets" 57 | ] 58 | } 59 | ] 60 | }, 61 | "put": { 62 | "tags": [ 63 | "pet" 64 | ], 65 | "summary": "Update an existing pet", 66 | "description": "", 67 | "operationId": "updatePet", 68 | "consumes": [ 69 | "application/json", 70 | "application/xml" 71 | ], 72 | "produces": [ 73 | "application/json", 74 | "application/xml" 75 | ], 76 | "parameters": [ 77 | { 78 | "in": "body", 79 | "name": "body", 80 | "description": "Pet object that needs to be added to the store", 81 | "required": false, 82 | "schema": { 83 | "$ref": "#/definitions/Pet" 84 | } 85 | } 86 | ], 87 | "responses": { 88 | "400": { 89 | "description": "Invalid ID supplied" 90 | }, 91 | "404": { 92 | "description": "Pet not found" 93 | }, 94 | "405": { 95 | "description": "Validation exception" 96 | } 97 | }, 98 | "security": [ 99 | { 100 | "petstore_auth": [ 101 | "write_pets", 102 | "read_pets" 103 | ] 104 | } 105 | ] 106 | } 107 | }, 108 | "/pets/findByStatus": { 109 | "get": { 110 | "tags": [ 111 | "pet" 112 | ], 113 | "summary": "Finds Pets by status", 114 | "description": "Multiple status values can be provided with comma seperated strings", 115 | "operationId": "findPetsByStatus", 116 | "produces": [ 117 | "application/json" 118 | ], 119 | "parameters": [ 120 | { 121 | "in": "query", 122 | "name": "status", 123 | "description": "Status values that need to be considered for filter", 124 | "required": false, 125 | "type": "array", 126 | "items": { 127 | "type": "string" 128 | }, 129 | "collectionFormat": "multi" 130 | } 131 | ], 132 | "responses": { 133 | "200": { 134 | "description": "successful operation", 135 | "schema": { 136 | "type": "array", 137 | "items": { 138 | "$ref": "#/definitions/Pet" 139 | } 140 | } 141 | }, 142 | "400": { 143 | "description": "Invalid status value" 144 | } 145 | }, 146 | "security": [ 147 | { 148 | "petstore_auth": [ 149 | "write_pets", 150 | "read_pets" 151 | ] 152 | } 153 | ] 154 | } 155 | }, 156 | "/pets/{petId}": { 157 | "get": { 158 | "tags": [ 159 | "pet" 160 | ], 161 | "summary": "Find pet by ID", 162 | "description": "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions", 163 | "operationId": "getPetById", 164 | "produces": [ 165 | "application/json" 166 | ], 167 | "parameters": [ 168 | { 169 | "in": "path", 170 | "name": "petId", 171 | "description": "ID of pet that needs to be fetched", 172 | "required": true, 173 | "type": "integer", 174 | "format": "int64" 175 | } 176 | ], 177 | "responses": { 178 | "200": { 179 | "description": "successful operation", 180 | "schema": { 181 | "$ref": "#/definitions/Pet" 182 | } 183 | }, 184 | "400": { 185 | "description": "Invalid ID supplied" 186 | }, 187 | "404": { 188 | "description": "Pet not found" 189 | } 190 | }, 191 | "security": [ 192 | { 193 | "api_key": [] 194 | }, 195 | { 196 | "petstore_auth": [ 197 | "write_pets", 198 | "read_pets" 199 | ] 200 | } 201 | ] 202 | }, 203 | "post": { 204 | "tags": [ 205 | "pet" 206 | ], 207 | "summary": "Updates a pet in the store with form data", 208 | "description": "", 209 | "operationId": "updatePetWithForm", 210 | "consumes": [ 211 | "application/x-www-form-urlencoded" 212 | ], 213 | "produces": [ 214 | "application/json" 215 | ], 216 | "parameters": [ 217 | { 218 | "in": "path", 219 | "name": "petId", 220 | "description": "ID of pet that needs to be updated", 221 | "required": true, 222 | "type": "string" 223 | }, 224 | { 225 | "in": "formData", 226 | "name": "name", 227 | "description": "Updated name of the pet", 228 | "required": true, 229 | "type": "string" 230 | }, 231 | { 232 | "in": "formData", 233 | "name": "status", 234 | "description": "Updated status of the pet", 235 | "required": true, 236 | "type": "string" 237 | } 238 | ], 239 | "responses": { 240 | "405": { 241 | "description": "Invalid input" 242 | } 243 | }, 244 | "security": [ 245 | { 246 | "petstore_auth": [ 247 | "write_pets", 248 | "read_pets" 249 | ] 250 | } 251 | ] 252 | }, 253 | "delete": { 254 | "tags": [ 255 | "pet" 256 | ], 257 | "summary": "Deletes a pet", 258 | "description": "", 259 | "operationId": "deletePet", 260 | "produces": [ 261 | "application/json", 262 | "application/xml" 263 | ], 264 | "parameters": [ 265 | { 266 | "in": "header", 267 | "name": "api_key", 268 | "description": "", 269 | "required": true, 270 | "type": "string" 271 | }, 272 | { 273 | "in": "path", 274 | "name": "petId", 275 | "description": "Pet id to delete", 276 | "required": true, 277 | "type": "integer", 278 | "format": "int64" 279 | } 280 | ], 281 | "responses": { 282 | "400": { 283 | "description": "Invalid pet value" 284 | } 285 | }, 286 | "security": [ 287 | { 288 | "petstore_auth": [ 289 | "write_pets", 290 | "read_pets" 291 | ] 292 | } 293 | ] 294 | } 295 | } 296 | }, 297 | "securityDefinitions": { 298 | "api_key": { 299 | "type": "apiKey", 300 | "name": "api_key", 301 | "in": "header" 302 | }, 303 | "petstore_auth": { 304 | "type": "oauth2", 305 | "authorizationUrl": "http://petstore.swagger.wordnik.com/api/oauth/dialog", 306 | "flow": "implicit", 307 | "scopes": { 308 | "write_pets": "modify pets in your account", 309 | "read_pets": "read your pets" 310 | } 311 | } 312 | }, 313 | "definitions": { 314 | "Category": { 315 | "properties": { 316 | "id": { 317 | "type": "integer", 318 | "format": "int64" 319 | }, 320 | "name": { 321 | "type": "string" 322 | } 323 | } 324 | }, 325 | "Pet": { 326 | "description": "Test description", 327 | "required": [ 328 | "name", 329 | "photoUrls" 330 | ], 331 | "properties": { 332 | "id": { 333 | "type": "integer", 334 | "format": "int64" 335 | }, 336 | "category": { 337 | "$ref": "#/definitions/Category" 338 | }, 339 | "name": { 340 | "type": "string", 341 | "example": "doggie" 342 | }, 343 | "photoUrls": { 344 | "type": "array", 345 | "items": { 346 | "type": "string" 347 | } 348 | }, 349 | "tags": { 350 | "type": "array", 351 | "items": { 352 | "$ref": "#/definitions/Tag" 353 | } 354 | }, 355 | "status": { 356 | "type": "string", 357 | "description": "pet status in the store" 358 | } 359 | } 360 | }, 361 | "Tag": { 362 | "properties": { 363 | "id": { 364 | "type": "integer", 365 | "format": "int64" 366 | }, 367 | "name": { 368 | "type": "string" 369 | } 370 | } 371 | } 372 | } 373 | } 374 | --------------------------------------------------------------------------------