mirror of
https://gitee.com/dcren/initializr.git
synced 2025-11-08 10:24:58 +08:00
Improve HAL urls
Remove `type` as a template variable since each action actually defines the related type. This commit however does not address all the concerns raised in gh-69; since the configuration is generic, there is no way to know that a particular action handles one and only one type so removing the type because it is redundant is not really possible. Besides, the zip and tgz endpoints aren't exposed via configuration either so offering such choice via the HAL-urls is not possible either. Partially fixes gh-69
This commit is contained in:
@@ -7,6 +7,7 @@ order.
|
||||
|
||||
=== Release 1.0.0 (In progress)
|
||||
|
||||
* https://github.com/spring-io/initializr/issues/69[#69]: improve the structure of templated urls.
|
||||
* https://github.com/spring-io/initializr/issues/70[#70]: explicit support for HTTPie (similar to curl).
|
||||
* https://github.com/spring-io/initializr/issues/67[#67]: explicit support for curl by returning a text
|
||||
description of the service instead of the raw meta-data. curl users can still discover the json metadata
|
||||
|
||||
@@ -35,7 +35,6 @@ class InitializrMetadataJsonMapper {
|
||||
InitializrMetadataJsonMapper() {
|
||||
this.templateVariables = new TemplateVariables(
|
||||
new TemplateVariable('dependencies', TemplateVariable.VariableType.REQUEST_PARAM),
|
||||
new TemplateVariable('type', TemplateVariable.VariableType.REQUEST_PARAM),
|
||||
new TemplateVariable('packaging', TemplateVariable.VariableType.REQUEST_PARAM),
|
||||
new TemplateVariable('javaVersion', TemplateVariable.VariableType.REQUEST_PARAM),
|
||||
new TemplateVariable('language', TemplateVariable.VariableType.REQUEST_PARAM),
|
||||
@@ -79,13 +78,14 @@ class InitializrMetadataJsonMapper {
|
||||
|
||||
private link(appUrl, type) {
|
||||
def result = [:]
|
||||
result.href = generateTemplatedUri(appUrl, type.action)
|
||||
result.href = generateTemplatedUri(appUrl, type)
|
||||
result.templated = true
|
||||
result
|
||||
}
|
||||
|
||||
private generateTemplatedUri(appUrl, action) {
|
||||
String uri = appUrl != null ? appUrl + action : action
|
||||
private generateTemplatedUri(appUrl, type) {
|
||||
String uri = appUrl != null ? appUrl + type.action : type.action
|
||||
uri += "?type=$type.id"
|
||||
UriTemplate uriTemplate = new UriTemplate(uri, this.templateVariables)
|
||||
uriTemplate.toString()
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ class InitializrMetadataJsonMapperTests {
|
||||
.addDependencyGroup('foo', 'one', 'two').validateAndGet()
|
||||
def json = jsonMapper.write(metadata, null)
|
||||
def result = slurper.parseText(json)
|
||||
assertEquals '/foo.zip{?dependencies,type,packaging,javaVersion,language,bootVersion,' +
|
||||
assertEquals '/foo.zip?type=foo{&dependencies,packaging,javaVersion,language,bootVersion,' +
|
||||
'groupId,artifactId,version,name,description,packageName}', result._links.foo.href
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ class InitializrMetadataJsonMapperTests {
|
||||
.addDependencyGroup('foo', 'one', 'two').validateAndGet()
|
||||
def json = jsonMapper.write(metadata, 'http://server:8080/my-app')
|
||||
def result = slurper.parseText(json)
|
||||
assertEquals 'http://server:8080/my-app/foo.zip{?dependencies,type,packaging,javaVersion,' +
|
||||
assertEquals 'http://server:8080/my-app/foo.zip?type=foo{&dependencies,packaging,javaVersion,' +
|
||||
'language,bootVersion,groupId,artifactId,version,name,description,packageName}',
|
||||
result._links.foo.href
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
{
|
||||
"_links": {
|
||||
"maven-build": {
|
||||
"href": "http://localhost:@port@/pom.xml{?dependencies,type,packaging,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}",
|
||||
"href": "http://localhost:@port@/pom.xml?type=maven-build{&dependencies,packaging,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}",
|
||||
"templated": true
|
||||
},
|
||||
"maven-project": {
|
||||
"href": "http://localhost:@port@/starter.zip{?dependencies,type,packaging,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}",
|
||||
"href": "http://localhost:@port@/starter.zip?type=maven-project{&dependencies,packaging,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}",
|
||||
"templated": true
|
||||
},
|
||||
"gradle-build": {
|
||||
"href": "http://localhost:@port@/build.gradle{?dependencies,type,packaging,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}",
|
||||
"href": "http://localhost:@port@/build.gradle?type=gradle-build{&dependencies,packaging,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}",
|
||||
"templated": true
|
||||
},
|
||||
"gradle-project": {
|
||||
"href": "http://localhost:@port@/starter.zip{?dependencies,type,packaging,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}",
|
||||
"href": "http://localhost:@port@/starter.zip?type=gradle-project{&dependencies,packaging,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}",
|
||||
"templated": true
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user