Skip to content

Commit f85e2e8

Browse files
committed
Add test; Minor syntax improvement
1 parent 36955cf commit f85e2e8

File tree

5 files changed

+487
-17
lines changed

5 files changed

+487
-17
lines changed

datamodel/openapi/openapi-generator/src/test/java/com/sap/cloud/sdk/datamodel/openapi/generator/DataModelGeneratorIntegrationTest.java

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
package com.sap.cloud.sdk.datamodel.openapi.generator;
66

7+
import static java.util.Map.entry;
8+
import static java.util.Map.ofEntries;
9+
710
import static org.assertj.core.api.Assertions.assertThat;
811

912
import java.nio.file.Files;
@@ -98,14 +101,10 @@ private enum TestCase
98101
true,
99102
true,
100103
6,
101-
Map
102-
.of(
103-
"pojoBuilderMethodName",
104-
"builder",
105-
"pojoBuildMethodName",
106-
"build",
107-
"pojoConstructorVisibility",
108-
"private")),
104+
ofEntries(
105+
entry("pojoBuilderMethodName", "builder"),
106+
entry("pojoBuildMethodName", "build"),
107+
entry("pojoConstructorVisibility", "private"))),
109108
REMOVE_OPERATION_ID_PREFIX(
110109
"remove-operation-id-prefix",
111110
"sodastore.json",
@@ -115,14 +114,10 @@ private enum TestCase
115114
true,
116115
true,
117116
6,
118-
Map
119-
.of(
120-
"removeOperationIdPrefix",
121-
"true",
122-
"removeOperationIdPrefixDelimiter",
123-
"\\.",
124-
"removeOperationIdPrefixCount",
125-
"3")),
117+
ofEntries(
118+
entry("removeOperationIdPrefix", "true"),
119+
entry("removeOperationIdPrefixDelimiter", "\\."),
120+
entry("removeOperationIdPrefixCount", "3"))),
126121
GENERATE_APIS(
127122
"generate-apis",
128123
"sodastore.yaml",
@@ -132,7 +127,17 @@ private enum TestCase
132127
true,
133128
false,
134129
7,
135-
Map.of());
130+
Map.of()),
131+
GENERATE_MODELS(
132+
"generate-models",
133+
"sodastore.yaml",
134+
"test",
135+
"test",
136+
ApiMaturity.RELEASED,
137+
true,
138+
true,
139+
3,
140+
ofEntries(entry("apisToGenerate", "Default, NotExist"), entry("modelsToGenerate", "Cola,Fanta ,NotExist")));
136141

