Skip to content
Open
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
16 changes: 12 additions & 4 deletions start-client/dev/api.mock.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"_links": {
"maven-project": {
"href": "https://start.spring.io/starter.zip?type=maven-project{&dependencies,packaging,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}",
"href": "https://start.spring.io/starter.zip?type=maven-project{&dependencies,packaging,configurationFileFormat,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}",
"templated": true
},
"maven-build": {
"href": "https://start.spring.io/pom.xml?type=maven-build{&dependencies,packaging,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}",
"href": "https://start.spring.io/pom.xml?type=maven-build{&dependencies,packaging,configurationFileFormat,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}",
"templated": true
},
"gradle-project": {
"href": "https://start.spring.io/starter.zip?type=gradle-project{&dependencies,packaging,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}",
"href": "https://start.spring.io/starter.zip?type=gradle-project{&dependencies,packaging,configurationFileFormat,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}",
"templated": true
},
"gradle-build": {
"href": "https://start.spring.io/build.gradle?type=gradle-build{&dependencies,packaging,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}",
"href": "https://start.spring.io/build.gradle?type=gradle-build{&dependencies,packaging,configurationFileFormat,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}",
"templated": true
},
"dependencies": {
Expand Down Expand Up @@ -1393,6 +1393,14 @@
{ "id": "war", "name": "War" }
]
},
"configurationFileFormat": {
"type": "single-select",
"default": "properties",
"values": [
{ "id": "properties", "name": "Properties" },
{ "id": "yaml", "name": "YAML" }
]
},
"javaVersion": {
"type": "single-select",
"default": "1.8",
Expand Down
10 changes: 10 additions & 0 deletions start-client/src/components/common/builder/Fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ function Fields({
</FieldError>
)}
</Control>
<Control text='Configuration File Format'>
<Radio
name='configurationFileFormat'
selected={get(values, 'configurationFileFormat')}
options={get(config, 'lists.configurationFileFormat')}
onChange={value => {
update({ configurationFileFormat: value })
}}
/>
</Control>
<Control text='Project Metadata'>
<FieldInput
id='input-group'
Expand Down
8 changes: 7 additions & 1 deletion start-client/src/components/reducer/Initializr.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const defaultInitializrContext = {
project: '',
language: '',
boot: '',
configurationFileFormat: '',
meta: {
name: '',
group: '',
Expand Down Expand Up @@ -41,6 +42,8 @@ const getPersistedOrDefault = json => {
language:
localStorage.getItem('language') || get(json, 'defaultValues').language,
boot: get(json, 'defaultValues').boot,
configurationFileFormat:
localStorage.getItem('configurationFileFormat') || get(json, 'defaultValues').configurationFileFormat,
meta: {
name: get(json, 'defaultValues.meta').name,
group: get(json, 'defaultValues.meta').group,
Expand All @@ -55,7 +58,7 @@ const getPersistedOrDefault = json => {
},
dependencies: [],
}
const checks = ['project', 'language', 'meta.java', 'meta.packaging']
const checks = ['project', 'language', 'meta.java', 'meta.packaging', 'configurationFileFormat',]
checks.forEach(key => {
const item = get(json, `lists.${key}`)?.find(
it => it.key === get(values, key)
Expand All @@ -80,6 +83,9 @@ const persist = changes => {
if (get(changes, 'meta.java')) {
localStorage.setItem('java', get(changes, 'meta.java'))
}
if (get(changes, 'configurationFileFormat')) {
localStorage.setItem('configurationFileFormat', get(changes, 'configurationFileFormat'))
}
}

export function reducer(state, action) {
Expand Down
14 changes: 13 additions & 1 deletion start-client/src/components/reducer/__tests__/Initializr.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('COMPLETE action', () => {
project: '',
language: '',
boot: '',
configurationFileFormat: '',
meta: {
name: '',
group: '',
Expand All @@ -47,7 +48,7 @@ describe('COMPLETE action', () => {
},
})
expect(get(result, 'share')).toBe(
'type=maven-project&language=java&platformVersion=2.2.0.RELEASE&packaging=jar&jvmVersion=1.8&groupId=com.example&artifactId=demo&name=demo&description=Demo%20project%20for%20Spring%20Boot&packageName=com.example.demo&dependencies='
'type=maven-project&language=java&platformVersion=2.2.0.RELEASE&packaging=jar&configurationFileFormat=properties&jvmVersion=1.8&groupId=com.example&artifactId=demo&name=demo&description=Demo%20project%20for%20Spring%20Boot&packageName=com.example.demo&dependencies='
)
expect(get(result, 'values.project')).toBe('maven-project')
expect(get(result, 'values.language')).toBe('java')
Expand Down Expand Up @@ -181,6 +182,15 @@ describe('UPDATE action', () => {
})
expect(get(result, 'values.meta.packaging')).toBe('war')
})
it('should reduce the state (configuration file format)', () => {
const result = reducer(state, {
type: 'UPDATE',
payload: {
configurationFileFormat: 'yaml',
},
})
expect(get(result, 'values.configurationFileFormat')).toBe('yaml')
})
it('should reduce the state (meta packageName)', () => {
const result = reducer(state, {
type: 'UPDATE',
Expand Down Expand Up @@ -217,6 +227,7 @@ describe('LOAD action', () => {
description: 'Demo1 project for Spring Boot',
groupId: 'com.example1',
jvmVersion: '1.8',
configurationFileFormat: 'yaml',
language: 'java',
name: 'demo1',
packageName: 'com.example1.demo1',
Expand All @@ -239,6 +250,7 @@ describe('LOAD action', () => {
expect(get(result, 'values.meta.packaging')).toBe('war')
expect(get(result, 'values.meta.packageName')).toBe('com.example1.demo1')
expect(get(result, 'values.meta.java')).toBe('1.8')
expect(get(result, 'values.configurationFileFormat')).toBe('yaml')
expect(get(result, 'values.dependencies').length).toBe(0)
expect(Object.keys(get(result, 'errors')).length).toBe(0)
expect(Object.keys(get(result, 'warnings')).length).toBe(0)
Expand Down
10 changes: 9 additions & 1 deletion start-client/src/components/utils/ApiUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const PROPERTIES_MAPPING_URL = {
language: 'language',
platformVersion: 'boot',
packaging: 'meta.packaging',
configurationFileFormat: 'configurationFileFormat',
jvmVersion: 'meta.java',
groupId: 'meta.group',
artifactId: 'meta.artifact',
Expand All @@ -24,7 +25,7 @@ export const getInfo = function getInfo(url) {
fetch(`${url}`, {
method: 'GET',
headers: {
Accept: 'application/vnd.initializr.v2.2+json',
Accept: 'application/vnd.initializr.v2.3+json',
},
})
.then(
Expand Down Expand Up @@ -82,6 +83,7 @@ export const parseParams = (values, queryParams, lists) => {
case 'project':
case 'language':
case 'meta.packaging':
case 'configurationFileFormat':
case 'meta.java': {
const list = get(lists, key, [])
const res = list.find(a => a.key.toLowerCase() === value)
Expand Down Expand Up @@ -229,6 +231,10 @@ export const getLists = json => {
text: `${packaging.name}`,
})),
},
configurationFileFormat: get(json, 'configurationFileFormat.values', []).map(configurationFileFormat => ({
key: `${configurationFileFormat.id}`,
text: `${configurationFileFormat.name}`,
})),
dependencies: deps,
}
}
Expand All @@ -238,6 +244,7 @@ export const getDefaultValues = json => {
project: get(json, 'type.default'),
language: get(json, 'language.default'),
boot: get(json, 'bootVersion.default'),
configurationFileFormat: get(json, 'configurationFileFormat.default') || 'properties',
meta: {
name: get(json, 'name.default'),
group: get(json, 'groupId.default'),
Expand Down Expand Up @@ -281,6 +288,7 @@ export const getProject = function getProject(url, values, config) {
packageName: get(values, 'meta.packageName'),
packaging: get(values, 'meta.packaging'),
javaVersion: get(values, 'meta.java'),
configurationFileFormat: get(values, 'configurationFileFormat'),
})
let paramsDependencies = get(values, 'dependencies', [])
.map(dependency => {
Expand Down
Loading