Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update swagger docs with declaration endpoints #1504

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

padv2010
Copy link
Contributor

@padv2010 padv2010 commented Jul 3, 2024

Context

Ticket: https://dfedigital.atlassian.net/browse/CPDNPQ-000

Description

Add API docs for all the declaration endpoints in NPQ in v1/v2/v3 for the GET/POST participant-declarations in all versions including any errors as in About the API - Manage training for early career teachers . Add the PUT void declarations in all versions.

@padv2010 padv2010 force-pushed the CPDLP-3103-ts-7-update-swagger-docs-with-declaration-endpoints branch from 0c458ac to f923fad Compare July 3, 2024 12:24
@padv2010 padv2010 marked this pull request as ready for review July 3, 2024 12:24
@padv2010 padv2010 requested a review from a team as a code owner July 3, 2024 12:24
@padv2010 padv2010 changed the title Cpdlp 3103 ts 7 update swagger docs with declaration endpoints Update swagger docs with declaration endpoints Jul 3, 2024
let(:application) { create(:application, :accepted, cohort:, course:, lead_provider:) }
let(:declaration_date) { schedule.applies_from + 1.day }
let(:response_example) do
extract_swagger_example(schema: "#/components/schemas/ParticipantDeclarationResponse", version: :v3)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can omit these if you aren't writing a custom response example, it will default to the ParticipantDeclarationResponse passed in on line 61

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 4e0af42

@@ -8,13 +8,6 @@
produces "application/json"
security [api_key: []]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this file should be deleted? it looks like it was replaced/renamed with create on existing resource?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I split it in two, because one post is for a resource that already exist, and the other one is for a new one. I tried to merge both and the code looked complicated.

},
attributes: {
anyOf: [
{ "$ref": "#/components/schemas/ParticipantDeclarationStartedRequest" },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there's any way to get this pulling through into the swagger-ui, it seems to only show one request example 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ethax-ross I have not been able to find how to do it, sorry

type: :string,
example: "2021,2022",
},
delivery_partner_id: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no delivery partners in NPQ; I think this should be training_status?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 34a5363. I have not been able to find a reference to training_status

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I think I was looking at the ECFParticipantFilter by accident, looks good now.

description: "An NPQ completed participant declaration",
type: :object,
required: %i[
participant_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit of a faff, but to get the swagger-ui to generate properly and mark as required you need to add required: true to the indivudual properties below as well, so:

participant_id: {
      description: "The unique id of the participant",
      type: :string,
      format: :uuid,
      example: "db3a7848-7308-4879-942a-c4a70ced400a",
      required: true
    },

We need to do this in all request schemas

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ethax-ross I described them in

required: %i[
participant_id
declaration_type
declaration_date
course_identifier
has_passed
],
and it is presented this way:
image

Would this be ok?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the issue with not putting it also on the type and attributes and individual attributes like participant_id is that it doesn't mark it as required 'in all the ways'... I'm not sure if we can that much about this, but here's how it looks if you do it everywhere:

Before After
Screenshot 2024-07-05 at 13 55 51 Group

Here's the diff:

diff --git a/spec/swagger_schemas/requests/participant_declaration_request.rb b/spec/swagger_schemas/requests/participant_declaration_request.rb
index 76cb809a..ed6529de 100644
--- a/spec/swagger_schemas/requests/participant_declaration_request.rb
+++ b/spec/swagger_schemas/requests/participant_declaration_request.rb
@@ -1,15 +1,18 @@
 PARTICIPANT_DECLARATION_REQUEST = {
   description: "A participant declaration data request",
   type: :object,
+  required: %w[type attributes],
   properties: {
     type: {
       type: :string,
+      required: true,
       enum: %w[
         participant-declaration
       ],
       example: "participant-declaration",
     },
     attributes: {
+      required: true,
       anyOf: [
         { "$ref": "#/components/schemas/ParticipantDeclarationStartedRequest" },
         { "$ref": "#/components/schemas/ParticipantDeclarationRetainedRequest" },
diff --git a/spec/swagger_schemas/requests/participant_declaration_started_request.rb b/spec/swagger_schemas/requests/participant_declaration_started_request.rb
index 956f601d..8b64bb1d 100644
--- a/spec/swagger_schemas/requests/participant_declaration_started_request.rb
+++ b/spec/swagger_schemas/requests/participant_declaration_started_request.rb
@@ -7,11 +7,13 @@ PARTICIPANT_DECLARATION_STARTED_REQUEST = {
       description: "The unique id of the participant",
       type: :string,
       format: :uuid,
+      required: true,
       example: "db3a7848-7308-4879-942a-c4a70ced400a",
     },
     declaration_type: {
       description: "The event declaration type",
       type: :string,
+      required: true,
       enum: %w[
         started
       ],
@@ -20,12 +22,14 @@ PARTICIPANT_DECLARATION_STARTED_REQUEST = {
     declaration_date: {
       description: "The event declaration date",
       type: :string,
+      required: true,
       format: "date-time",
       example: "2021-05-31T02:21:32.000Z",
     },
     course_identifier: {
       description: "The type of course the participant is enrolled in",
       type: :string,
+      required: true,
       enum: %w[
         npq-leading-teaching
         npq-leading-behaviour-culture

type: :string,
nullable: false,
example: "started",
enum: %w[
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could populate from the model (we don't have extended declarations), so:

enum: Schedule::DECLARATION_TYPES

The example can also be populated: example: Schedule::DECLARATION_TYPES.first

Copy link
Contributor Author

@padv2010 padv2010 Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in f5275af

type: :string,
nullable: false,
example: "npq-leading-teaching",
enum: %w[
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto pull from Course::IDENTIFIERS and the example can use Course::IDENTIFIERS.first

Copy link
Contributor Author

@padv2010 padv2010 Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in f5275af

type: :string,
nullable: false,
example: "submitted",
enum: %w[
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declaration.states.keys

Copy link
Contributor Author

@padv2010 padv2010 Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in f5275af

example: "2021-05-31T02:22:32.000Z",
},
has_passed: {
description: "The date the declaration was last updated",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whether the participant has failed or passed

Copy link
Contributor Author

@padv2010 padv2010 Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in f5275af

},
},
},
v2: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of copy/pasting here we could deep_dup the hash and tap it to modify only the changed parts (see other schemas for an example). v2 drops the voided/eligible_for_payment fields and v3 builds on v2 and adds statement_id, clawback_statement_id, uplift_paid, lead_provider_name, ineligible_for_funding_reason and created_at

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in f5275af

@leandroalemao leandroalemao force-pushed the CPDLP-3094 branch 2 times, most recently from 5aa4ff6 to c871d86 Compare July 4, 2024 18:32
Base automatically changed from CPDLP-3094 to main July 4, 2024 19:01
@padv2010 padv2010 force-pushed the CPDLP-3103-ts-7-update-swagger-docs-with-declaration-endpoints branch 3 times, most recently from 9b01e9e to f5275af Compare July 5, 2024 12:59
Copy link

github-actions bot commented Jul 5, 2024

@padv2010 padv2010 force-pushed the CPDLP-3103-ts-7-update-swagger-docs-with-declaration-endpoints branch from 8d5c34e to 82e7d2c Compare July 5, 2024 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants