Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for resolveTemplate and resolveTemplates #342

Merged
merged 1 commit into from
Aug 31, 2023
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
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 original authors
* Copyright 2017-2023 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,7 +32,7 @@
*/
public class JaxRsUriBuilder extends UriBuilder {

private final io.micronaut.http.uri.UriBuilder uriBuilder;
private io.micronaut.http.uri.UriBuilder uriBuilder;

/**
* Default constructor.
Expand Down Expand Up @@ -180,7 +180,8 @@ public UriBuilder fragment(String fragment) {

@Override
public UriBuilder resolveTemplate(String name, Object value) {
throw new UnsupportedOperationException("Method resolveTemplate(..) not supported by implementation");
uriBuilder = io.micronaut.http.uri.UriBuilder.of(uriBuilder.expand(Map.of(name, value)));
return this;
}

@Override
Expand All @@ -195,7 +196,8 @@ public UriBuilder resolveTemplateFromEncoded(String name, Object value) {

@Override
public UriBuilder resolveTemplates(Map<String, Object> templateValues) {
throw new UnsupportedOperationException("Method resolveTemplates(..) not supported by implementation");
uriBuilder = io.micronaut.http.uri.UriBuilder.of(uriBuilder.expand(templateValues));
return this;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.micronaut.jaxrs.runtime.core

import spock.lang.Specification

class JaxRsUriBuilderSpec extends Specification {

def 'resolve template encodes the value'() {
given:
def builder = JaxRsUriBuilder.fromPath("/person")

when:
def result = builder.path("/{name}").resolveTemplate("name", "Tim Yates").build()

then:
result.toString() == '/person/Tim%20Yates'
}

def 'resolve template accepts multiple values'() {
given:
def builder = JaxRsUriBuilder.fromPath("/person/{age}")
Map<String, Object> values = Map.of("name", "Tim Yates", "age", 43)

when:
def result = builder.path("/{name}").resolveTemplates(values).build()

then:
result.toString() == '/person/43/Tim%20Yates'
}
}