Skip to content

Commit a6cf6ca

Browse files
authored
Merge pull request #518 from citation-file-format/490-authors-are-always-defined
Make authors not optional in CffType
2 parents e5e9dd8 + fd8f3da commit a6cf6ca

5 files changed

Lines changed: 38 additions & 36 deletions

File tree

src/components/ScreenAuthors.vue

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -107,40 +107,27 @@ export default defineComponent({
107107
const { errors } = useValidation()
108108
const editingId = ref(0)
109109
const addAuthor = async () => {
110-
let newAuthors:AuthorType[]
111110
const newAuthor: AuthorType = {}
112-
if (authors.value === undefined) {
113-
newAuthors = [newAuthor]
114-
} else {
115-
newAuthors = [...authors.value, newAuthor]
116-
}
111+
const newAuthors = [...authors.value, newAuthor]
117112
setAuthors(newAuthors)
118113
editingId.value = newAuthors.length - 1
119114
// await the DOM update that resulted from updating the authors list
120115
await nextTick()
121116
scrollToBottom()
122117
}
123118
const removeAuthor = () => {
124-
if (authors.value !== undefined) {
125-
const newAuthors = [...authors.value]
126-
newAuthors.splice(editingId.value, 1)
127-
setAuthors(newAuthors)
128-
editingId.value = -1
129-
if (Array.isArray(newAuthors) && newAuthors.length === 0) {
130-
setAuthors([])
131-
}
132-
}
119+
const newAuthors = [...authors.value]
120+
newAuthors.splice(editingId.value, 1)
121+
setAuthors(newAuthors)
122+
editingId.value = -1
133123
}
134124
const setAuthorField = (field: keyof AuthorType, value: string) => {
135-
if (authors.value !== undefined) {
136-
const author = { ...authors.value[editingId.value] }
137-
author[field] = value === '' ? undefined : value
138-
authors.value[editingId.value] = author
139-
setAuthors(authors.value)
140-
}
125+
const newAuthor = { ...authors.value[editingId.value] }
126+
newAuthor[field] = value === '' ? undefined : value
127+
authors.value[editingId.value] = newAuthor
128+
setAuthors(authors.value)
141129
}
142130
const moveAuthorUp = (index: number) => {
143-
if (authors.value === undefined) return
144131
moveUp(index, authors.value, setAuthors)
145132
if (editingId.value === index && index > 0) {
146133
editingId.value = editingId.value - 1
@@ -149,7 +136,6 @@ export default defineComponent({
149136
}
150137
}
151138
const moveAuthorDown = (index: number) => {
152-
if (authors.value === undefined) return
153139
moveDown(index, authors.value, setAuthors)
154140
if (editingId.value === index && index < authors.value.length - 1) {
155141
editingId.value = editingId.value + 1

src/error-filtering.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ export const messageQueries: ErrorQuery[] = [{
156156
replace: {
157157
message: '\'message\' is a required property'
158158
}
159+
}, {
160+
find: {
161+
message: 'must NOT have fewer than 1 characters',
162+
schemaPath: '#/properties/message/minLength'
163+
},
164+
replace: {
165+
message: '\'message\' needs to be at least 1 character long.'
166+
}
159167
}]
160168

161169
export const orcidQueries = (index: number) => {
@@ -209,6 +217,14 @@ export const titleQueries: ErrorQuery[] = [{
209217
replace: {
210218
message: '\'title\' is a required property'
211219
}
220+
}, {
221+
find: {
222+
message: 'must NOT have fewer than 1 characters',
223+
schemaPath: '#/properties/title/minLength'
224+
},
225+
replace: {
226+
message: '\'title\' needs to be at least 1 character long.'
227+
}
212228
}]
213229

214230
export const urlQueries: ErrorQuery[] = [{

src/store/cff.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ const getInitialData = () => {
1111
identifiers: undefined,
1212
keywords: undefined,
1313
license: undefined,
14-
message: undefined,
14+
message: '',
1515
repository: undefined,
1616
repositoryArtifact: undefined,
1717
repositoryCode: undefined,
18-
title: undefined,
18+
title: '',
1919
type: 'software',
2020
url: undefined,
2121
version: undefined
@@ -43,17 +43,17 @@ export const useCff = () => {
4343
url: computed(() => cff.value.url),
4444
version: computed(() => cff.value.version),
4545
setAbstract: (newAbstract: string) => { cff.value.abstract = newAbstract === '' ? undefined : newAbstract },
46-
setAuthors: (newAuthors: AuthorsType) => { cff.value.authors = newAuthors === [] ? undefined : newAuthors },
46+
setAuthors: (newAuthors: AuthorsType) => { cff.value.authors = newAuthors },
4747
setCommit: (newCommit: string) => { cff.value.commit = newCommit === '' ? undefined : newCommit },
4848
setDateReleased: (newDateReleased: string) => { cff.value.dateReleased = newDateReleased === '' ? undefined : newDateReleased },
4949
setIdentifiers: (newIdentifiers: IdentifiersType) => { cff.value.identifiers = newIdentifiers === [] ? undefined : newIdentifiers },
5050
setKeywords: (newKeywords: KeywordsType) => { cff.value.keywords = newKeywords === [] ? undefined : newKeywords },
5151
setLicense: (newLicense: string) => { cff.value.license = newLicense === '' ? undefined : newLicense },
52-
setMessage: (newMessage: string) => { cff.value.message = newMessage === '' ? undefined : newMessage },
52+
setMessage: (newMessage: string) => { cff.value.message = newMessage },
5353
setRepository: (newRepository: string) => { cff.value.repository = newRepository === '' ? undefined : newRepository },
5454
setRepositoryArtifact: (newRepositoryArtifact: string) => { cff.value.repositoryArtifact = newRepositoryArtifact === '' ? undefined : newRepositoryArtifact },
5555
setRepositoryCode: (newRepositoryCode: string) => { cff.value.repositoryCode = newRepositoryCode === '' ? undefined : newRepositoryCode },
56-
setTitle: (newTitle: string) => { cff.value.title = newTitle === '' ? undefined : newTitle },
56+
setTitle: (newTitle: string) => { cff.value.title = newTitle },
5757
setType: (newType: TypeType) => { cff.value.type = newType },
5858
setUrl: (newUrl: string) => { cff.value.url = newUrl === '' ? undefined : newUrl },
5959
setVersion: (newVersion: string) => { cff.value.version = newVersion === '' ? undefined : newVersion },

src/types/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type AuthorType = {
88
email?: string;
99
}
1010

11-
export type AuthorsType = Array<AuthorType> | undefined
11+
export type AuthorsType = Array<AuthorType>
1212

1313
export type IdentifierTypeType = 'doi' | 'url' | 'swh' | 'other'
1414
export type IdentifierType = {
@@ -25,18 +25,18 @@ export type TypeType = 'software' | 'dataset'
2525

2626
export type CffType = {
2727
abstract?: string,
28-
authors?: AuthorsType,
28+
authors: AuthorsType,
2929
cffVersion: string,
3030
commit?: string,
3131
dateReleased?: string,
3232
keywords?: KeywordsType,
3333
identifiers?: IdentifiersType,
3434
license?: string,
35-
message?: string,
35+
message: string,
3636
repository?: string,
3737
repositoryArtifact?: string,
3838
repositoryCode?: string,
39-
title?: string,
39+
title: string,
4040
type: TypeType,
4141
url?: string,
4242
version?: string

test/jest/__tests__/store/cffstr.jest.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('useCffstr', () => {
1212
})
1313
describe('initial content', () => {
1414
it('should only have fields with defaults', () => {
15-
const expected = generatedBy + 'cff-version: 1.2.0\ntype: software\nauthors: []\n'
15+
const expected = generatedBy + "cff-version: 1.2.0\ntitle: ''\nmessage: ''\ntype: software\nauthors: []\n"
1616
expect(cffstr.value).toEqual(expected)
1717
})
1818
})
@@ -23,7 +23,7 @@ describe('useCffstr', () => {
2323
})
2424

2525
it('should have title', () => {
26-
const expected = generatedBy + 'cff-version: 1.2.0\ntitle: sometitle\ntype: software\nauthors: []\n'
26+
const expected = generatedBy + "cff-version: 1.2.0\ntitle: sometitle\nmessage: ''\ntype: software\nauthors: []\n"
2727
expect(cffstr.value).toEqual(expected)
2828
})
2929
})
@@ -34,7 +34,7 @@ describe('useCffstr', () => {
3434
})
3535

3636
it('should have a keyword', () => {
37-
const expected = generatedBy + 'cff-version: 1.2.0\ntype: software\nauthors: []\nkeywords:\n - keyword1\n'
37+
const expected = generatedBy + "cff-version: 1.2.0\ntitle: ''\nmessage: ''\ntype: software\nauthors: []\nkeywords:\n - keyword1\n"
3838
expect(cffstr.value).toEqual(expected)
3939
})
4040
})
@@ -45,7 +45,7 @@ describe('useCffstr', () => {
4545
})
4646

4747
it('should have a identifier', () => {
48-
const expected = generatedBy + 'cff-version: 1.2.0\ntype: software\nauthors: []\nidentifiers:\n - type: doi\n value: 10.5281/zenodo.5171937\n'
48+
const expected = generatedBy + "cff-version: 1.2.0\ntitle: ''\nmessage: ''\ntype: software\nauthors: []\nidentifiers:\n - type: doi\n value: 10.5281/zenodo.5171937\n"
4949
expect(cffstr.value).toEqual(expected)
5050
})
5151
})

0 commit comments

Comments
 (0)