Skip to content

Commit

Permalink
fix: adding organization domain spec file in examples to fix java tes…
Browse files Browse the repository at this point in the history
…t 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.
  • Loading branch information
AsabuHere authored Jun 28, 2024
1 parent e8929a5 commit c81ce44
Show file tree
Hide file tree
Showing 10 changed files with 1,274 additions and 1 deletion.
3 changes: 2 additions & 1 deletion examples/java/src/main/java/com/twilio/Domains.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ public enum Domains {
API("api"),
FLEXAPI("flex-api"),
VERSIONLESS("versionless"),
MESSAGING("messaging");
MESSAGING("messaging"),
PREVIEWIAM("preview-iam");

private final String value;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
/*
* This code was generated by
* ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
* | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
* | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
*
* Organization Public API
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* NOTE: This class is auto generated by OpenAPI Generator.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

package com.twilio.rest.previewiam.organizations;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.twilio.base.noauth.Resource;
import com.twilio.converter.Converter;
import java.util.Currency;
import com.twilio.converter.DateConverter;
import com.twilio.converter.Promoter;
import com.twilio.converter.PrefixedCollapsibleMap;
import com.twilio.converter.CurrencyDeserializer;
import com.twilio.exception.ApiConnectionException;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

import com.twilio.exception.ApiException;
import com.twilio.exception.RestException;
import com.twilio.http.HttpMethod;
import com.twilio.http.Request;
import com.twilio.http.Response;
import com.twilio.http.TwilioRestClient;
import com.twilio.rest.Domains;

import lombok.ToString;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.time.ZonedDateTime;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.Map;
import java.time.LocalDate;
import java.math.BigDecimal;
import com.twilio.type.PhoneNumberCapabilities;
import com.twilio.type.FeedbackIssue;
import com.twilio.type.IceServer;
import com.twilio.type.InboundCallPrice;
import com.twilio.type.OutboundPrefixPriceWithOrigin;
import com.twilio.type.OutboundPrefixPrice;
import com.twilio.type.OutboundCallPriceWithOrigin;
import com.twilio.type.PhoneNumberPrice;
import com.twilio.type.InboundSmsPrice;
import com.twilio.type.OutboundSmsPrice;
import com.twilio.type.OutboundCallPrice;
import com.twilio.type.RecordingRule;
import com.twilio.type.SubscribeRule;

@JsonIgnoreProperties(ignoreUnknown = true)
@ToString
public class Token extends Resource {
private static final long serialVersionUID = 258139119277894L;



public static TokenCreator creator(final String grantType, final String clientId){
return new TokenCreator(grantType, clientId);
}

/**
* Converts a JSON String into a Token object using the provided ObjectMapper.
*
* @param json Raw JSON String
* @param objectMapper Jackson ObjectMapper
* @return Token object represented by the provided JSON
*/
public static Token fromJson(final String json, final ObjectMapper objectMapper) {
// Convert all checked exceptions to Runtime
try {
return objectMapper.readValue(json, Token.class);
} catch (final JsonMappingException | JsonParseException e) {
throw new ApiException(e.getMessage(), e);
} catch (final IOException e) {
throw new ApiConnectionException(e.getMessage(), e);
}
}

/**
* Converts a JSON InputStream into a Token object using the provided
* ObjectMapper.
*
* @param json Raw JSON InputStream
* @param objectMapper Jackson ObjectMapper
* @return Token object represented by the provided JSON
*/
public static Token fromJson(final InputStream json, final ObjectMapper objectMapper) {
// Convert all checked exceptions to Runtime
try {
return objectMapper.readValue(json, Token.class);
} catch (final JsonMappingException | JsonParseException e) {
throw new ApiException(e.getMessage(), e);
} catch (final IOException e) {
throw new ApiConnectionException(e.getMessage(), e);
}
}

private final String accessToken;
private final String refreshToken;
private final String idToken;
private final String tokenType;
private final Long expiresIn;

@JsonCreator
private Token(
@JsonProperty("access_token")
final String accessToken,

@JsonProperty("refresh_token")
final String refreshToken,

@JsonProperty("id_token")
final String idToken,

@JsonProperty("token_type")
final String tokenType,

@JsonProperty("expires_in")
final Long expiresIn
) {
this.accessToken = accessToken;
this.refreshToken = refreshToken;
this.idToken = idToken;
this.tokenType = tokenType;
this.expiresIn = expiresIn;
}

public final String getAccessToken() {
return this.accessToken;
}
public final String getRefreshToken() {
return this.refreshToken;
}
public final String getIdToken() {
return this.idToken;
}
public final String getTokenType() {
return this.tokenType;
}
public final Long getExpiresIn() {
return this.expiresIn;
}

@Override
public boolean equals(final Object o) {
if (this==o) {
return true;
}

if (o == null || getClass() != o.getClass()) {
return false;
}

Token other = (Token) o;

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) ;
}

