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 |
--------------------------------------------------------------------------------