Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

import java.util.*;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNull;

Expand Down Expand Up @@ -40,7 +43,7 @@ public void generateFromResponseSchemaWithPrimitiveType() {
}

@Test
public void generateFromResponseSchemaWithDateFormat() {
public void generateFromResponseSchemaWithDateFormat() throws Exception {
OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/example_generator_test.yaml");

new InlineModelResolver().flatten(openAPI);
Expand All @@ -62,9 +65,11 @@ public void generateFromResponseSchemaWithDateFormat() {
mediaTypeKeys
);

ObjectMapper mapper = new ObjectMapper();

assertEquals(1, examples.size());
assertEquals("application/json", examples.get(0).get("contentType"));
assertEquals(String.format(Locale.ROOT, "{%n \"date_with_example\" : \"2024-01-01\",%n \"date_without_example\" : \"2000-01-23\"%n}"), examples.get(0).get("example"));
assertEquals(mapper.readTree(String.format(Locale.ROOT, "{%n \"date_with_example\" : \"2024-01-01\",%n \"date_without_example\" : \"2000-01-23\"%n}")), mapper.readTree(examples.get(0).get("example")));
assertEquals("200", examples.get(0).get("statusCode"));
}

Expand Down Expand Up @@ -211,7 +216,7 @@ public void generateFromResponseSchemaWithModel() {
}

@Test
public void generateFromResponseSchemaWithAllOfComposedModel() {
public void generateFromResponseSchemaWithAllOfComposedModel() throws Exception{
OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/example_generator_test.yaml");

new InlineModelResolver().flatten(openAPI);
Expand All @@ -233,14 +238,16 @@ public void generateFromResponseSchemaWithAllOfComposedModel() {
mediaTypeKeys
);

ObjectMapper mapper = new ObjectMapper();

assertEquals(1, examples.size());
assertEquals("application/json", examples.get(0).get("contentType"));
assertEquals(String.format(Locale.ROOT, "{%n \"example_schema_property_composed\" : \"example schema property value composed\",%n \"example_schema_property\" : \"example schema property value\"%n}"), examples.get(0).get("example"));
assertEquals(mapper.readTree(String.format(Locale.ROOT, "{%n \"example_schema_property_composed\" : \"example schema property value composed\",%n \"example_schema_property\" : \"example schema property value\"%n}")), mapper.readTree(examples.get(0).get("example")));
assertEquals("200", examples.get(0).get("statusCode"));
}

@Test
public void generateFromResponseSchemaWithAllOfChildComposedModel() {
public void generateFromResponseSchemaWithAllOfChildComposedModel() throws Exception {
OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/example_generator_test.yaml");

new InlineModelResolver().flatten(openAPI);
Expand All @@ -262,9 +269,11 @@ public void generateFromResponseSchemaWithAllOfChildComposedModel() {
mediaTypeKeys
);

ObjectMapper mapper = new ObjectMapper();

assertEquals(1, examples.size());
assertEquals("application/json", examples.get(0).get("contentType"));
assertEquals(String.format(Locale.ROOT, "{%n \"example_schema_property_composed\" : \"example schema property value composed\",%n \"example_schema_property_composed_parent\" : \"example schema property value composed parent\",%n \"example_schema_property\" : \"example schema property value\"%n}"), examples.get(0).get("example"));
assertEquals(mapper.readTree(String.format(Locale.ROOT, "{%n \"example_schema_property_composed\" : \"example schema property value composed\",%n \"example_schema_property_composed_parent\" : \"example schema property value composed parent\",%n \"example_schema_property\" : \"example schema property value\"%n}")), mapper.readTree(examples.get(0).get("example")));
assertEquals("200", examples.get(0).get("statusCode"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1251,29 +1251,33 @@ void testNotDuplicateOauth2FlowsScopes() {

final List<CodegenOperation> codegenOperations = paths.values().stream().flatMap(Collection::stream).collect(Collectors.toList());
final CodegenOperation getWithBasicAuthAndOauth = getByOperationId(codegenOperations, "getWithBasicAuthAndOauth");
assertEquals(getWithBasicAuthAndOauth.authMethods.size(), 3);
assertEquals(getWithBasicAuthAndOauth.authMethods.get(0).name, "basic_auth");
List<CodegenSecurity> sortedAuthMethods = new ArrayList<>(getWithBasicAuthAndOauth.authMethods);
sortedAuthMethods.sort(Comparator.comparing(am -> am.name));
assertEquals(sortedAuthMethods.size(), 3);
assertEquals(sortedAuthMethods.get(0).name, "basic_auth");

final Map<String, Object> passwordFlowScope = getWithBasicAuthAndOauth.authMethods.get(1).scopes.get(0);
final Map<String, Object> passwordFlowScope = sortedAuthMethods.get(1).scopes.get(0);
assertEquals(passwordFlowScope.get("scope"), "something:create");
assertEquals(passwordFlowScope.get("description"), "create from password flow");

final Map<String, Object> clientCredentialsFlow = getWithBasicAuthAndOauth.authMethods.get(2).scopes.get(0);
final Map<String, Object> clientCredentialsFlow = sortedAuthMethods.get(2).scopes.get(0);
assertEquals(clientCredentialsFlow.get("scope"), "something:create");
assertEquals(clientCredentialsFlow.get("description"), "create from client credentials flow");

final CodegenOperation getWithOauthAuth = getByOperationId(codegenOperations, "getWithOauthAuth");
assertEquals(getWithOauthAuth.authMethods.size(), 2);
List<CodegenSecurity> sortedOauthAuthMethods = new ArrayList<>(getWithOauthAuth.authMethods);
sortedOauthAuthMethods.sort(Comparator.comparing(am -> am.name));
assertEquals(sortedOauthAuthMethods.size(), 2);

final Map<String, Object> passwordFlow = getWithOauthAuth.authMethods.get(0).scopes.get(0);
final Map<String, Object> passwordFlow = sortedOauthAuthMethods.get(0).scopes.get(0);
assertEquals(passwordFlow.get("scope"), "something:create");
assertEquals(passwordFlow.get("description"), "create from password flow");

final Map<String, Object> clientCredentialsCreateFlow = getWithOauthAuth.authMethods.get(1).scopes.get(0);
final Map<String, Object> clientCredentialsCreateFlow = sortedOauthAuthMethods.get(1).scopes.get(0);
assertEquals(clientCredentialsCreateFlow.get("scope"), "something:create");
assertEquals(clientCredentialsCreateFlow.get("description"), "create from client credentials flow");

final Map<String, Object> clientCredentialsProcessFlow = getWithOauthAuth.authMethods.get(1).scopes.get(1);
final Map<String, Object> clientCredentialsProcessFlow = sortedOauthAuthMethods.get(1).scopes.get(1);
assertEquals(clientCredentialsProcessFlow.get("scope"), "something:process");
assertEquals(clientCredentialsProcessFlow.get("description"), "process from client credentials flow");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,19 +387,19 @@ public void testBasicGenerationManyAuths() throws IOException {
"Accept: application/json\n" +
"Authorization: Bearer {{bearerToken}}");

TestUtils.assertFileContains(path, "### Get payment methods\n" +
"## Get payment methods\n" +
"GET https://checkout-test.adyen.com/v71/paymentMethods\n" +
"Accept: application/json\n" +
"Authorization: Basic: {{username-password}}\n" +
TestUtils.assertFileContains(path, "### Get payment methods",
"## Get payment methods",
"GET https://checkout-test.adyen.com/v71/paymentMethods",
"Accept: application/json",
"Authorization: Basic: {{username-password}}",
"Authorization: Bearer {{bearerToken}}");

TestUtils.assertFileContains(path, "### Make a payment\n" +
"## Example with a merchant account that doesn&#39;t exist\n" +
"POST https://checkout-test.adyen.com/v71/payments\n" +
"Content-Type: application/json\n" +
"Accept: application/json\n" +
"Cookie: X-API-Key={{cookieKey}}\n" +
TestUtils.assertFileContains(path, "### Make a payment",
"## Example with a merchant account that doesn&#39;t exist",
"POST https://checkout-test.adyen.com/v71/payments",
"Content-Type: application/json",
"Accept: application/json",
"Cookie: X-API-Key={{cookieKey}}",
"Authorization: Bearer {{bearerToken}}");
}

Expand Down
Loading