Skip to content

Commit

Permalink
Merge pull request #12133 from GihanAyesh/master
Browse files Browse the repository at this point in the history
Check updated title and version in the swagger definition
  • Loading branch information
tgtshanika authored Sep 11, 2023
2 parents 53a55ce + 3bfc39a commit 3a95dec
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -616,12 +616,9 @@ private String generateAPIDefinition(SwaggerData swaggerData, Swagger swaggerObj
updateSwaggerSecurityDefinition(swaggerObj, swaggerData, "https://test.com");
updateLegacyScopesFromSwagger(swaggerObj, swaggerData);

if (StringUtils.isEmpty(swaggerObj.getInfo().getTitle())) {
swaggerObj.getInfo().setTitle(swaggerData.getTitle());
}
if (StringUtils.isEmpty(swaggerObj.getInfo().getVersion())) {
swaggerObj.getInfo().setVersion(swaggerData.getVersion());
}
swaggerObj.getInfo().setTitle(swaggerData.getTitle());
swaggerObj.getInfo().setVersion(swaggerData.getVersion());

preserveResourcePathOrderFromAPI(swaggerData, swaggerObj);
return getSwaggerJsonString(swaggerObj);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -699,10 +699,8 @@ private String generateAPIDefinition(SwaggerData swaggerData, OpenAPI openAPI) t
updateLegacyScopesFromSwagger(openAPI, swaggerData);

openAPI.getInfo().setTitle(swaggerData.getTitle());
openAPI.getInfo().setVersion(swaggerData.getVersion());

if (StringUtils.isEmpty(openAPI.getInfo().getVersion())) {
openAPI.getInfo().setVersion(swaggerData.getVersion());
}
if (!APIConstants.GRAPHQL_API.equals(swaggerData.getTransportType())) {
preserveResourcePathOrderFromAPI(swaggerData, openAPI);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,16 @@ public void testGenerateAPIDefinition(APIDefinition parser) throws Exception {
}

public void testGenerateAPIDefinition2(APIDefinition parser, String content, OASParserEvaluator evaluator) throws Exception {
String updateApiName = "updatedAPI";
String updateApiVersion = "2.0.0";
String INFO_KEY = "info";
String TITLE_KEY = "title";
String VERSION_KEY = "version";

JSONObject jsonObject = new JSONObject(content);
String equalNoOfResources = jsonObject.getJSONObject("equalNoOfResources").toString();

APIIdentifier identifier = new APIIdentifier("admin", "simple", "1.0.0");
APIIdentifier identifier = new APIIdentifier("admin", updateApiName, updateApiVersion);
API api = new API(identifier);
api.setScopes(new HashSet<>(Arrays.asList(sampleScope, extensionScope)));
api.setUriTemplates(new HashSet<>(Arrays.asList(petGet, petPost, itemGet, itemPost)));
Expand All @@ -189,6 +195,16 @@ public void testGenerateAPIDefinition2(APIDefinition parser, String content, OAS
Assert.assertTrue(response.isValid());
Assert.assertTrue(response.getParser().getClass().equals(parser.getClass()));

JSONObject jsonDefinition = new JSONObject(definition);
// Access the "info" object in the swagger definition
JSONObject infoObject = jsonDefinition.getJSONObject(INFO_KEY);
String title = infoObject.getString(TITLE_KEY);
String version = infoObject.getString(VERSION_KEY);

// Assert the updated title and version in the swagger definition
Assert.assertEquals(updateApiName, title);
Assert.assertEquals(updateApiVersion, version);

Set<URITemplate> uriTemplates = parser.getURITemplates(definition);
Assert.assertEquals(4, uriTemplates.size());
Assert.assertTrue(uriTemplates.contains(petGet));
Expand Down

0 comments on commit 3a95dec

Please sign in to comment.