Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit a0b2b10

Browse files
authored
Merge pull request #191 from Azure/lucashh-oaspecs
Lucashh oaspecs
2 parents 22302e7 + 7366746 commit a0b2b10

File tree

11 files changed

+1737
-26
lines changed

11 files changed

+1737
-26
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Xunit;
2+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common;
3+
using System;
4+
using System.IO;
5+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Create;
6+
7+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Test
8+
{
9+
public class OpenAPISpecReaderTests
10+
{
11+
private string openAPISpecFolder;
12+
13+
public OpenAPISpecReaderTests()
14+
{
15+
this.openAPISpecFolder = String.Concat("..", Path.DirectorySeparatorChar,
16+
"..", Path.DirectorySeparatorChar,
17+
"..", Path.DirectorySeparatorChar,
18+
"..", Path.DirectorySeparatorChar,
19+
"apimtemplate.test", Path.DirectorySeparatorChar,
20+
"Common", Path.DirectorySeparatorChar,
21+
"OpenAPISpecs", Path.DirectorySeparatorChar);
22+
}
23+
[Fact]
24+
public async void ShouldDetermineCorrectOpenAPISpecVersion()
25+
{
26+
// arrange
27+
OpenAPISpecReader openAPISpecReader = new OpenAPISpecReader();
28+
29+
// act
30+
bool shouldOutputVersionTwo = await openAPISpecReader.isJSONOpenAPISpecVersionThreeAsync(String.Concat(this.openAPISpecFolder, "swaggerPetstore.json"));
31+
bool shouldOutputVersionThree = await openAPISpecReader.isJSONOpenAPISpecVersionThreeAsync(String.Concat(this.openAPISpecFolder, "swaggerPetstorev3.json"));
32+
33+
// assert
34+
Assert.False(shouldOutputVersionTwo);
35+
Assert.True(shouldOutputVersionThree);
36+
}
37+
}
38+
}
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
{
2+
"swagger": "2.0",
3+
"info": {
4+
"version": "1.0.0",
5+
"title": "Swagger Petstore",
6+
"description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification",
7+
"termsOfService": "http://swagger.io/terms/",
8+
"contact": {
9+
"name": "Swagger API Team",
10+
"email": "apiteam@swagger.io",
11+
"url": "http://swagger.io"
12+
},
13+
"license": {
14+
"name": "Apache 2.0",
15+
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
16+
}
17+
},
18+
"host": "petstore.swagger.io",
19+
"basePath": "/api",
20+
"schemes": [
21+
"http"
22+
],
23+
"consumes": [
24+
"application/json"
25+
],
26+
"produces": [
27+
"application/json"
28+
],
29+
"paths": {
30+
"/pets": {
31+
"get": {
32+
"description": "Returns all pets from the system that the user has access to\nNam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia.\n\nSed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien.\n",
33+
"operationId": "findPets",
34+
"parameters": [
35+
{
36+
"name": "tags",
37+
"in": "query",
38+
"description": "tags to filter by",
39+
"required": false,
40+
"type": "array",
41+
"collectionFormat": "csv",
42+
"items": {
43+
"type": "string"
44+
}
45+
},
46+
{
47+
"name": "limit",
48+
"in": "query",
49+
"description": "maximum number of results to return",
50+
"required": false,
51+
"type": "integer",
52+
"format": "int32"
53+
}
54+
],
55+
"responses": {
56+
"200": {
57+
"description": "pet response",
58+
"schema": {
59+
"type": "array",
60+
"items": {
61+
"$ref": "#/definitions/Pet"
62+
}
63+
}
64+
},
65+
"default": {
66+
"description": "unexpected error",
67+
"schema": {
68+
"$ref": "#/definitions/Error"
69+
}
70+
}
71+
}
72+
},
73+
"post": {
74+
"description": "Creates a new pet in the store. Duplicates are allowed",
75+
"operationId": "addPet",
76+
"parameters": [
77+
{
78+
"name": "pet",
79+
"in": "body",
80+
"description": "Pet to add to the store",
81+
"required": true,
82+
"schema": {
83+
"$ref": "#/definitions/NewPet"
84+
}
85+
}
86+
],
87+
"responses": {
88+
"200": {
89+
"description": "pet response",
90+
"schema": {
91+
"$ref": "#/definitions/Pet"
92+
}
93+
},
94+
"default": {
95+
"description": "unexpected error",
96+
"schema": {
97+
"$ref": "#/definitions/Error"
98+
}
99+
}
100+
}
101+
}
102+
},
103+
"/pets/{id}": {
104+
"get": {
105+
"description": "Returns a user based on a single ID, if the user does not have access to the pet",
106+
"operationId": "find pet by id",
107+
"parameters": [
108+
{
109+
"name": "id",
110+
"in": "path",
111+
"description": "ID of pet to fetch",
112+
"required": true,
113+
"type": "integer",
114+
"format": "int64"
115+
}
116+
],
117+
"responses": {
118+
"200": {
119+
"description": "pet response",
120+
"schema": {
121+
"$ref": "#/definitions/Pet"
122+
}
123+
},
124+
"default": {
125+
"description": "unexpected error",
126+
"schema": {
127+
"$ref": "#/definitions/Error"
128+
}
129+
}
130+
}
131+
},
132+
"delete": {
133+
"description": "deletes a single pet based on the ID supplied",
134+
"operationId": "deletePet",
135+
"parameters": [
136+
{
137+
"name": "id",
138+
"in": "path",
139+
"description": "ID of pet to delete",
140+
"required": true,
141+
"type": "integer",
142+
"format": "int64"
143+
}
144+
],
145+
"responses": {
146+
"204": {
147+
"description": "pet deleted"
148+
},
149+
"default": {
150+
"description": "unexpected error",
151+
"schema": {
152+
"$ref": "#/definitions/Error"
153+
}
154+
}
155+
}
156+
}
157+
}
158+
},
159+
"definitions": {
160+
"Pet": {
161+
"type": "object",
162+
"allOf": [
163+
{
164+
"$ref": "#/definitions/NewPet"
165+
},
166+
{
167+
"required": [
168+
"id"
169+
],
170+
"properties": {
171+
"id": {
172+
"type": "integer",
173+
"format": "int64"
174+
}
175+
}
176+
}
177+
]
178+
},
179+
"NewPet": {
180+
"type": "object",
181+
"required": [
182+
"name"
183+
],
184+
"properties": {
185+
"name": {
186+
"type": "string"
187+
},
188+
"tag": {
189+
"type": "string"
190+
}
191+
}
192+
},
193+
"Error": {
194+
"type": "object",
195+
"required": [
196+
"code",
197+
"message"
198+
],
199+
"properties": {
200+
"code": {
201+
"type": "integer",
202+
"format": "int32"
203+
},
204+
"message": {
205+
"type": "string"
206+
}
207+
}
208+
}
209+
}
210+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
swagger: "2.0"
2+
info:
3+
version: 1.0.0
4+
title: Swagger Petstore
5+
license:
6+
name: MIT
7+
host: petstore.swagger.io
8+
basePath: /v1
9+
schemes:
10+
- http
11+
consumes:
12+
- application/json
13+
produces:
14+
- application/json
15+
paths:
16+
/pets:
17+
get:
18+
summary: List all pets
19+
operationId: listPets
20+
tags:
21+
- pets
22+
parameters:
23+
- name: limit
24+
in: query
25+
description: How many items to return at one time (max 100)
26+
required: false
27+
type: integer
28+
format: int32
29+
responses:
30+
"200":
31+
description: A paged array of pets
32+
headers:
33+
x-next:
34+
type: string
35+
description: A link to the next page of responses
36+
schema:
37+
$ref: '#/definitions/Pets'
38+
default:
39+
description: unexpected error
40+
schema:
41+
$ref: '#/definitions/Error'
42+
post:
43+
summary: Create a pet
44+
operationId: createPets
45+
tags:
46+
- pets
47+
responses:
48+
"201":
49+
description: Null response
50+
default:
51+
description: unexpected error
52+
schema:
53+
$ref: '#/definitions/Error'
54+
/pets/{petId}:
55+
get:
56+
summary: Info for a specific pet
57+
operationId: showPetById
58+
tags:
59+
- pets
60+
parameters:
61+
- name: petId
62+
in: path
63+
required: true
64+
description: The id of the pet to retrieve
65+
type: string
66+
responses:
67+
"200":
68+
description: Expected response to a valid request
69+
schema:
70+
$ref: '#/definitions/Pets'
71+
default:
72+
description: unexpected error
73+
schema:
74+
$ref: '#/definitions/Error'
75+
definitions:
76+
Pet:
77+
type: "object"
78+
required:
79+
- id
80+
- name
81+
properties:
82+
id:
83+
type: integer
84+
format: int64
85+
name:
86+
type: string
87+
tag:
88+
type: string
89+
Pets:
90+
type: array
91+
items:
92+
$ref: '#/definitions/Pet'
93+
Error:
94+
type: "object"
95+
required:
96+
- code
97+
- message
98+
properties:
99+
code:
100+
type: integer
101+
format: int32
102+
message:
103+
type: string

0 commit comments

Comments
 (0)