Skip to content

Commit c81ce44

Browse files
authored
fix: adding organization domain spec file in examples to fix java test failure (#590)
<!-- We appreciate the effort for this pull request but before that please make sure you read the contribution guidelines, then fill out the blanks below. Please format the PR title appropriately based on the type of change: <type>[!]: <description> Where <type> is one of: docs, chore, feat, fix, test, misc. Add a '!' after the type for breaking changes (e.g. feat!: new breaking feature). **All third-party contributors acknowledge that any contributions they provide will be made under the same open-source license that the open-source project is provided under.** Please enter each Issue number you are resolving in your PR after one of the following words [Fixes, Closes, Resolves]. This will auto-link these issues and close them when this PR is merged! e.g. Fixes #1 Closes #2 --> # Fixes # Java Test [failures](https://github.com/twilio/twilio-oai-generator/actions/runs/9695482909/job/26755337612#step:7:2475) in twilio-oai-generator repo because some files in http directory are expecting the organizations domain in rest folder. Adding spec file for generating sample files for organization domain ### Checklist - [x] I acknowledge that all my contributions will be made under the project's license - [ ] Run `make test-docker` - [ ] Verify affected language: - [ ] Generate [twilio-go](https://github.com/twilio/twilio-go) from our [OpenAPI specification](https://github.com/twilio/twilio-oai) using the [build_twilio_go.py](./examples/build_twilio_go.py) using `python examples/build_twilio_go.py path/to/twilio-oai/spec/yaml path/to/twilio-go` and inspect the diff - [ ] Run `make test` in `twilio-go` - [ ] Create a pull request in `twilio-go` - [ ] Provide a link below to the pull request - [ ] I have made a material change to the repo (functionality, testing, spelling, grammar) - [ ] I have read the [Contribution Guidelines](https://github.com/twilio/twilio-oai-generator/blob/main/CONTRIBUTING.md) and my PR follows them - [ ] I have titled the PR appropriately - [ ] I have updated my branch with the main branch - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] I have added the necessary documentation about the functionality in the appropriate .md file - [ ] I have added inline documentation to the code I modified If you have questions, please create a GitHub Issue in this repository.
1 parent e8929a5 commit c81ce44

File tree

10 files changed

+1274
-1
lines changed

10 files changed

+1274
-1
lines changed

examples/java/src/main/java/com/twilio/Domains.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ public enum Domains {
44
API("api"),
55
FLEXAPI("flex-api"),
66
VERSIONLESS("versionless"),
7-
MESSAGING("messaging");
7+
MESSAGING("messaging"),
8+
PREVIEWIAM("preview-iam");
89

910
private final String value;
1011

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
/*
2+
* This code was generated by
3+
* ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
4+
* | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
5+
* | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
6+
*
7+
* Organization Public API
8+
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
9+
*
10+
* NOTE: This class is auto generated by OpenAPI Generator.
11+
* https://openapi-generator.tech
12+
* Do not edit the class manually.
13+
*/
14+
15+
package com.twilio.rest.previewiam.organizations;
16+
17+
import com.fasterxml.jackson.annotation.JsonCreator;
18+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
19+
import com.fasterxml.jackson.annotation.JsonInclude;
20+
import com.fasterxml.jackson.annotation.JsonProperty;
21+
import com.fasterxml.jackson.core.JsonParseException;
22+
import com.fasterxml.jackson.core.JsonProcessingException;
23+
import com.fasterxml.jackson.databind.JsonMappingException;
24+
import com.fasterxml.jackson.databind.ObjectMapper;
25+
import com.twilio.base.noauth.Resource;
26+
import com.twilio.converter.Converter;
27+
import java.util.Currency;
28+
import com.twilio.converter.DateConverter;
29+
import com.twilio.converter.Promoter;
30+
import com.twilio.converter.PrefixedCollapsibleMap;
31+
import com.twilio.converter.CurrencyDeserializer;
32+
import com.twilio.exception.ApiConnectionException;
33+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
34+
35+
import com.twilio.exception.ApiException;
36+
import com.twilio.exception.RestException;
37+
import com.twilio.http.HttpMethod;
38+
import com.twilio.http.Request;
39+
import com.twilio.http.Response;
40+
import com.twilio.http.TwilioRestClient;
41+
import com.twilio.rest.Domains;
42+
43+
import lombok.ToString;
44+
45+
import java.io.IOException;
46+
import java.io.InputStream;
47+
import java.net.URI;
48+
import java.time.ZonedDateTime;
49+
50+
import java.util.ArrayList;
51+
import java.util.HashMap;
52+
import java.util.List;
53+
import java.util.Map;
54+
import java.util.Objects;
55+
56+
import lombok.Getter;
57+
import lombok.Setter;
58+
import lombok.ToString;
59+
60+
import java.util.Map;
61+
import java.time.LocalDate;
62+
import java.math.BigDecimal;
63+
import com.twilio.type.PhoneNumberCapabilities;
64+
import com.twilio.type.FeedbackIssue;
65+
import com.twilio.type.IceServer;
66+
import com.twilio.type.InboundCallPrice;
67+
import com.twilio.type.OutboundPrefixPriceWithOrigin;
68+
import com.twilio.type.OutboundPrefixPrice;
69+
import com.twilio.type.OutboundCallPriceWithOrigin;
70+
import com.twilio.type.PhoneNumberPrice;
71+
import com.twilio.type.InboundSmsPrice;
72+
import com.twilio.type.OutboundSmsPrice;
73+
import com.twilio.type.OutboundCallPrice;
74+
import com.twilio.type.RecordingRule;
75+
import com.twilio.type.SubscribeRule;
76+
77+
@JsonIgnoreProperties(ignoreUnknown = true)
78+
@ToString
79+
public class Token extends Resource {
80+
private static final long serialVersionUID = 258139119277894L;
81+
82+
83+
84+
public static TokenCreator creator(final String grantType, final String clientId){
85+
return new TokenCreator(grantType, clientId);
86+
}
87+
88+
/**
89+
* Converts a JSON String into a Token object using the provided ObjectMapper.
90+
*
91+
* @param json Raw JSON String
92+
* @param objectMapper Jackson ObjectMapper
93+
* @return Token object represented by the provided JSON
94+
*/
95+
public static Token fromJson(final String json, final ObjectMapper objectMapper) {
96+
// Convert all checked exceptions to Runtime
97+
try {
98+
return objectMapper.readValue(json, Token.class);
99+
} catch (final JsonMappingException | JsonParseException e) {
100+
throw new ApiException(e.getMessage(), e);
101+
} catch (final IOException e) {
102+
throw new ApiConnectionException(e.getMessage(), e);
103+
}
104+
}
105+
106+
/**
107+
* Converts a JSON InputStream into a Token object using the provided
108+
* ObjectMapper.
109+
*
110+
* @param json Raw JSON InputStream
111+
* @param objectMapper Jackson ObjectMapper
112+
* @return Token object represented by the provided JSON
113+
*/
114+
public static Token fromJson(final InputStream json, final ObjectMapper objectMapper) {
115+
// Convert all checked exceptions to Runtime
116+
try {
117+
return objectMapper.readValue(json, Token.class);
118+
} catch (final JsonMappingException | JsonParseException e) {
119+
throw new ApiException(e.getMessage(), e);
120+
} catch (final IOException e) {
121+
throw new ApiConnectionException(e.getMessage(), e);
122+
}
123+
}
124+
125+
private final String accessToken;
126+
private final String refreshToken;
127+
private final String idToken;
128+
private final String tokenType;
129+
private final Long expiresIn;
130+
131+
@JsonCreator
132+
private Token(
133+
@JsonProperty("access_token")
134+
final String accessToken,
135+
136+
@JsonProperty("refresh_token")
137+
final String refreshToken,
138+
139+
@JsonProperty("id_token")
140+
final String idToken,
141+
142+
@JsonProperty("token_type")
143+
final String tokenType,
144+
145+
@JsonProperty("expires_in")
146+
final Long expiresIn
147+
) {
148+
this.accessToken = accessToken;
149+
this.refreshToken = refreshToken;
150+
this.idToken = idToken;
151+
this.tokenType = tokenType;
152+
this.expiresIn = expiresIn;
153+
}
154+
155+
public final String getAccessToken() {
156+
return this.accessToken;
157+
}
158+
public final String getRefreshToken() {
159+
return this.refreshToken;
160+
}
161+
public final String getIdToken() {
162+
return this.idToken;
163+
}
164+
public final String getTokenType() {
165+
return this.tokenType;
166+
}
167+
public final Long getExpiresIn() {
168+
return this.expiresIn;
169+
}
170+
171+
@Override
172+
public boolean equals(final Object o) {
173+
if (this==o) {
174+
return true;
175+
}
176+
177+
if (o == null || getClass() != o.getClass()) {
178+
return false;
179+
}
180+
181+
Token other = (Token) o;
182+
183+
return Objects.equals(accessToken, other.accessToken) && Objects.equals(refreshToken, other.refreshToken) && Objects.equals(idToken, other.idToken) && Objects.equals(tokenType, other.tokenType) && Objects.equals(expiresIn, other.expiresIn) ;
184+
}
185+
186+
@Override
187+
public int hashCode() {
188+
return Objects.hash(accessToken, refreshToken, idToken, tokenType, expiresIn);
189+
}
190+
191+
192+
}
193+
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/*
2+
* This code was generated by
3+
* ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
4+
* | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
5+
* | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
6+
*
7+
* Organization Public API
8+
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
9+
*
10+
* NOTE: This class is auto generated by OpenAPI Generator.
11+
* https://openapi-generator.tech
12+
* Do not edit the class manually.
13+
*/
14+
15+
package com.twilio.rest.previewiam.organizations;
16+
17+
import com.fasterxml.jackson.databind.ObjectMapper;
18+
import com.twilio.constant.EnumConstants;
19+
import com.twilio.converter.Promoter;
20+
import com.twilio.exception.ApiConnectionException;
21+
import com.twilio.converter.PrefixedCollapsibleMap;
22+
import com.twilio.converter.Converter;
23+
import com.twilio.exception.ApiException;
24+
import com.twilio.exception.RestException;
25+
import com.twilio.http.HttpMethod;
26+
import com.twilio.http.Response;
27+
import com.twilio.rest.Domains;
28+
import java.math.BigDecimal;
29+
import java.util.List;
30+
import java.util.Map;
31+
import java.time.LocalDate;
32+
import com.twilio.converter.Converter;
33+
import java.time.ZonedDateTime;
34+
import java.io.IOException;
35+
import java.io.InputStream;
36+
import java.math.BigDecimal;
37+
import java.net.URI;
38+
import java.time.format.DateTimeFormatter;
39+
import com.twilio.converter.DateConverter;
40+
41+
import java.util.ArrayList;
42+
import java.util.HashMap;
43+
import java.util.List;
44+
import java.util.Map;
45+
import java.util.Objects;
46+
import java.util.UUID;
47+
48+
import lombok.ToString;
49+
50+
import java.net.URI;
51+
52+
import com.twilio.base.noauth.Creator;
53+
import com.twilio.http.noauth.NoAuthRequest;
54+
import com.twilio.http.noauth.NoAuthTwilioRestClient;
55+
56+
public class TokenCreator extends Creator<Token>{
57+
private String grantType;
58+
private String clientId;
59+
private String clientSecret;
60+
private String code;
61+
private String redirectUri;
62+
private String audience;
63+
private String refreshToken;
64+
private String scope;
65+
66+
public TokenCreator(final String grantType, final String clientId) {
67+
this.grantType = grantType;
68+
this.clientId = clientId;
69+
}
70+
71+
public TokenCreator setGrantType(final String grantType){
72+
this.grantType = grantType;
73+
return this;
74+
}
75+
public TokenCreator setClientId(final String clientId){
76+
this.clientId = clientId;
77+
return this;
78+
}
79+
public TokenCreator setClientSecret(final String clientSecret){
80+
this.clientSecret = clientSecret;
81+
return this;
82+
}
83+
public TokenCreator setCode(final String code){
84+
this.code = code;
85+
return this;
86+
}
87+
public TokenCreator setRedirectUri(final String redirectUri){
88+
this.redirectUri = redirectUri;
89+
return this;
90+
}
91+
public TokenCreator setAudience(final String audience){
92+
this.audience = audience;
93+
return this;
94+
}
95+
public TokenCreator setRefreshToken(final String refreshToken){
96+
this.refreshToken = refreshToken;
97+
return this;
98+
}
99+
public TokenCreator setScope(final String scope){
100+
this.scope = scope;
101+
return this;
102+
}
103+
104+
@Override
105+
public Token create(final NoAuthTwilioRestClient client){
106+
String path = "/v1/token";
107+
108+
path = path.replace("{"+"grant_type"+"}", this.grantType.toString());
109+
path = path.replace("{"+"client_id"+"}", this.clientId.toString());
110+
111+
NoAuthRequest request = new NoAuthRequest(
112+
HttpMethod.POST,
113+
Domains.PREVIEWIAM.toString(),
114+
path
115+
);
116+
request.setContentType(EnumConstants.ContentType.FORM_URLENCODED);
117+
addPostParams(request);
118+
Response response = client.request(request);
119+
if (response == null) {
120+
throw new ApiConnectionException("Token creation failed: Unable to connect to server");
121+
} else if (!NoAuthTwilioRestClient.SUCCESS.test(response.getStatusCode())) {
122+
RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper());
123+
if (restException == null) {
124+
throw new ApiException("Server Error, no content", response.getStatusCode());
125+
}
126+
throw new ApiException(restException);
127+
}
128+
129+
return Token.fromJson(response.getStream(), client.getObjectMapper());
130+
}
131+
private void addPostParams(final NoAuthRequest request) {
132+
if (grantType != null) {
133+
request.addPostParam("grant_type", grantType);
134+
135+
}
136+
if (clientId != null) {
137+
request.addPostParam("client_id", clientId);
138+
139+
}
140+
if (clientSecret != null) {
141+
request.addPostParam("client_secret", clientSecret);
142+
143+
}
144+
if (code != null) {
145+
request.addPostParam("code", code);
146+
147+
}
148+
if (redirectUri != null) {
149+
request.addPostParam("redirect_uri", redirectUri);
150+
151+
}
152+
if (audience != null) {
153+
request.addPostParam("audience", audience);
154+
155+
}
156+
if (refreshToken != null) {
157+
request.addPostParam("refresh_token", refreshToken);
158+
159+
}
160+
if (scope != null) {
161+
request.addPostParam("scope", scope);
162+
163+
}
164+
}
165+
}

0 commit comments

Comments
 (0)