generated from DFE-Digital/govuk-rails-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Merged
mooktakim
merged 11 commits into
main
from
CPDLP-3103-ts-7-update-swagger-docs-with-declaration-endpoints
Jul 10, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9ee1113
Add Swagger support for V1 declarations
padv2010 73da60d
Add Swagger support for V2 declarations
padv2010 75fec84
Add Swagger support for V3 declarations
padv2010 15c4e72
Remove `let`: not needed
padv2010 caf0ad5
Remove delivery_partner_id from declarations v3
padv2010 7eae7ba
DRy-up participant declaration
padv2010 aae4d2f
Update Swagger
padv2010 cd7af63
[CPDLP-3103] rubocop fix
mooktakim 12ac0f7
[CPDLP-3103] api version fix
mooktakim d7a7c2a
[CPDLP-3103] set required to each individual attribute
mooktakim 82b3792
[CPDLP-3103] make sure enums are set with variables, examples are set…
mooktakim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
require "rails_helper" | ||
require "swagger_helper" | ||
|
||
RSpec.describe "Participant Declarations endpoint", type: :request, openapi_spec: "v3/swagger.yaml" do | ||
include_context "with authorization for api doc request" | ||
|
||
it_behaves_like "an API index endpoint documentation", | ||
"/api/v3/participant-declarations", | ||
"Participant declarations", | ||
"Participant declarations", | ||
"#/components/schemas/ListParticipantDeclarationsFilter", | ||
"#/components/schemas/ParticipantDeclarationsResponse" | ||
|
||
describe "single declarations" do | ||
let(:lead_provider) { create(:lead_provider) } | ||
let(:type) { "participant-declaration" } # check | ||
let(:application) { create(:application, :accepted, :with_declaration, lead_provider:) } | ||
let(:resource) { application.declarations.first } | ||
let(:base_response_example) do | ||
extract_swagger_example(schema: "#/components/schemas/ParticipantDeclarationResponse", version: :v3) | ||
end | ||
|
||
it_behaves_like "an API show endpoint documentation", | ||
"/api/v3/participant-declarations/{id}", | ||
"Participant declarations", | ||
"Participant declarations", | ||
"#/components/schemas/ParticipantDeclarationResponse" | ||
|
||
it_behaves_like "an API update endpoint documentation", | ||
"/api/v3/participant-declarations/{id}/void", | ||
"Participant declarations", | ||
"Void a declaration", | ||
"The participant declaration being voided", | ||
"#/components/schemas/ParticipantDeclarationResponse" do | ||
let(:response_example) do | ||
base_response_example.tap do |example| | ||
example[:data][:attributes][:state] = "voided" | ||
example[:data][:attributes][:has_passed] = nil | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe "create declarations" do | ||
let(:lead_provider) { create(:lead_provider) } | ||
let(:type) { "participant-declaration" } # check | ||
let(:cohort) { create(:cohort, :current) } | ||
let(:course_group) { CourseGroup.find_by(name: "leadership") } | ||
let(:course) { create(:course, :sl, course_group:) } | ||
let!(:schedule) { create(:schedule, :npq_leadership_autumn, course_group:, cohort:) } | ||
let(:application) { create(:application, :accepted, cohort:, course:, lead_provider:) } | ||
let(:declaration_date) { schedule.applies_from + 1.day } | ||
let(:invalid_attributes) { { participant_id: "invalid" } } | ||
let(:attributes) do | ||
{ | ||
participant_id: application.user.ecf_id, | ||
declaration_type: "started", | ||
declaration_date: application.schedule.applies_from.rfc3339, | ||
course_identifier: course.identifier, | ||
} | ||
end | ||
|
||
it_behaves_like "an API create on resource endpoint documentation", | ||
"/api/v3/participant-declarations", | ||
"Participant declarations", | ||
"Declare a participant has reached a milestone", | ||
"The participant declaration being created", | ||
"#/components/schemas/ParticipantDeclarationResponse", | ||
"#/components/schemas/ParticipantDeclarationRequest" | ||
end | ||
end |
98 changes: 98 additions & 0 deletions
98
...support/shared_examples/api_create_on_existing_resource_endpoint_documentation_support.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.shared_examples "an API create on existing resource endpoint documentation" do |url, tag, resource_description, response_description, response_schema_ref, request_schema_ref| | ||
path url do | ||
post resource_description do | ||
tags tag | ||
consumes "application/json" | ||
produces "application/json" | ||
security [api_key: []] | ||
|
||
parameter name: :id, | ||
in: :path, | ||
required: true, | ||
schema: { | ||
"$ref": "#/components/schemas/IDAttribute", | ||
} | ||
|
||
if request_schema_ref | ||
parameter name: :params, | ||
in: :body, | ||
style: :deepObject, | ||
required: false, | ||
schema: { | ||
"$ref": request_schema_ref, | ||
} | ||
|
||
let(:params) do | ||
{ | ||
data: { | ||
type:, | ||
attributes:, | ||
}, | ||
} | ||
end | ||
end | ||
|
||
response "200", response_description do | ||
let(:id) { resource.ecf_id } | ||
|
||
schema({ "$ref": response_schema_ref }) | ||
|
||
after do |example| | ||
if defined?(response_example) | ||
example_spec = { | ||
"application/json" => { | ||
examples: { | ||
success: { | ||
value: response_example, | ||
}, | ||
}, | ||
}, | ||
} | ||
example.metadata[:response][:content] = example_spec | ||
end | ||
end | ||
|
||
run_test! | ||
end | ||
|
||
response "401", "Unauthorized" do | ||
let(:id) { resource.ecf_id } | ||
let(:token) { "invalid" } | ||
|
||
schema({ "$ref": "#/components/schemas/UnauthorisedResponse" }) | ||
|
||
run_test! | ||
end | ||
|
||
if request_schema_ref | ||
response "400", "Bad request" do | ||
let(:id) { resource.ecf_id } | ||
let(:params) { { data: {} } } | ||
|
||
schema({ "$ref": "#/components/schemas/BadRequestResponse" }) | ||
|
||
run_test! | ||
end | ||
|
||
response "422", "Unprocessable entity" do | ||
let(:id) { resource.ecf_id } | ||
let(:attributes) { invalid_attributes } | ||
|
||
schema({ "$ref": "#/components/schemas/UnprocessableEntityResponse" }) | ||
|
||
run_test! | ||
end | ||
end | ||
|
||
response "404", "Not found", exceptions_app: true do | ||
let(:id) { SecureRandom.uuid } | ||
|
||
schema({ "$ref": "#/components/schemas/NotFoundResponse" }) | ||
|
||
run_test! | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could voided declarations have examples returned with voided state?