Skip to content

Commit

Permalink
Merge pull request #173 from andreaTP/fix-uri-template
Browse files Browse the repository at this point in the history
Fix URI template expansion
  • Loading branch information
baywet authored Feb 13, 2023
2 parents 27ac7d0 + b9fb933 commit 364475a
Show file tree
Hide file tree
Showing 9 changed files with 1,225 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

## [0.2.1] - 2023-01-13

### Changed

- Fix #165 incorrect/missing substitutions of `queryParameters` after `pathParameters` and other edge cases

## [0.2.0] - 2023-01-17

### Changed
Expand Down
2 changes: 1 addition & 1 deletion components/abstractions/gradle/dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
dependencies {
// Use JUnit Jupiter API for testing.
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.9.2'
testImplementation 'org.mockito:mockito-inline:5.1.1'

// Use JUnit Jupiter Engine for testing.
Expand All @@ -9,7 +10,6 @@ dependencies {
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:31.1-jre'
implementation 'org.javatuples:javatuples:1.2'
implementation 'com.github.hal4j:uritemplate:1.3.0'
implementation 'javax.annotation:javax.annotation-api:1.3.2'
implementation 'io.opentelemetry:opentelemetry-api:1.23.0'
implementation 'io.opentelemetry:opentelemetry-context:1.22.0'
Expand Down
4 changes: 4 additions & 0 deletions components/abstractions/spotBugsExcludeFilter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
xmlns="https://github.com/spotbugs/filter/3.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubusercontent.com/spotbugs/spotbugs/3.1.0/spotbugs/etc/findbugsfilter.xsd">
<Match>
<Class name="com.microsoft.kiota.UriTemplate$UriTemplateParser" />
<Bug pattern="SF_SWITCH_FALLTHROUGH" />
</Match>
</FindBugsFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@
import com.microsoft.kiota.serialization.Parsable;
import com.microsoft.kiota.serialization.SerializationWriter;

import com.github.hal4j.uritemplate.URITemplate;

import io.opentelemetry.api.trace.Span;
import io.opentelemetry.context.Scope;
import io.opentelemetry.api.GlobalOpenTelemetry;


/** This class represents an abstract HTTP request. */
public class RequestInformation {
/** Creates a new instance of the request information class. */
Expand Down Expand Up @@ -63,11 +62,11 @@ public URI getUri() throws URISyntaxException,IllegalStateException{
if(!pathParameters.containsKey("baseurl") && urlTemplate.toLowerCase(Locale.ROOT).contains("{+baseurl}"))
throw new IllegalStateException("PathParameters must contain a value for \"baseurl\" for the url to be built.");

final URITemplate template = new URITemplate(urlTemplate)
.expandOnly(new HashMap<String, Object>(queryParameters) {{
putAll(pathParameters);
}});
return template.toURI();
Map<String, Object> params = new HashMap<>(pathParameters.size() + queryParameters.size());
params.putAll(pathParameters);
params.putAll(queryParameters);

return new URI(new UriTemplate(urlTemplate).expand(params));
}
}
/**
Expand Down
Loading

0 comments on commit 364475a

Please sign in to comment.