Skip to content

Commit

Permalink
Ensure Custom Fields API docs match responses and use types in fronte…
Browse files Browse the repository at this point in the history
…nd form.
  • Loading branch information
BusterNeece committed Feb 25, 2025
1 parent 1d49e0e commit 6d7f94b
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 24 deletions.
24 changes: 21 additions & 3 deletions backend/src/Controller/Api/Admin/CustomFieldsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@
new OA\Response(
response: 200,
description: 'Success',
content: new OA\JsonContent(type: 'array', items: new OA\Items(ref: '#/components/schemas/CustomField'))
content: new OA\JsonContent(
type: 'array',
items: new OA\Items(
allOf: [
new OA\Schema(ref: '#/components/schemas/CustomField'),
new OA\Schema(ref: '#/components/schemas/HasLinks'),
]
)
)
),
new OA\Response(ref: OpenApi::REF_RESPONSE_ACCESS_DENIED, response: 403),
new OA\Response(ref: OpenApi::REF_RESPONSE_GENERIC_ERROR, response: 500),
Expand All @@ -40,7 +48,12 @@
new OA\Response(
response: 200,
description: 'Success',
content: new OA\JsonContent(ref: '#/components/schemas/CustomField')
content: new OA\JsonContent(
allOf: [
new OA\Schema(ref: '#/components/schemas/CustomField'),
new OA\Schema(ref: '#/components/schemas/HasLinks'),
]
)
),
new OA\Response(ref: OpenApi::REF_RESPONSE_ACCESS_DENIED, response: 403),
new OA\Response(ref: OpenApi::REF_RESPONSE_GENERIC_ERROR, response: 500),
Expand All @@ -65,7 +78,12 @@
new OA\Response(
response: 200,
description: 'Success',
content: new OA\JsonContent(ref: '#/components/schemas/CustomField')
content: new OA\JsonContent(
allOf: [
new OA\Schema(ref: '#/components/schemas/CustomField'),
new OA\Schema(ref: '#/components/schemas/HasLinks'),
]
)
),
new OA\Response(ref: OpenApi::REF_RESPONSE_ACCESS_DENIED, response: 403),
new OA\Response(ref: OpenApi::REF_RESPONSE_NOT_FOUND, response: 404),
Expand Down
7 changes: 6 additions & 1 deletion backend/src/Entity/CustomField.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
use Symfony\Component\Validator\Constraints as Assert;

