Skip to content

Commit

Permalink
Add suggestions from review
Browse files Browse the repository at this point in the history
  • Loading branch information
TharmiganK committed Sep 19, 2024
1 parent 6c1a7b9 commit 49b5e31
Show file tree
Hide file tree
Showing 6 changed files with 787 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
public abstract class SubCmdBase implements BLauncherCmd {

private static final String JSON = "json";
private static final String YAML = "yaml";

public enum CommandType {
FLATTEN("flatten"),
Expand Down Expand Up @@ -259,7 +260,7 @@ private void populateInputOptions() {
}

private void setDefaultFormat() {
format = inputPath.endsWith(JSON_EXTENSION) ? JSON : "yaml";
format = inputPath.endsWith(JSON_EXTENSION) ? JSON : YAML;
}

private void exitError() {
Expand Down
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
Loading

0 comments on commit 49b5e31

Please sign in to comment.