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

Add API methods to get schema information #2767

Merged
merged 4 commits into from
Jun 11, 2024

Conversation

pezholio
Copy link
Contributor

This adds some API methods to return information about the schemas that Publishing API knows about, as well as fetching a schema by name. This allows us to get up to date schema information without having to have a local copy of the schemas stored somewhere and using the GOV.UK Schemas gem.

This will allow the content modelling team to have a way to create many different types of reusable content using the Publishing API as a single source of truth for the schema, rather than having to keep fields, validation rules etc in two places.

Happy to chat through in more detail if anyone needs any more context / has any questions!

This fetches all the Publisher Schemas and marshals them into
a key/value arrangement, removing the filepath and replacing
with the schema name
This allows us to fetch a schema for a particular content type, throwing
an error if there is no such schema found
@@ -0,0 +1,50 @@
RSpec.describe V2::SchemasController do
Copy link
Contributor

Choose a reason for hiding this comment

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

does there also need to be a request spec?

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 guess I'm kinda doing a request spec over a controller spec here, as I guess controller specs are more designed to be "unit-type" tests, so I think I'll switch over 👍

@@ -0,0 +1,8 @@
class SchemaService
def self.all_schemas
format_regex = Regexp.new(".+\/formats\/([a-z_]+)\/.+")
Copy link
Contributor

Choose a reason for hiding this comment

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

so here we are using the file path to get the type of object the schema is for? Is there any other way to get the type, e.g. in the schema itself with a title key for instance? Just wondering if there's a risk depending on a file path set in another gem which could easily change...

Copy link
Contributor

Choose a reason for hiding this comment

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

After chat with @pezholio There is no codified place for the name/type except in folder name

This adds controller methods that call the relevant service method
and return the result as JSON
@pezholio pezholio force-pushed the add-api-methods-to-get-schema-information branch from 8b47701 to 555611f Compare June 11, 2024 13:50
@pezholio pezholio enabled auto-merge June 11, 2024 13:51
@pezholio pezholio merged commit 2ec6d7a into main Jun 11, 2024
12 checks passed
@pezholio pezholio deleted the add-api-methods-to-get-schema-information branch June 11, 2024 13:52
Harriethw added a commit to alphagov/gds-api-adapters that referenced this pull request Jun 12, 2024
`/schemas` and `/schemas/{schema_name}` were added
to the Publishing API in this PR [1]

This adds methods to the publishing_api adapter

[1] alphagov/publishing-api#2767
Harriethw added a commit to alphagov/gds-api-adapters that referenced this pull request Jun 12, 2024
`/schemas` and `/schemas/{schema_name}` were added
to the Publishing API in this PR [1].

This adds helper methods to stub responses to these
end points.

[1] alphagov/publishing-api#2767
Harriethw added a commit to alphagov/gds-api-adapters that referenced this pull request Jun 12, 2024
`/schemas` and `/schemas/{schema_name}` were added
to the Publishing API in this PR [1]

This adds methods to the publishing_api adapter

[1] alphagov/publishing-api#2767
Harriethw added a commit to alphagov/gds-api-adapters that referenced this pull request Jun 12, 2024
`/schemas` and `/schemas/{schema_name}` were added
to the Publishing API in this PR [1].

This adds helper methods to stub responses to these
end points.

[1] alphagov/publishing-api#2767
Harriethw added a commit to alphagov/gds-api-adapters that referenced this pull request Jun 13, 2024
`/schemas` and `/schemas/{schema_name}` were added
to the Publishing API in this PR [1].

This adds helper methods to stub responses to these
end points.

[1] alphagov/publishing-api#2767
Harriethw added a commit to alphagov/gds-api-adapters that referenced this pull request Jun 13, 2024
`/schemas` and `/schemas/{schema_name}` were added
to the Publishing API in this PR [1].

This adds helper methods to stub responses to these
end points.

[1] alphagov/publishing-api#2767
Harriethw added a commit to alphagov/gds-api-adapters that referenced this pull request Jun 14, 2024
`/schemas` and `/schemas/{schema_name}` were added
to the Publishing API in this PR [1]

This adds methods to the publishing_api adapter

[1] alphagov/publishing-api#2767
Harriethw added a commit to alphagov/gds-api-adapters that referenced this pull request Jun 14, 2024
`/schemas` and `/schemas/{schema_name}` were added
to the Publishing API in this PR [1].

This adds helper methods to stub responses to these
end points.

[1] alphagov/publishing-api#2767
Harriethw added a commit to alphagov/gds-api-adapters that referenced this pull request Jun 14, 2024
`/schemas` and `/schemas/{schema_name}` were added
to the Publishing API in this PR [1].

This adds helper methods to stub responses to these
end points.

[1] alphagov/publishing-api#2767
Harriethw added a commit to alphagov/gds-api-adapters that referenced this pull request Jun 14, 2024
`/schemas` and `/schemas/{schema_name}` were added
to the Publishing API in this PR [1]

This adds methods to the publishing_api adapter

[1] alphagov/publishing-api#2767
Harriethw added a commit to alphagov/gds-api-adapters that referenced this pull request Jun 14, 2024
`/schemas` and `/schemas/{schema_name}` were added
to the Publishing API in this PR [1].

This adds helper methods to stub responses to these
end points.

[1] alphagov/publishing-api#2767
tahb added a commit to alphagov/gds-api-adapters that referenced this pull request Jun 17, 2024
`/schemas` and `/schemas/{schema_name}` were added
to the Publishing API in this PR [1]

This adds methods to the publishing_api adapter

[1] alphagov/publishing-api#2767

Co-authored-by: Tom Hipkin <tomhipkin@gmail.com>
Co-authored-by: Harriet H-W <harriethw@gmail.com>
tahb pushed a commit to alphagov/gds-api-adapters that referenced this pull request Jun 17, 2024
`/schemas` and `/schemas/{schema_name}` were added
to the Publishing API in this PR [1].

This adds helper methods to stub responses to these
end points.

[1] alphagov/publishing-api#2767
Harriethw added a commit to alphagov/gds-api-adapters that referenced this pull request Jun 18, 2024
`/schemas` and `/schemas/{schema_name}` were added
to the Publishing API in this PR [1]

This adds methods to the publishing_api adapter

[1] alphagov/publishing-api#2767

Co-authored-by: Tom Hipkin <tomhipkin@gmail.com>
Co-authored-by: Harriet H-W <harriethw@gmail.com>
Harriethw added a commit to alphagov/gds-api-adapters that referenced this pull request Jun 18, 2024
`/schemas` and `/schemas/{schema_name}` were added
to the Publishing API in this PR [1].

This adds helper methods to stub responses to these
end points.

[1] alphagov/publishing-api#2767
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.

3 participants