#[
OA\Schema(type: 'object'),
OA\Schema(
required: [
'name',
],
type: 'object'
),
ORM\Entity,
ORM\Table(name: 'custom_field'),
Attributes\Auditable
Expand Down
4 changes: 1 addition & 3 deletions frontend/components/Admin/AuditLog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ const dateRange = ref({
const {$gettext} = useTranslate();
const {timeConfig} = useAzuraCast();
type Row = DeepRequired<ApiAdminAuditLog>
const fields: DataTableField<Row>[] = [
const fields: DataTableField<ApiAdminAuditLog>[] = [
{
key: 'timestamp',
label: $gettext('Date/Time'),
Expand Down
16 changes: 10 additions & 6 deletions frontend/components/Admin/CustomFields.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@
:show-toolbar="false"
:api-url="listUrl"
>
<template #cell(name)="row">
{{ row.item.name }} <code>{{ row.item.short_name }}</code>
<template #cell(name)="{ item }">
{{ item.name }} <code>{{ item.short_name }}</code>
</template>
<template #cell(actions)="row">
<template #cell(actions)="{ item }">
<div class="btn-group btn-group-sm">
<button
type="button"
class="btn btn-primary"
@click="doEdit(row.item.links.self)"
@click="doEdit(item.links.self)"
>
{{ $gettext('Edit') }}
</button>
<button
type="button"
class="btn btn-danger"
@click="doDelete(row.item.links.self)"
@click="doDelete(item.links.self)"
>
{{ $gettext('Delete') }}
</button>
Expand Down Expand Up @@ -65,6 +65,8 @@ import useConfirmAndDelete from "~/functions/useConfirmAndDelete";
import CardPage from "~/components/Common/CardPage.vue";
import {getApiUrl} from "~/router";
import AddButton from "~/components/Common/AddButton.vue";
import {DeepRequired} from "utility-types";
import {CustomField, HasLinks} from "~/entities/ApiInterfaces.ts";
const props = defineProps<{
autoAssignTypes: Record<string, string>,
Expand All @@ -74,7 +76,9 @@ const listUrl = getApiUrl('/admin/custom_fields');
const {$gettext} = useTranslate();
const fields: DataTableField[] = [
type Row = DeepRequired<CustomField & HasLinks>
const fields: DataTableField<Row>[] = [
{
key: 'name',
isRowHeader: true,
Expand Down
7 changes: 3 additions & 4 deletions frontend/components/Admin/CustomFields/EditModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import AdminCustomFieldsForm from "~/components/Admin/CustomFields/Form.vue";
import {computed, useTemplateRef} from "vue";
import {BaseEditModalEmits, BaseEditModalProps, useBaseEditModal} from "~/functions/useBaseEditModal";
import {useTranslate} from "~/vendor/gettext";
import {CustomField} from "~/entities/ApiInterfaces.ts";
interface CustomFieldsEditModalProps extends BaseEditModalProps {
autoAssignTypes: Record<string, string>
Expand All @@ -42,12 +43,10 @@ const {
edit,
doSubmit,
close
} = useBaseEditModal(
} = useBaseEditModal<CustomField>(
props,
emit,
$modal,
{},
{},
$modal
);
const {$gettext} = useTranslate();
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/Admin/CustomFields/Form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ import {forEach} from "lodash";
import FormGroupSelect from "~/components/Form/FormGroupSelect.vue";
import {required} from "@vuelidate/validators";
import {useVuelidateOnFormTab} from "~/functions/useVuelidateOnFormTab.ts";
import {GenericForm} from "~/entities/Forms.ts";
import {CustomField} from "~/entities/ApiInterfaces.ts";
const props = defineProps<{
autoAssignTypes: Record<string, string>
}>();
const form = defineModel<GenericForm>('form', {required: true});
const form = defineModel<CustomField>('form', {required: true});
const {
v$
Expand Down
2 changes: 1 addition & 1 deletion frontend/entities/ApiInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ export interface ApiUploadFile {
}

export type CustomField = HasAutoIncrementId & {
name?: string;
name: string;
/** The programmatic name for the field. Can be auto-generated from the full name. */
short_name?: string;
/** An ID3v2 field to automatically assign to this value, if it exists in the media file. */
Expand Down
2 changes: 1 addition & 1 deletion frontend/functions/useVuelidateOnFormTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {useFormTabEventBus, VuelidateRef} from "~/functions/useVuelidateOnForm.t

export function useVuelidateOnFormTab<
ParentForm extends GenericForm = GenericForm,
TabForm extends GenericForm = GenericForm
TabForm extends GenericForm = Partial<ParentForm>
>(
form: ModelRef<ParentForm>,
validations: Ref<ValidationArgs<TabForm>> | ValidationArgs<TabForm>,
Expand Down
12 changes: 9 additions & 3 deletions web/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ paths:
schema:
type: array
items:
$ref: '#/components/schemas/CustomField'
allOf: [{ $ref: '#/components/schemas/CustomField' }, { $ref: '#/components/schemas/HasLinks' }]
'403':
$ref: '#/components/responses/AccessDenied'
'500':
Expand All @@ -73,7 +73,9 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/CustomField'
allOf:
- { $ref: '#/components/schemas/CustomField' }
- { $ref: '#/components/schemas/HasLinks' }
'403':
$ref: '#/components/responses/AccessDenied'
'500':
Expand Down Expand Up @@ -102,7 +104,9 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/CustomField'
allOf:
- { $ref: '#/components/schemas/CustomField' }
- { $ref: '#/components/schemas/HasLinks' }
'403':
$ref: '#/components/responses/AccessDenied'
'404':
Expand Down Expand Up @@ -4900,6 +4904,8 @@ components:
example: ''
type: object
CustomField:
required:
- name
type: object
allOf:
-
Expand Down

0 comments on commit 6d7f94b

Please sign in to comment.