@Override
public int hashCode() {
return Objects.hash(accessToken, refreshToken, idToken, tokenType, expiresIn);
}


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/*
* This code was generated by
* ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
* | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
* | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
*
* Organization Public API
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* NOTE: This class is auto generated by OpenAPI Generator.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

package com.twilio.rest.previewiam.organizations;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.twilio.constant.EnumConstants;
import com.twilio.converter.Promoter;
import com.twilio.exception.ApiConnectionException;
import com.twilio.converter.PrefixedCollapsibleMap;
import com.twilio.converter.Converter;
import com.twilio.exception.ApiException;
import com.twilio.exception.RestException;
import com.twilio.http.HttpMethod;
import com.twilio.http.Response;
import com.twilio.rest.Domains;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.time.LocalDate;
import com.twilio.converter.Converter;
import java.time.ZonedDateTime;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.net.URI;
import java.time.format.DateTimeFormatter;
import com.twilio.converter.DateConverter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;

import lombok.ToString;

import java.net.URI;

import com.twilio.base.noauth.Creator;
import com.twilio.http.noauth.NoAuthRequest;
import com.twilio.http.noauth.NoAuthTwilioRestClient;

public class TokenCreator extends Creator<Token>{
private String grantType;
private String clientId;
private String clientSecret;
private String code;
private String redirectUri;
private String audience;
private String refreshToken;
private String scope;

public TokenCreator(final String grantType, final String clientId) {
this.grantType = grantType;
this.clientId = clientId;
}

public TokenCreator setGrantType(final String grantType){
this.grantType = grantType;
return this;
}
public TokenCreator setClientId(final String clientId){
this.clientId = clientId;
return this;
}
public TokenCreator setClientSecret(final String clientSecret){
this.clientSecret = clientSecret;
return this;
}
public TokenCreator setCode(final String code){
this.code = code;
return this;
}
public TokenCreator setRedirectUri(final String redirectUri){
this.redirectUri = redirectUri;
return this;
}
public TokenCreator setAudience(final String audience){
this.audience = audience;
return this;
}
public TokenCreator setRefreshToken(final String refreshToken){
this.refreshToken = refreshToken;
return this;
}
public TokenCreator setScope(final String scope){
this.scope = scope;
return this;
}

@Override
public Token create(final NoAuthTwilioRestClient client){
String path = "/v1/token";

path = path.replace("{"+"grant_type"+"}", this.grantType.toString());
path = path.replace("{"+"client_id"+"}", this.clientId.toString());

NoAuthRequest request = new NoAuthRequest(
HttpMethod.POST,
Domains.PREVIEWIAM.toString(),
path
);
request.setContentType(EnumConstants.ContentType.FORM_URLENCODED);
addPostParams(request);
Response response = client.request(request);
if (response == null) {
throw new ApiConnectionException("Token creation failed: Unable to connect to server");
} else if (!NoAuthTwilioRestClient.SUCCESS.test(response.getStatusCode())) {
RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper());
if (restException == null) {
throw new ApiException("Server Error, no content", response.getStatusCode());
}
throw new ApiException(restException);
}

return Token.fromJson(response.getStream(), client.getObjectMapper());
}
private void addPostParams(final NoAuthRequest request) {
if (grantType != null) {
request.addPostParam("grant_type", grantType);

}
if (clientId != null) {
request.addPostParam("client_id", clientId);

}
if (clientSecret != null) {
request.addPostParam("client_secret", clientSecret);

}
if (code != null) {
request.addPostParam("code", code);

}
if (redirectUri != null) {
request.addPostParam("redirect_uri", redirectUri);

}
if (audience != null) {
request.addPostParam("audience", audience);

}
if (refreshToken != null) {
request.addPostParam("refresh_token", refreshToken);

}
if (scope != null) {
request.addPostParam("scope", scope);

}
}
}
Loading

0 comments on commit c81ce44

Please sign in to comment.