Skip to content

Commit

Permalink
Add test cases for Swagger V2 and OpenAPI 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TharmiganK committed Sep 19, 2024
1 parent ad24c75 commit 4befa98
Show file tree
Hide file tree
Showing 5 changed files with 785 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,26 @@ public void testSanitizeCmdDefaultYaml() throws IOException {
compareFiles(expectedFilePath, tmpDir.resolve("sanitized_openapi.yaml"));
}

@Test(description = "Test openapi sanitize sub command with Swagger 2.0")
public void testSanitizeCmdWithSwaggerV2() throws IOException {
Path expectedFilePath = resourceDir.resolve(Paths.get("cmd/sanitize/sanitized_openapi_2.0_expected.yaml"));
String[] args = {"-i", resourceDir + "/cmd/sanitize/openapi_2.0.yaml", "-o", tmpDir.toString()};
Sanitize sanitize = new Sanitize();
new CommandLine(sanitize).parseArgs(args);
sanitize.execute();
compareFiles(expectedFilePath, tmpDir.resolve("sanitized_openapi.yaml"));
}

@Test(description = "Test openapi sanitize sub command with OpenAPI 3.0.0")
public void testSanitizeCmdWithOpenAPIV3_0_0() throws IOException {
Path expectedFilePath = resourceDir.resolve(Paths.get("cmd/sanitize/sanitized_openapi_3.0.0_expected.yaml"));
String[] args = {"-i", resourceDir + "/cmd/sanitize/openapi_3.0.0.yaml", "-o", tmpDir.toString()};
Sanitize sanitize = new Sanitize();
new CommandLine(sanitize).parseArgs(args);
sanitize.execute();
compareFiles(expectedFilePath, tmpDir.resolve("sanitized_openapi.yaml"));
}

@Test(description = "Test openapi sanitize sub command with the name option")
public void testSanitizeCmdName() throws IOException {
Path expectedFilePath = resourceDir.resolve(Paths.get("cmd/sanitize/sanitized_openapi_expected.json"));
Expand Down
174 changes: 174 additions & 0 deletions openapi-cli/src/test/resources/cmd/sanitize/openapi_2.0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
swagger: "2.0"
info:
title: Api V1
version: 0.0.0
host: "localhost:8080"
basePath: "/api/v1"
schemes:
- http
paths:
/albums:
get:
tags:
- albums
operationId: getAlbums
produces:
- application/json
parameters:
- name: _artists_
in: query
type: array
items:
type: string
collectionFormat: csv
default: []
- name: X-API-VERSION
in: header
type: string
default: v1
responses:
"200":
description: Ok
schema:
type: array
items:
$ref: "#/definitions/album"
"400":
description: BadRequest
schema:
$ref: "#/definitions/ErrorPayload"
post:
tags:
- albums
operationId: postAlbum
produces:
- application/json
consumes:
- application/json
parameters:
- in: body
name: body
required: true
schema:
$ref: "#/definitions/album"
responses:
"201":
description: Created
schema:
$ref: "#/definitions/album"
"400":
description: BadRequest
schema:
$ref: "#/definitions/ErrorPayload"
/albums/{_id}:
get:
tags:
- albums
operationId: getAlbumById
produces:
- application/json
parameters:
- name: _id
in: path
required: true
type: string
responses:
"200":
description: Ok
schema:
$ref: "#/definitions/album"
"404":
description: NotFound
schema:
$ref: "#/definitions/message"
"400":
description: BadRequest
schema:
$ref: "#/definitions/ErrorPayload"
/albums/{id}/artist:
get:
tags:
- artists
operationId: getArtistByAlbum
produces:
- application/json
parameters:
- name: id
in: path
required: true
type: string
responses:
"200":
description: Ok
schema:
$ref: "#/definitions/album_aRTIST"
"400":
description: BadRequest
schema:
$ref: "#/definitions/ErrorPayload"
definitions:
ErrorPayload:
required:
- message
- method
- path
- reason
- status
- timestamp
type: object
properties:
timestamp:
type: string
status:
type: integer
format: int64
reason:
type: string
message:
type: string
path:
type: string
method:
type: string
album:
required:
- _id
- artist
- title
type: object
properties:
_id:
type: string
title:
type: string
artist:
type: string
additionalProperties: false
album_aRTIST:
required:
- albums
- id
- name
type: object
properties:
id:
type: string
name:
type: string
albums:
type: array
items:
$ref: "#/definitions/album"
additionalProperties: false
message:
required:
- code
- message
type: object
properties:
message:
type: string
code:
type: integer
format: int64
additionalProperties: false
190 changes: 190 additions & 0 deletions openapi-cli/src/test/resources/cmd/sanitize/openapi_3.0.0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
openapi: 3.0.0
info:
title: Api V1
version: 0.0.0
servers:
- url: "http://{server}:{port}/api/v1"
variables:
server:
default: localhost
port:
default: "8080"
paths:
/albums:
get:
tags:
- albums
operationId: getAlbums
parameters:
- name: _artists_
in: query
schema:
type: array
items:
type: string
default: []
- name: X-API-VERSION
in: header
schema:
type: string
default: v1
responses:
"200":
description: Ok
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/album'
"400":
description: BadRequest
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorPayload'
post:
tags:
- albums
operationId: postAlbum
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/album'
required: true
responses:
"201":
description: Created
content:
application/json:
schema:
$ref: '#/components/schemas/album'
"400":
description: BadRequest
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorPayload'
/albums/{_id}:
get:
tags:
- albums
operationId: getAlbumById
parameters:
- name: _id
in: path
required: true
schema:
type: string
responses:
"200":
description: Ok
content:
application/json:
schema:
$ref: '#/components/schemas/album'
"404":
description: NotFound
content:
application/json:
schema:
$ref: '#/components/schemas/message'
"400":
description: BadRequest
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorPayload'
/albums/{id}/artist:
get:
tags:
- artists
operationId: getArtistByAlbum
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
"200":
description: Ok
content:
application/json:
schema:
$ref: '#/components/schemas/album_aRTIST'
"400":
description: BadRequest
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorPayload'
components:
schemas:
ErrorPayload:
required:
- message
- method
- path
- reason
- status
- timestamp
type: object
properties:
timestamp:
type: string
format: date-time
status:
type: integer
format: int64
reason:
type: string
message:
type: string
path:
type: string
method:
type: string
album:
required:
- _id
- artist
- title
type: object
properties:
_id:
type: string
title:
type: string
artist:
type: string
additionalProperties: false
album_aRTIST:
required:
- albums
- id
- name
type: object
properties:
id:
type: string
name:
type: string
albums:
type: array
items:
$ref: "#/components/schemas/album"
additionalProperties: false
message:
required:
- code
- message
type: object
properties:
message:
type: string
code:
type: integer
format: int64
additionalProperties: false
Loading

0 comments on commit 4befa98

Please sign in to comment.