Skip to content

Commit

Permalink
fix open api swagger yaml not schema bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jerry-024 committed Dec 11, 2024
1 parent 5196caa commit 41d2660
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,32 @@ public static ErrorHandler getInstance() {

@Override
public void accept(ErrorResponse error) {
int code = error.code();
int code = error.getCode();
String message = error.getMessage();
switch (code) {
case 400:
throw new BadRequestException(
String.format("Malformed request: %s", error.message()));
throw new BadRequestException(String.format("Malformed request: %s", message));
case 401:
throw new NotAuthorizedException("Not authorized: %s", error.message());
throw new NotAuthorizedException("Not authorized: %s", message);
case 403:
throw new ForbiddenException("Forbidden: %s", error.message());
throw new ForbiddenException("Forbidden: %s", message);
case 404:
throw new NoSuchResourceException("%s", error.message());
throw new NoSuchResourceException("%s", message);
case 405:
case 406:
break;
case 409:
throw new AlreadyExistsException("%s", error.message());
throw new AlreadyExistsException("%s", message);
case 500:
throw new ServiceFailureException("Server error: %s", error.message());
throw new ServiceFailureException("Server error: %s", message);
case 501:
throw new UnsupportedOperationException(error.message());
throw new UnsupportedOperationException(message);
case 503:
throw new ServiceUnavailableException("Service unavailable: %s", error.message());
throw new ServiceUnavailableException("Service unavailable: %s", message);
default:
break;
}

throw new RESTException("Unable to process: %s", error.message());
throw new RESTException("Unable to process: %s", message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ public FileIO fileIO() {
public List<String> listDatabases() {
ListDatabasesResponse response =
client.get(resourcePaths.databases(), ListDatabasesResponse.class, headers());
if (response.databases() != null) {
return response.databases().stream()
.map(DatabaseName::name)
if (response.getDatabases() != null) {
return response.getDatabases().stream()
.map(DatabaseName::getName)
.collect(Collectors.toList());
}
return ImmutableList.of();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ public Map<String, String> merge(Map<String, String> clientProperties) {
}

@JsonGetter(FIELD_DEFAULTS)
public Map<String, String> defaults() {
public Map<String, String> getDefaults() {
return defaults;
}

@JsonGetter(FIELD_OVERRIDES)
public Map<String, String> overrides() {
public Map<String, String> getOverrides() {
return overrides;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public CreateDatabaseResponse(String name, Map<String, String> properties) {
}

@JsonGetter(FIELD_NAME)
public String name() {
public String getName() {
return name;
}

@JsonGetter(FIELD_PROPERTIES)
public Map<String, String> properties() {
public Map<String, String> getProperties() {
return properties;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public DatabaseName(String name) {
}

@JsonGetter(FIELD_NAME)
public String name() {
public String getName() {
return this.name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ public ErrorResponse(String message, int code, Throwable throwable) {
}

@JsonGetter(FIELD_MESSAGE)
public String message() {
public String getMessage() {
return message;
}

@JsonGetter(FIELD_CODE)
public Integer code() {
public Integer getCode() {
return code;
}

@JsonGetter(FIELD_STACK)
public List<String> stack() {
public List<String> getStack() {
return stack;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,33 @@ public GetDatabaseResponse(String name, Map<String, String> options, @Nullable S
this.comment = comment;
}

@Override
@JsonGetter(FIELD_NAME)
public String name() {
public String getName() {
return name;
}

@Override
@JsonGetter(FIELD_OPTIONS)
public Map<String, String> options() {
public Map<String, String> getOptions() {
return options;
}

@Override
@JsonGetter(FIELD_COMMENT)
public Optional<String> comment() {
public Optional<String> getComment() {
return Optional.ofNullable(comment);
}

@Override
public String name() {
return this.getName();
}

@Override
public Map<String, String> options() {
return this.getOptions();
}

@Override
public Optional<String> comment() {
return this.getComment();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public ListDatabasesResponse(List<DatabaseName> databases) {
}

@JsonGetter(FIELD_DATABASES)
public List<DatabaseName> databases() {
public List<DatabaseName> getDatabases() {
return this.databases;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void testGetConfig() {
}

private void mockOptions(String key, String value) {
String mockResponse = String.format("{\"defaults\": {\"%s\": \"%s\"}}", key, value);
String mockResponse = String.format("{\"getDefaults\": {\"%s\": \"%s\"}}", key, value);
MockResponse mockResponseObj =
new MockResponse()
.setBody(mockResponse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void configResponseParseTest() throws Exception {
ConfigResponse response = new ConfigResponse(conf, conf);
String responseStr = mapper.writeValueAsString(response);
ConfigResponse parseData = mapper.readValue(responseStr, ConfigResponse.class);
assertEquals(conf.get(confKey), parseData.defaults().get(confKey));
assertEquals(conf.get(confKey), parseData.getDefaults().get(confKey));
}

@Test
Expand All @@ -53,7 +53,7 @@ public void errorResponseParseTest() throws Exception {
ErrorResponse response = new ErrorResponse(message, code, new ArrayList<String>());
String responseStr = mapper.writeValueAsString(response);
ErrorResponse parseData = mapper.readValue(responseStr, ErrorResponse.class);
assertEquals(message, parseData.message());
assertEquals(code, parseData.code());
assertEquals(message, parseData.getMessage());
assertEquals(code, parseData.getCode());
}
}
1 change: 1 addition & 0 deletions paimon-open-api/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

# Start the application
cd ..
mvn spotless:apply
mvn clean install -DskipTests
cd ./paimon-open-api
mvn spring-boot:run &
Expand Down
20 changes: 4 additions & 16 deletions paimon-open-api/rest-catalog-open-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ paths:
schema:
$ref: '#/components/schemas/ConfigResponse'
examples:
defaults:
description: defaults
getDefaults:
description: getDefaults
value: |-
{
"k1": "v1",
"k2": "v2",
}
overrides:
description: overrides
getOverrides:
description: getOverrides
value: |-
{
"k3": "v1",
Expand Down Expand Up @@ -164,65 +164,53 @@ components:
properties:
name:
type: string
writeOnly: true
properties:
type: object
additionalProperties:
type: string
writeOnly: true
ErrorResponse:
type: object
properties:
message:
type: string
writeOnly: true
code:
type: integer
format: int32
writeOnly: true
stack:
type: array
writeOnly: true
items:
type: string
DatabaseName:
type: object
properties:
name:
type: string
writeOnly: true
ListDatabasesResponse:
type: object
properties:
databases:
type: array
writeOnly: true
items:
$ref: '#/components/schemas/DatabaseName'
GetDatabaseResponse:
type: object
properties:
name:
type: string
writeOnly: true
options:
type: object
additionalProperties:
type: string
writeOnly: true
comment:
type: string
writeOnly: true
ConfigResponse:
type: object
properties:
defaults:
type: object
additionalProperties:
type: string
writeOnly: true
overrides:
type: object
additionalProperties:
type: string
writeOnly: true
Loading

0 comments on commit 41d2660

Please sign in to comment.