From 7266bdf3078105d083798581a547018982236c8e Mon Sep 17 00:00:00 2001 From: Thomas Gran Date: Tue, 10 Dec 2024 13:05:50 +0100 Subject: [PATCH 1/2] Add endpoint to download Transmodel GraphQL Schema --- .../opentripplanner/apis/transmodel/TransmodelAPI.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/application/src/main/java/org/opentripplanner/apis/transmodel/TransmodelAPI.java b/application/src/main/java/org/opentripplanner/apis/transmodel/TransmodelAPI.java index fe73e8b9887..d2d6379d19b 100644 --- a/application/src/main/java/org/opentripplanner/apis/transmodel/TransmodelAPI.java +++ b/application/src/main/java/org/opentripplanner/apis/transmodel/TransmodelAPI.java @@ -2,9 +2,11 @@ import com.fasterxml.jackson.databind.ObjectMapper; import graphql.schema.GraphQLSchema; +import graphql.schema.idl.SchemaPrinter; import io.micrometer.core.instrument.Tag; import jakarta.ws.rs.BadRequestException; import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.GET; import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; @@ -138,6 +140,12 @@ public Response getGraphQL(String query, @Context HttpHeaders headers) { ); } + @GET + @Path("schema.graphql") + public Response getGraphQLSchema() { + return Response.ok().encoding("UTF-8").entity(new SchemaPrinter().print(schema)).build(); + } + private static Iterable getTagsFromHeaders(HttpHeaders headers) { return tracingHeaderTags .stream() From f765199bb730ced20212d4cc7f7e2baa574ef14d Mon Sep 17 00:00:00 2001 From: Thomas Gran Date: Tue, 10 Dec 2024 14:49:14 +0100 Subject: [PATCH 2/2] doc: Add a disclaimer to the top of the Transmodel Schema served at runtime. --- .../apis/transmodel/TransmodelAPI.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/application/src/main/java/org/opentripplanner/apis/transmodel/TransmodelAPI.java b/application/src/main/java/org/opentripplanner/apis/transmodel/TransmodelAPI.java index d2d6379d19b..66377a56390 100644 --- a/application/src/main/java/org/opentripplanner/apis/transmodel/TransmodelAPI.java +++ b/application/src/main/java/org/opentripplanner/apis/transmodel/TransmodelAPI.java @@ -33,6 +33,15 @@ @Produces(MediaType.APPLICATION_JSON) public class TransmodelAPI { + // Note, the blank line at the end is intended + private static final String SCHEMA_DOC_HEADER = + """ +# THIS IS NOT INTENDED FOR PRODUCTION USE. We recommend using the GraphQL introspection instead. +# This is intended for the OTP Debug UI and can also be used by humans to get the schema with the +# OTP configured default-values injected. + +"""; + private static final Logger LOG = LoggerFactory.getLogger(TransmodelAPI.class); private static GraphQLSchema schema; @@ -143,7 +152,8 @@ public Response getGraphQL(String query, @Context HttpHeaders headers) { @GET @Path("schema.graphql") public Response getGraphQLSchema() { - return Response.ok().encoding("UTF-8").entity(new SchemaPrinter().print(schema)).build(); + var text = SCHEMA_DOC_HEADER + new SchemaPrinter().print(schema); + return Response.ok().encoding("UTF-8").entity(text).build(); } private static Iterable getTagsFromHeaders(HttpHeaders headers) {