Skip to content

Commit fde808a

Browse files
committed
support master with no paths case
1 parent 6522928 commit fde808a

File tree

4 files changed

+140
-1
lines changed

4 files changed

+140
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The input swagger specs must follow a convention:
1313

1414
## Merge specification
1515

16-
* All input files are valid swagger files alone
16+
* All input files are valid swagger files alone, except for master which may have no paths.
1717
* Only **paths, definitions, parameters and responses** are copied from partials.
1818
* If element is defined only in one partial, it is copied as is.
1919
* If element exists in more than one partial, then:

src/test/java/com/ai_traders/swagger/composer/ComposerTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@ public void shouldMergeSimpleCase() throws Exception {
4545
assertThat(outputMerged.getConflicts().size(),is(0));
4646
}
4747

48+
InputSwaggers loadNoPathsMasterCase() throws IOException {
49+
return new InputSwaggers(
50+
loadSwaggerSource("noPathsMaster/master.yaml"),
51+
loadSwaggerSource("noPathsMaster/part1.yaml"));
52+
}
53+
54+
@Test
55+
public void shouldNoPathsMasterCase() throws Exception {
56+
InputSwaggers input = loadNoPathsMasterCase();
57+
MergedSwagger outputMerged = composer.merge(input);
58+
Swagger output = outputMerged.getMerged();
59+
assertNull(output.getPath("/v1/products"));
60+
assertNotNull(output.getPath("/v2/products"));
61+
assertNotNull(output.getDefinitions().get("Product"));
62+
assertNotNull(output.getDefinitions().get("Error"));
63+
assertThat(outputMerged.getConflicts().size(),is(0));
64+
}
65+
4866
InputSwaggers loadBasePathCase() throws IOException {
4967
return new InputSwaggers(
5068
loadSwaggerSource("basePath/master.yaml"),
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# this is an example of the Uber API
2+
# as a demonstration of an API spec in YAML
3+
swagger: '2.0'
4+
info:
5+
title: Uber API
6+
description: Move your app forward with the Uber API
7+
version: "1.0.0"
8+
# the domain of the service
9+
host: api.uber.com
10+
# array of all schemes that your API supports
11+
schemes:
12+
- https
13+
produces:
14+
- application/json
15+
definitions:
16+
Product:
17+
type: object
18+
properties:
19+
product_id:
20+
type: string
21+
description: Unique identifier representing a specific product for a given latitude & longitude. For example, uberX in San Francisco will have a different product_id than uberX in Los Angeles.
22+
description:
23+
type: string
24+
description: Description of product.
25+
display_name:
26+
type: string
27+
description: Display name of product.
28+
capacity:
29+
type: string
30+
description: Capacity of product. For example, 4 people.
31+
image:
32+
type: string
33+
description: Image URL representing the product.
34+
Error:
35+
type: object
36+
properties:
37+
code:
38+
type: integer
39+
format: int32
40+
message:
41+
type: string
42+
fields:
43+
type: string
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# this is an example of the Uber API
2+
# as a demonstration of an API spec in YAML
3+
swagger: '2.0'
4+
info:
5+
title: Uber API
6+
description: Move your app forward with the Uber API
7+
version: "1.0.0"
8+
# the domain of the service
9+
host: api.uber.com
10+
# array of all schemes that your API supports
11+
schemes:
12+
- https
13+
produces:
14+
- application/json
15+
paths:
16+
/v2/products:
17+
get:
18+
summary: Product Types
19+
description: |
20+
The Products endpoint returns information about the *Uber* products
21+
offered at a given location. The response includes the display name
22+
and other details about each product, and lists the products in the
23+
proper display order.
24+
parameters:
25+
- name: latitude
26+
in: query
27+
description: Latitude component of location.
28+
required: true
29+
type: number
30+
format: double
31+
- name: longitude
32+
in: query
33+
description: Longitude component of location.
34+
required: true
35+
type: number
36+
format: double
37+
tags:
38+
- Products
39+
responses:
40+
200:
41+
description: An array of products
42+
schema:
43+
type: array
44+
items:
45+
$ref: '#/definitions/Product'
46+
default:
47+
description: Unexpected error
48+
schema:
49+
$ref: '#/definitions/Error'
50+
definitions:
51+
Product:
52+
type: object
53+
properties:
54+
product_id:
55+
type: string
56+
description: Unique identifier representing a specific product for a given latitude & longitude. For example, uberX in San Francisco will have a different product_id than uberX in Los Angeles.
57+
description:
58+
type: string
59+
description: Description of product.
60+
display_name:
61+
type: string
62+
description: Display name of product.
63+
capacity:
64+
type: string
65+
description: Capacity of product. For example, 4 people.
66+
image:
67+
type: string
68+
description: Image URL representing the product.
69+
Error:
70+
type: object
71+
properties:
72+
code:
73+
type: integer
74+
format: int32
75+
message:
76+
type: string
77+
fields:
78+
type: string

0 commit comments

Comments
 (0)