diff --git a/README.md b/README.md index db991db..e6972a0 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,10 @@ the generated Swagger specification, please do not hesitate to [open an issue](https://github.com/jolicode/harvest-openapi-generator/issues) and share it with us. +If the [documentation](https://help.getharvest.com/api-v2/) is incomplete, you +may want to override a definition. See the +`JoliCode\Extractor\Dumper\Dumper:dump()` method. + ## Further documentation You can see the current and past versions using one of the following: diff --git a/generated/harvest-openapi.yaml b/generated/harvest-openapi.yaml index 87aa0c5..26b9636 100644 --- a/generated/harvest-openapi.yaml +++ b/generated/harvest-openapi.yaml @@ -115,6 +115,30 @@ paths: schema: $ref: '#/definitions/Error' '/clients/{clientId}': + delete: + summary: 'Delete a client' + operationId: deleteClient + description: 'Delete a client. Deleting a client is only possible if it has no projects, invoices, or estimates associated with it. Returns a 200 OK response code if the call succeeded.' + externalDocs: + description: 'Delete a client' + url: 'https://help.getharvest.com/api-v2/clients-api/clients/clients/#delete-a-client' + security: + - + BearerAuth: [] + AccountAuth: [] + parameters: + - + name: clientId + required: true + in: path + type: string + responses: + 200: + description: 'Delete a client' + default: + description: 'error payload' + schema: + $ref: '#/definitions/Error' get: summary: 'Retrieve a client' operationId: retrieveClient @@ -187,30 +211,6 @@ paths: description: 'error payload' schema: $ref: '#/definitions/Error' - delete: - summary: 'Delete a client' - operationId: deleteClient - description: 'Delete a client. Deleting a client is only possible if it has no projects, invoices, or estimates associated with it. Returns a 200 OK response code if the call succeeded.' - externalDocs: - description: 'Delete a client' - url: 'https://help.getharvest.com/api-v2/clients-api/clients/clients/#delete-a-client' - security: - - - BearerAuth: [] - AccountAuth: [] - parameters: - - - name: clientId - required: true - in: path - type: string - responses: - 200: - description: 'Delete a client' - default: - description: 'error payload' - schema: - $ref: '#/definitions/Error' /company: get: summary: 'Retrieve a company' @@ -374,6 +374,30 @@ paths: schema: $ref: '#/definitions/Error' '/contacts/{contactId}': + delete: + summary: 'Delete a contact' + operationId: deleteContact + description: 'Delete a contact. Returns a 200 OK response code if the call succeeded.' + externalDocs: + description: 'Delete a contact' + url: 'https://help.getharvest.com/api-v2/clients-api/clients/contacts/#delete-a-contact' + security: + - + BearerAuth: [] + AccountAuth: [] + parameters: + - + name: contactId + required: true + in: path + type: string + responses: + 200: + description: 'Delete a contact' + default: + description: 'error payload' + schema: + $ref: '#/definitions/Error' get: summary: 'Retrieve a contact' operationId: retrieveContact @@ -460,30 +484,6 @@ paths: description: 'error payload' schema: $ref: '#/definitions/Error' - delete: - summary: 'Delete a contact' - operationId: deleteContact - description: 'Delete a contact. Returns a 200 OK response code if the call succeeded.' - externalDocs: - description: 'Delete a contact' - url: 'https://help.getharvest.com/api-v2/clients-api/clients/contacts/#delete-a-contact' - security: - - - BearerAuth: [] - AccountAuth: [] - parameters: - - - name: contactId - required: true - in: path - type: string - responses: - 200: - description: 'Delete a contact' - default: - description: 'error payload' - schema: - $ref: '#/definitions/Error' /estimate_item_categories: get: summary: 'List all estimate item categories' @@ -559,6 +559,30 @@ paths: schema: $ref: '#/definitions/Error' '/estimate_item_categories/{estimateItemCategoryId}': + delete: + summary: 'Delete an estimate item category' + operationId: deleteEstimateItemCategory + description: 'Delete an estimate item category. Returns a 200 OK response code if the call succeeded.' + externalDocs: + description: 'Delete an estimate item category' + url: 'https://help.getharvest.com/api-v2/estimates-api/estimates/estimate-item-categories/#delete-an-estimate-item-category' + security: + - + BearerAuth: [] + AccountAuth: [] + parameters: + - + name: estimateItemCategoryId + required: true + in: path + type: string + responses: + 200: + description: 'Delete an estimate item category' + default: + description: 'error payload' + schema: + $ref: '#/definitions/Error' get: summary: 'Retrieve an estimate item category' operationId: retrieveEstimateItemCategory @@ -622,30 +646,6 @@ paths: description: 'error payload' schema: $ref: '#/definitions/Error' - delete: - summary: 'Delete an estimate item category' - operationId: deleteEstimateItemCategory - description: 'Delete an estimate item category. Returns a 200 OK response code if the call succeeded.' - externalDocs: - description: 'Delete an estimate item category' - url: 'https://help.getharvest.com/api-v2/estimates-api/estimates/estimate-item-categories/#delete-an-estimate-item-category' - security: - - - BearerAuth: [] - AccountAuth: [] - parameters: - - - name: estimateItemCategoryId - required: true - in: path - type: string - responses: - 200: - description: 'Delete an estimate item category' - default: - description: 'error payload' - schema: - $ref: '#/definitions/Error' /estimates: get: summary: 'List all estimates' @@ -806,6 +806,30 @@ paths: schema: $ref: '#/definitions/Error' '/estimates/{estimateId}': + delete: + summary: 'Delete an estimate' + operationId: deleteEstimate + description: 'Delete an estimate. Returns a 200 OK response code if the call succeeded.' + externalDocs: + description: 'Delete an estimate' + url: 'https://help.getharvest.com/api-v2/estimates-api/estimates/estimates/#delete-an-estimate' + security: + - + BearerAuth: [] + AccountAuth: [] + parameters: + - + name: estimateId + required: true + in: path + type: string + responses: + 200: + description: 'Delete an estimate' + default: + description: 'error payload' + schema: + $ref: '#/definitions/Error' get: summary: 'Retrieve an estimate' operationId: retrieveEstimate @@ -931,30 +955,6 @@ paths: description: 'error payload' schema: $ref: '#/definitions/Error' - delete: - summary: 'Delete an estimate' - operationId: deleteEstimate - description: 'Delete an estimate. Returns a 200 OK response code if the call succeeded.' - externalDocs: - description: 'Delete an estimate' - url: 'https://help.getharvest.com/api-v2/estimates-api/estimates/estimates/#delete-an-estimate' - security: - - - BearerAuth: [] - AccountAuth: [] - parameters: - - - name: estimateId - required: true - in: path - type: string - responses: - 200: - description: 'Delete an estimate' - default: - description: 'error payload' - schema: - $ref: '#/definitions/Error' '/estimates/{estimateId}/messages': get: summary: 'List all messages for an estimate' @@ -1184,6 +1184,30 @@ paths: schema: $ref: '#/definitions/Error' '/expense_categories/{expenseCategoryId}': + delete: + summary: 'Delete an expense category' + operationId: deleteExpenseCategory + description: 'Delete an expense category. Returns a 200 OK response code if the call succeeded.' + externalDocs: + description: 'Delete an expense category' + url: 'https://help.getharvest.com/api-v2/expenses-api/expenses/expense-categories/#delete-an-expense-category' + security: + - + BearerAuth: [] + AccountAuth: [] + parameters: + - + name: expenseCategoryId + required: true + in: path + type: string + responses: + 200: + description: 'Delete an expense category' + default: + description: 'error payload' + schema: + $ref: '#/definitions/Error' get: summary: 'Retrieve an expense category' operationId: retrieveExpenseCategory @@ -1257,30 +1281,6 @@ paths: description: 'error payload' schema: $ref: '#/definitions/Error' - delete: - summary: 'Delete an expense category' - operationId: deleteExpenseCategory - description: 'Delete an expense category. Returns a 200 OK response code if the call succeeded.' - externalDocs: - description: 'Delete an expense category' - url: 'https://help.getharvest.com/api-v2/expenses-api/expenses/expense-categories/#delete-an-expense-category' - security: - - - BearerAuth: [] - AccountAuth: [] - parameters: - - - name: expenseCategoryId - required: true - in: path - type: string - responses: - 200: - description: 'Delete an expense category' - default: - description: 'error payload' - schema: - $ref: '#/definitions/Error' /expenses: get: summary: 'List all expenses' @@ -1424,6 +1424,30 @@ paths: schema: $ref: '#/definitions/Error' '/expenses/{expenseId}': + delete: + summary: 'Delete an expense' + operationId: deleteExpense + description: 'Delete an expense. Returns a 200 OK response code if the call succeeded.' + externalDocs: + description: 'Delete an expense' + url: 'https://help.getharvest.com/api-v2/expenses-api/expenses/expenses/#delete-an-expense' + security: + - + BearerAuth: [] + AccountAuth: [] + parameters: + - + name: expenseId + required: true + in: path + type: string + responses: + 200: + description: 'Delete an expense' + default: + description: 'error payload' + schema: + $ref: '#/definitions/Error' get: summary: 'Retrieve an expense' operationId: retrieveExpense @@ -1516,30 +1540,6 @@ paths: description: 'error payload' schema: $ref: '#/definitions/Error' - delete: - summary: 'Delete an expense' - operationId: deleteExpense - description: 'Delete an expense. Returns a 200 OK response code if the call succeeded.' - externalDocs: - description: 'Delete an expense' - url: 'https://help.getharvest.com/api-v2/expenses-api/expenses/expenses/#delete-an-expense' - security: - - - BearerAuth: [] - AccountAuth: [] - parameters: - - - name: expenseId - required: true - in: path - type: string - responses: - 200: - description: 'Delete an expense' - default: - description: 'error payload' - schema: - $ref: '#/definitions/Error' /invoice_item_categories: get: summary: 'List all invoice item categories' @@ -1615,6 +1615,30 @@ paths: schema: $ref: '#/definitions/Error' '/invoice_item_categories/{invoiceItemCategoryId}': + delete: + summary: 'Delete an invoice item category' + operationId: deleteInvoiceItemCategory + description: 'Delete an invoice item category. Deleting an invoice item category is only possible if use_as_service and use_as_expense are both false. Returns a 200 OK response code if the call succeeded.' + externalDocs: + description: 'Delete an invoice item category' + url: 'https://help.getharvest.com/api-v2/invoices-api/invoices/invoice-item-categories/#delete-an-invoice-item-category' + security: + - + BearerAuth: [] + AccountAuth: [] + parameters: + - + name: invoiceItemCategoryId + required: true + in: path + type: string + responses: + 200: + description: 'Delete an invoice item category' + default: + description: 'error payload' + schema: + $ref: '#/definitions/Error' get: summary: 'Retrieve an invoice item category' operationId: retrieveInvoiceItemCategory @@ -1678,30 +1702,6 @@ paths: description: 'error payload' schema: $ref: '#/definitions/Error' - delete: - summary: 'Delete an invoice item category' - operationId: deleteInvoiceItemCategory - description: 'Delete an invoice item category. Deleting an invoice item category is only possible if use_as_service and use_as_expense are both false. Returns a 200 OK response code if the call succeeded.' - externalDocs: - description: 'Delete an invoice item category' - url: 'https://help.getharvest.com/api-v2/invoices-api/invoices/invoice-item-categories/#delete-an-invoice-item-category' - security: - - - BearerAuth: [] - AccountAuth: [] - parameters: - - - name: invoiceItemCategoryId - required: true - in: path - type: string - responses: - 200: - description: 'Delete an invoice item category' - default: - description: 'error payload' - schema: - $ref: '#/definitions/Error' /invoices: get: summary: 'List all invoices' @@ -1935,6 +1935,30 @@ paths: schema: $ref: '#/definitions/Error' '/invoices/{invoiceId}': + delete: + summary: 'Delete an invoice' + operationId: deleteInvoice + description: 'Delete an invoice. Returns a 200 OK response code if the call succeeded.' + externalDocs: + description: 'Delete an invoice' + url: 'https://help.getharvest.com/api-v2/invoices-api/invoices/invoices/#delete-an-invoice' + security: + - + BearerAuth: [] + AccountAuth: [] + parameters: + - + name: invoiceId + required: true + in: path + type: string + responses: + 200: + description: 'Delete an invoice' + default: + description: 'error payload' + schema: + $ref: '#/definitions/Error' get: summary: 'Retrieve an invoice' operationId: retrieveInvoice @@ -2079,30 +2103,6 @@ paths: description: 'error payload' schema: $ref: '#/definitions/Error' - delete: - summary: 'Delete an invoice' - operationId: deleteInvoice - description: 'Delete an invoice. Returns a 200 OK response code if the call succeeded.' - externalDocs: - description: 'Delete an invoice' - url: 'https://help.getharvest.com/api-v2/invoices-api/invoices/invoices/#delete-an-invoice' - security: - - - BearerAuth: [] - AccountAuth: [] - parameters: - - - name: invoiceId - required: true - in: path - type: string - responses: - 200: - description: 'Delete an invoice' - default: - description: 'error payload' - schema: - $ref: '#/definitions/Error' '/invoices/{invoiceId}/messages': get: summary: 'List all messages for an invoice' @@ -2532,6 +2532,30 @@ paths: schema: $ref: '#/definitions/Error' '/projects/{projectId}': + delete: + summary: 'Delete a project' + operationId: deleteProject + description: "Deletes a project and any time entries or expenses tracked to it.\nHowever, invoices associated with the project will not be deleted.\nIf you don’t want the project’s time entries and expenses to be deleted, you should archive the project instead." + externalDocs: + description: 'Delete a project' + url: 'https://help.getharvest.com/api-v2/projects-api/projects/projects/#delete-a-project' + security: + - + BearerAuth: [] + AccountAuth: [] + parameters: + - + name: projectId + required: true + in: path + type: string + responses: + 200: + description: 'Delete a project' + default: + description: 'error payload' + schema: + $ref: '#/definitions/Error' get: summary: 'Retrieve a project' operationId: retrieveProject @@ -2660,30 +2684,6 @@ paths: description: 'error payload' schema: $ref: '#/definitions/Error' - delete: - summary: 'Delete a project' - operationId: deleteProject - description: "Deletes a project and any time entries or expenses tracked to it.\nHowever, invoices associated with the project will not be deleted.\nIf you don’t want the project’s time entries and expenses to be deleted, you should archive the project instead." - externalDocs: - description: 'Delete a project' - url: 'https://help.getharvest.com/api-v2/projects-api/projects/projects/#delete-a-project' - security: - - - BearerAuth: [] - AccountAuth: [] - parameters: - - - name: projectId - required: true - in: path - type: string - responses: - 200: - description: 'Delete a project' - default: - description: 'error payload' - schema: - $ref: '#/definitions/Error' '/projects/{projectId}/task_assignments': get: summary: 'List all task assignments for a specific project' @@ -2790,6 +2790,35 @@ paths: schema: $ref: '#/definitions/Error' '/projects/{projectId}/task_assignments/{taskAssignmentId}': + delete: + summary: 'Delete a task assignment' + operationId: deleteTaskAssignment + description: 'Delete a task assignment. Deleting a task assignment is only possible if it has no time entries associated with it. Returns a 200 OK response code if the call succeeded.' + externalDocs: + description: 'Delete a task assignment' + url: 'https://help.getharvest.com/api-v2/projects-api/projects/task-assignments/#delete-a-task-assignment' + security: + - + BearerAuth: [] + AccountAuth: [] + parameters: + - + name: projectId + required: true + in: path + type: string + - + name: taskAssignmentId + required: true + in: path + type: string + responses: + 200: + description: 'Delete a task assignment' + default: + description: 'error payload' + schema: + $ref: '#/definitions/Error' get: summary: 'Retrieve a task assignment' operationId: retrieveTaskAssignment @@ -2868,37 +2897,8 @@ paths: responses: 200: description: 'Update a task assignment' - schema: - $ref: '#/definitions/TaskAssignment' - default: - description: 'error payload' - schema: - $ref: '#/definitions/Error' - delete: - summary: 'Delete a task assignment' - operationId: deleteTaskAssignment - description: 'Delete a task assignment. Deleting a task assignment is only possible if it has no time entries associated with it. Returns a 200 OK response code if the call succeeded.' - externalDocs: - description: 'Delete a task assignment' - url: 'https://help.getharvest.com/api-v2/projects-api/projects/task-assignments/#delete-a-task-assignment' - security: - - - BearerAuth: [] - AccountAuth: [] - parameters: - - - name: projectId - required: true - in: path - type: string - - - name: taskAssignmentId - required: true - in: path - type: string - responses: - 200: - description: 'Delete a task assignment' + schema: + $ref: '#/definitions/TaskAssignment' default: description: 'error payload' schema: @@ -3018,6 +3018,35 @@ paths: schema: $ref: '#/definitions/Error' '/projects/{projectId}/user_assignments/{userAssignmentId}': + delete: + summary: 'Delete a user assignment' + operationId: deleteUserAssignment + description: 'Delete a user assignment. Deleting a user assignment is only possible if it has no time entries or expenses associated with it. Returns a 200 OK response code if the call succeeded.' + externalDocs: + description: 'Delete a user assignment' + url: 'https://help.getharvest.com/api-v2/projects-api/projects/user-assignments/#delete-a-user-assignment' + security: + - + BearerAuth: [] + AccountAuth: [] + parameters: + - + name: projectId + required: true + in: path + type: string + - + name: userAssignmentId + required: true + in: path + type: string + responses: + 200: + description: 'Delete a user assignment' + default: + description: 'error payload' + schema: + $ref: '#/definitions/Error' get: summary: 'Retrieve a user assignment' operationId: retrieveUserAssignment @@ -3105,35 +3134,6 @@ paths: description: 'error payload' schema: $ref: '#/definitions/Error' - delete: - summary: 'Delete a user assignment' - operationId: deleteUserAssignment - description: 'Delete a user assignment. Deleting a user assignment is only possible if it has no time entries or expenses associated with it. Returns a 200 OK response code if the call succeeded.' - externalDocs: - description: 'Delete a user assignment' - url: 'https://help.getharvest.com/api-v2/projects-api/projects/user-assignments/#delete-a-user-assignment' - security: - - - BearerAuth: [] - AccountAuth: [] - parameters: - - - name: projectId - required: true - in: path - type: string - - - name: userAssignmentId - required: true - in: path - type: string - responses: - 200: - description: 'Delete a user assignment' - default: - description: 'error payload' - schema: - $ref: '#/definitions/Error' /reports/expenses/categories: get: summary: 'Expense Categories Report' @@ -3662,6 +3662,30 @@ paths: schema: $ref: '#/definitions/Error' '/roles/{roleId}': + delete: + summary: 'Delete a role' + operationId: deleteRole + description: 'Delete a role. Deleting a role will unlink it from any users it was assigned to. Returns a 200 OK response code if the call succeeded.' + externalDocs: + description: 'Delete a role' + url: 'https://help.getharvest.com/api-v2/roles-api/roles/roles/#delete-a-role' + security: + - + BearerAuth: [] + AccountAuth: [] + parameters: + - + name: roleId + required: true + in: path + type: string + responses: + 200: + description: 'Delete a role' + default: + description: 'error payload' + schema: + $ref: '#/definitions/Error' get: summary: 'Retrieve a role' operationId: retrieveRole @@ -3732,30 +3756,6 @@ paths: description: 'error payload' schema: $ref: '#/definitions/Error' - delete: - summary: 'Delete a role' - operationId: deleteRole - description: 'Delete a role. Deleting a role will unlink it from any users it was assigned to. Returns a 200 OK response code if the call succeeded.' - externalDocs: - description: 'Delete a role' - url: 'https://help.getharvest.com/api-v2/roles-api/roles/roles/#delete-a-role' - security: - - - BearerAuth: [] - AccountAuth: [] - parameters: - - - name: roleId - required: true - in: path - type: string - responses: - 200: - description: 'Delete a role' - default: - description: 'error payload' - schema: - $ref: '#/definitions/Error' /task_assignments: get: summary: 'List all task assignments' @@ -3896,6 +3896,30 @@ paths: schema: $ref: '#/definitions/Error' '/tasks/{taskId}': + delete: + summary: 'Delete a task' + operationId: deleteTask + description: 'Delete a task. Deleting a task is only possible if it has no time entries associated with it. Returns a 200 OK response code if the call succeeded.' + externalDocs: + description: 'Delete a task' + url: 'https://help.getharvest.com/api-v2/tasks-api/tasks/tasks/#delete-a-task' + security: + - + BearerAuth: [] + AccountAuth: [] + parameters: + - + name: taskId + required: true + in: path + type: string + responses: + 200: + description: 'Delete a task' + default: + description: 'error payload' + schema: + $ref: '#/definitions/Error' get: summary: 'Retrieve a task' operationId: retrieveTask @@ -3972,30 +3996,6 @@ paths: description: 'error payload' schema: $ref: '#/definitions/Error' - delete: - summary: 'Delete a task' - operationId: deleteTask - description: 'Delete a task. Deleting a task is only possible if it has no time entries associated with it. Returns a 200 OK response code if the call succeeded.' - externalDocs: - description: 'Delete a task' - url: 'https://help.getharvest.com/api-v2/tasks-api/tasks/tasks/#delete-a-task' - security: - - - BearerAuth: [] - AccountAuth: [] - parameters: - - - name: taskId - required: true - in: path - type: string - responses: - 200: - description: 'Delete a task' - default: - description: 'error payload' - schema: - $ref: '#/definitions/Error' /time_entries: get: summary: 'List all time entries' @@ -4163,6 +4163,30 @@ paths: schema: $ref: '#/definitions/Error' '/time_entries/{timeEntryId}': + delete: + summary: 'Delete a time entry' + operationId: deleteTimeEntry + description: 'Delete a time entry. Deleting a time entry is only possible if it’s not closed and the associated project and task haven’t been archived. However, Admins can delete closed entries. Returns a 200 OK response code if the call succeeded.' + externalDocs: + description: 'Delete a time entry' + url: 'https://help.getharvest.com/api-v2/timesheets-api/timesheets/time-entries/#delete-a-time-entry' + security: + - + BearerAuth: [] + AccountAuth: [] + parameters: + - + name: timeEntryId + required: true + in: path + type: string + responses: + 200: + description: 'Delete a time entry' + default: + description: 'error payload' + schema: + $ref: '#/definitions/Error' get: summary: 'Retrieve a time entry' operationId: retrieveTimeEntry @@ -4258,30 +4282,6 @@ paths: description: 'error payload' schema: $ref: '#/definitions/Error' - delete: - summary: 'Delete a time entry' - operationId: deleteTimeEntry - description: 'Delete a time entry. Deleting a time entry is only possible if it’s not closed and the associated project and task haven’t been archived. However, Admins can delete closed entries. Returns a 200 OK response code if the call succeeded.' - externalDocs: - description: 'Delete a time entry' - url: 'https://help.getharvest.com/api-v2/timesheets-api/timesheets/time-entries/#delete-a-time-entry' - security: - - - BearerAuth: [] - AccountAuth: [] - parameters: - - - name: timeEntryId - required: true - in: path - type: string - responses: - 200: - description: 'Delete a time entry' - default: - description: 'error payload' - schema: - $ref: '#/definitions/Error' '/time_entries/{timeEntryId}/external_reference': delete: summary: 'Delete a time entry’s external reference' @@ -4599,6 +4599,30 @@ paths: schema: $ref: '#/definitions/Error' '/users/{userId}': + delete: + summary: 'Delete a user' + operationId: deleteUser + description: 'Delete a user. Deleting a user is only possible if they have no time entries or expenses associated with them. Returns a 200 OK response code if the call succeeded.' + externalDocs: + description: 'Delete a user' + url: 'https://help.getharvest.com/api-v2/users-api/users/users/#delete-a-user' + security: + - + BearerAuth: [] + AccountAuth: [] + parameters: + - + name: userId + required: true + in: path + type: string + responses: + 200: + description: 'Delete a user' + default: + description: 'error payload' + schema: + $ref: '#/definitions/Error' get: summary: 'Retrieve a user' operationId: retrieveUser @@ -4713,30 +4737,6 @@ paths: description: 'error payload' schema: $ref: '#/definitions/Error' - delete: - summary: 'Delete a user' - operationId: deleteUser - description: 'Delete a user. Deleting a user is only possible if they have no time entries or expenses associated with them. Returns a 200 OK response code if the call succeeded.' - externalDocs: - description: 'Delete a user' - url: 'https://help.getharvest.com/api-v2/users-api/users/users/#delete-a-user' - security: - - - BearerAuth: [] - AccountAuth: [] - parameters: - - - name: userId - required: true - in: path - type: string - responses: - 200: - description: 'Delete a user' - default: - description: 'error payload' - schema: - $ref: '#/definitions/Error' '/users/{userId}/billable_rates': get: summary: 'List all billable rates for a specific user' @@ -5811,6 +5811,14 @@ definitions: type: string description: 'Date and time the expense was last updated.' format: date-time + total_cost: + type: number + description: 'The total amount of the expense.' + format: float + units: + type: integer + description: 'The quantity of units to use in calculating the total_cost of the expense.' + format: int32 ExpenseCategory: type: object externalDocs: diff --git a/src/Command/GenerateCommand.php b/src/Command/GenerateCommand.php index 8e434b3..18f01ec 100644 --- a/src/Command/GenerateCommand.php +++ b/src/Command/GenerateCommand.php @@ -35,6 +35,11 @@ public function execute(InputInterface $input, OutputInterface $output) { $extractor = new Extractor(); $dumper = new Dumper(__DIR__.'/../../generated/harvest-openapi.yaml'); - $dumper->dump($extractor->extract()); + $warnings = $dumper->dump($extractor->extract()); + + if (\count($warnings) > 0) { + $formatter = $this->getHelper('formatter'); + $output->writeln($formatter->formatBlock($warnings, 'bg=yellow;fg=black', true)); + } } } diff --git a/src/Dumper/Dumper.php b/src/Dumper/Dumper.php index 9c4693f..fdbe145 100644 --- a/src/Dumper/Dumper.php +++ b/src/Dumper/Dumper.php @@ -15,12 +15,14 @@ class Dumper { - public function __construct($target) + private string $target; + + public function __construct(string $target) { $this->target = $target; } - public function dump($data) + public function dump(array $data): array { $baseData = [ 'swagger' => '2.0', @@ -96,6 +98,43 @@ public function dump($data) ], ]; $data = array_merge($baseData, $data); + $definitionOverrides = [ + 'Expense' => [ + 'properties' => [ + 'total_cost' => [ + 'type' => 'number', + 'description' => 'The total amount of the expense.', + 'format' => 'float', + ], + 'units' => [ + 'type' => 'integer', + 'description' => 'The quantity of units to use in calculating the total_cost of the expense.', + 'format' => 'int32', + ], + ], + ], + ]; + $warnings = []; + + foreach ($definitionOverrides as $definition => $override) { + if (isset($override['properties'])) { + foreach ($override['properties'] as $propertyName => $propertyOverride) { + if (isset($data['definitions'][$definition]) + && isset($data['definitions'][$definition]['properties'][$propertyName])) { + $warnings[] = sprintf( + 'The property "%s" of the definition "%s" already exists and has been overriden.', + $propertyName, + $definition + ); + } + + $data['definitions'][$definition]['properties'][$propertyName] = $propertyOverride; + } + } + } + file_put_contents($this->target, Yaml::dump($data, 20, 2, Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE)); + + return $warnings; } } diff --git a/src/Extractor/Extractor.php b/src/Extractor/Extractor.php index cd55c0c..39c94e7 100644 --- a/src/Extractor/Extractor.php +++ b/src/Extractor/Extractor.php @@ -35,7 +35,12 @@ public function extract() $this->buildPluralDefinitions(); $this->buildItemsTypes(); - array_map('ksort', $this->paths); + $this->paths = array_map(function ($path) { + ksort($path); + + return $path; + }, + $this->paths); ksort($this->paths); $this->printUnknownDefinitions($this->paths); @@ -376,7 +381,7 @@ public static function buildDefinitionProperty($name, $type, $description, $path return $property; } - public function buildPath($url, $path, $method, $node, $title) + public static function buildPath($url, $path, $method, $node, $title) { $description = []; $parentNode = $node->parents()->filter('.highlighter-rouge')->first();