137142
final String testCaseName;
138143
final String inputSpecFileName;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
openapi: 3.0.0
2+
info:
3+
title: Soda Store API
4+
version: 1.0.0
5+
description: API for managing sodas in a soda store
6+
paths:
7+
/sodas:
8+
get:
9+
summary: Get a list of all sodas
10+
operationId: getSodas
11+
responses:
12+
'200':
13+
description: A list of sodas
14+
content:
15+
application/json:
16+
schema:
17+
type: array
18+
items:
19+
$ref: '#/components/schemas/OneOf'
20+
components:
21+
schemas:
22+
OneOfWithDiscriminatorAndMapping:
23+
oneOf:
24+
- $ref: '#/components/schemas/Cola'
25+
- $ref: '#/components/schemas/Fanta'
26+
discriminator:
27+
propertyName: sodaType
28+
mapping:
29+
Cola: '#/components/schemas/Cola'
30+
Fanta: '#/components/schemas/Fanta'
31+
OneOfWithDiscriminator:
32+
oneOf:
33+
- $ref: '#/components/schemas/Cola'
34+
- $ref: '#/components/schemas/Fanta'
35+
discriminator:
36+
propertyName: sodaType
37+
OneOf:
38+
oneOf:
39+
- $ref: '#/components/schemas/Cola'
40+
- $ref: '#/components/schemas/Fanta'
41+
AnyOf:
42+
anyOf:
43+
- $ref: '#/components/schemas/Cola'
44+
- $ref: '#/components/schemas/Fanta'
45+
AllOf:
46+
allOf:
47+
- $ref: '#/components/schemas/Cola'
48+
- $ref: '#/components/schemas/Fanta'
49+
Cola:
50+
type: object
51+
properties:
52+
sodaType:
53+
type: string
54+
Fanta:
55+
type: object
56+
properties:
57+
sodaType:
58+
type: string
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/*
2+
* Copyright (c) 2024 SAP SE or an SAP affiliate company. All rights reserved.
3+
*/
4+
5+
/*
6+
* Soda Store API
7+
* API for managing sodas in a soda store
8+
*
9+
* The version of the OpenAPI document: 1.0.0
10+
*
11+
*
12+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
13+
* https://openapi-generator.tech
14+
* Do not edit the class manually.
15+
*/
16+
17+
package test;
18+
19+
import java.util.Objects;
20+
import java.util.Arrays;
21+
import java.util.LinkedHashMap;
22+
import java.util.Map;
23+
import java.util.NoSuchElementException;
24+
import java.util.Set;
25+
import com.fasterxml.jackson.annotation.JsonInclude;
26+
import com.fasterxml.jackson.annotation.JsonProperty;
27+
import com.fasterxml.jackson.annotation.JsonCreator;
28+
import com.fasterxml.jackson.annotation.JsonTypeName;
29+
import com.fasterxml.jackson.annotation.JsonValue;
30+
import com.fasterxml.jackson.annotation.JsonAnySetter;
31+
import com.fasterxml.jackson.annotation.JsonAnyGetter;
32+
import com.fasterxml.jackson.annotation.JsonIgnore;
33+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
34+
35+
import javax.annotation.Nonnull;
36+
import javax.annotation.Nullable;
37+
38+
/**
39+
* Cola
40+
*/
41+
// CHECKSTYLE:OFF
42+
public class Cola
43+
// CHECKSTYLE:ON
44+
{
45+
@JsonProperty("sodaType")
46+
private String sodaType;
47+
48+
@JsonAnySetter
49+
@JsonAnyGetter
50+
private final Map<String, Object> cloudSdkCustomFields = new LinkedHashMap<>();
51+
52+
/**
53+
* Set the sodaType of this {@link Cola} instance and return the same instance.
54+
*
55+
* @param sodaType The sodaType of this {@link Cola}
56+
* @return The same instance of this {@link Cola} class
57+
*/
58+
@Nonnull public Cola sodaType( @Nullable final String sodaType) {
59+
this.sodaType = sodaType;
60+
return this;
61+
}
62+
63+
/**
64+
* Get sodaType
65+
* @return sodaType The sodaType of this {@link Cola} instance.
66+
*/
67+
@Nonnull
68+
public String getSodaType() {
69+
return sodaType;
70+
}
71+
72+
/**
73+
* Set the sodaType of this {@link Cola} instance.
74+
*
75+
* @param sodaType The sodaType of this {@link Cola}
76+
*/
77+
public void setSodaType( @Nullable final String sodaType) {
78+
this.sodaType = sodaType;
79+
}
80+
81+
/**
82+
* Get the names of the unrecognizable properties of the {@link Cola}.
83+
* @return The set of properties names
84+
*/
85+
@JsonIgnore
86+
@Nonnull
87+
public Set<String> getCustomFieldNames() {
88+
return cloudSdkCustomFields.keySet();
89+
}
90+
91+
/**
92+
* Get the value of an unrecognizable property of this {@link Cola} instance.
93+
* @param name The name of the property
94+
* @return The value of the property
95+
* @throws NoSuchElementException If no property with the given name could be found.
96+
*/
97+
@Nullable
98+
public Object getCustomField( @Nonnull final String name ) throws NoSuchElementException {
99+
if( !cloudSdkCustomFields.containsKey(name) ) {
100+
throw new NoSuchElementException("Cola has no field with name '" + name + "'.");
101+
}
102+
return cloudSdkCustomFields.get(name);
103+
}
104+
105+
/**
106+
* Set an unrecognizable property of this {@link Cola} instance. If the map previously contained a mapping
107+
* for the key, the old value is replaced by the specified value.
108+
* @param customFieldName The name of the property
109+
* @param customFieldValue The value of the property
110+
*/
111+
@JsonIgnore
112+
public void setCustomField( @Nonnull String customFieldName, @Nullable Object customFieldValue )
113+
{
114+
cloudSdkCustomFields.put(customFieldName, customFieldValue);
115+
}
116+
117+
118+
@Override
119+
public boolean equals(@Nullable final java.lang.Object o) {
120+
if (this == o) {
121+
return true;
122+
}
123+
if (o == null || getClass() != o.getClass()) {
124+
return false;
125+
}
126+
final Cola cola = (Cola) o;
127+
return Objects.equals(this.cloudSdkCustomFields, cola.cloudSdkCustomFields) &&
128+
Objects.equals(this.sodaType, cola.sodaType);
129+
}
130+
131+
@Override
132+
public int hashCode() {
133+
return Objects.hash(sodaType, cloudSdkCustomFields);
134+
}
135+
136+
@Override
137+
@Nonnull public String toString() {
138+
final StringBuilder sb = new StringBuilder();
139+
sb.append("class Cola {\n");
140+
sb.append(" sodaType: ").append(toIndentedString(sodaType)).append("\n");
141+
cloudSdkCustomFields.forEach((k,v) -> sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n"));
142+
sb.append("}");
143+
return sb.toString();
144+
}
145+
146+
/**
147+
* Convert the given object to string with each line indented by 4 spaces
148+
* (except the first line).
149+
*/
150+
private String toIndentedString(final java.lang.Object o) {
151+
if (o == null) {
152+
return "null";
153+
}
154+
return o.toString().replace("\n", "\n ");
155+
}
156+
157+
}
158+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright (c) 2024 SAP SE or an SAP affiliate company. All rights reserved.
3+
*/
4+
5+
package test;
6+
7+
import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException;
8+
import com.sap.cloud.sdk.services.openapi.core.OpenApiResponse;
9+
import com.sap.cloud.sdk.services.openapi.core.AbstractOpenApiService;
10+
import com.sap.cloud.sdk.services.openapi.apiclient.ApiClient;
11+
12+
import test.OneOf;
13+
14+
import java.util.HashMap;
15+
import java.util.List;
16+
import java.util.Locale;
17+
import java.util.Map;
18+
19+
import org.springframework.util.LinkedMultiValueMap;
20+
import org.springframework.util.MultiValueMap;
21+
import org.springframework.web.util.UriComponentsBuilder;
22+
import org.springframework.core.ParameterizedTypeReference;
23+
import org.springframework.core.io.FileSystemResource;
24+
import org.springframework.http.HttpHeaders;
25+
import org.springframework.http.HttpMethod;
26+
import org.springframework.http.MediaType;
27+
28+
import javax.annotation.Nonnull;
29+
import javax.annotation.Nullable;
30+
import com.google.common.annotations.Beta;
31+
32+
import com.sap.cloud.sdk.cloudplatform.connectivity.Destination;
33+
34+
/**
35+
* Soda Store API in version 1.0.0.
36+
*
37+
* API for managing sodas in a soda store
38+
*/
39+
public class DefaultApi extends AbstractOpenApiService {
40+
/**
41+
* Instantiates this API class to invoke operations on the Soda Store API.
42+
*
43+
* @param httpDestination The destination that API should be used with
44+
*/
45+
public DefaultApi( @Nonnull final Destination httpDestination )
46+
{
47+
super(httpDestination);
48+
}
49+
50+
/**
51+
* Instantiates this API class to invoke operations on the Soda Store API based on a given {@link ApiClient}.
52+
*
53+
* @param apiClient
54+
* ApiClient to invoke the API on
55+
*/
56+
@Beta
57+
public DefaultApi( @Nonnull final ApiClient apiClient )
58+
{
59+
super(apiClient);
60+
}
61+
62+
/**
63+
* <p>Get a list of all sodas</p>
64+
* <p></p>
65+
* <p><b>200</b> - A list of sodas
66+
* @return List&lt;OneOf&gt;
67+
* @throws OpenApiRequestException if an error occurs while attempting to invoke the API
68+
*/
69+
@Nonnull
70+
public List<OneOf> getSodas() throws OpenApiRequestException {
71+
final Object localVarPostBody = null;
72+
73+
final String localVarPath = UriComponentsBuilder.fromPath("/sodas").build().toUriString();
74+
75+
final MultiValueMap<String, String> localVarQueryParams = new LinkedMultiValueMap<String, String>();
76+
final HttpHeaders localVarHeaderParams = new HttpHeaders();
77+
final MultiValueMap<String, Object> localVarFormParams = new LinkedMultiValueMap<String, Object>();
78+
79+
final String[] localVarAccepts = {
80+
"application/json"
81+
};
82+
final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
83+
final String[] localVarContentTypes = { };
84+
final MediaType localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
85+
86+
final String[] localVarAuthNames = new String[] { };
87+
88+
final ParameterizedTypeReference<List<OneOf>> localVarReturnType = new ParameterizedTypeReference<List<OneOf>>() {};
89+
return apiClient.invokeAPI(localVarPath, HttpMethod.GET, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType);
90+
}
91+
}

0 commit comments

Comments
 (0)