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

Make it possible to add custom API documentation based on the deployment location #6355

Open
wants to merge 7 commits into
base: dev-2.x
Choose a base branch
from

Conversation

t2gran
Copy link
Member

@t2gran t2gran commented Jan 2, 2025

Summary

This PR introduce a new configuration parameter to load a deployment specific properies file.

router-config.json

{
  "server": {
    "apiDocumentationProfile" : "entur",
 ...

custom-documentation-entur.properties

TariffZone.description=A **zone** used to define ...

Syntax properties file

Use:

<TypeName>[.<FieldName>].(description|deprecated)[.append]

Examples

Replace the existing type description

Quay.description=The place for boarding/alighting a vehicle

Append to the existing type description

Quay.description.append=This is appended

Replace the existing field description

Quay.name.description=The name of a Quay is ...

Append to the existing field description

Quay.name.description.append=(Source NSR)

Insert deprecated reason. Due to a bug in the Java GraphQL lib, an existing deprecated reason cannot be updated, but it can be deprecated if not already marked. Deleting the reason from the schema, and adding it back using
the "default" TransmodelApiDocumentationProfile can be used as a workaround. The problem is reported to the Java GraphQL Prodject here: graphql-java/graphql-java#3786.

Quay.name.deprecated=This field is deprecated ...

Issue

🟥 No isse exist for this.

Unit tests

✅ All new code have unit-tests

Documentation

✅ JavaDoc and user doc is added/updated.

Changelog

✅ This is a new feature

Bumping the serialization version id

🟥 Not needed

@t2gran t2gran added New Feature Entur Test This is currently being tested at Entur labels Jan 2, 2025
@t2gran t2gran added this to the 2.7 (next release) milestone Jan 2, 2025
@t2gran t2gran requested a review from a team as a code owner January 2, 2025 12:34
Copy link

codecov bot commented Jan 2, 2025

Codecov Report

Attention: Patch coverage is 83.45324% with 23 lines in your changes missing coverage. Please review.

Project coverage is 69.87%. Comparing base (4198bb6) to head (f2406e7).
Report is 47 commits behind head on dev-2.x.

Files with missing lines Patch % Lines
...support/graphql/injectdoc/CustomDocumentation.java 74.35% 6 Missing and 4 partials ⚠️
...pplanner/utils/text/TextVariablesSubstitution.java 86.20% 2 Missing and 2 partials ⚠️
...t/graphql/injectdoc/InjectCustomDocumentation.java 92.10% 2 Missing and 1 partial ⚠️
...anner/apis/transmodel/TransmodelGraphQLSchema.java 66.66% 2 Missing and 1 partial ⚠️
...framework/project/EnvironmentVariableReplacer.java 87.50% 1 Missing ⚠️
...r/standalone/config/routerconfig/ServerConfig.java 87.50% 1 Missing ⚠️
...ner/standalone/configure/ConstructApplication.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #6355      +/-   ##
=============================================
+ Coverage      69.85%   69.87%   +0.02%     
- Complexity     17926    17981      +55     
=============================================
  Files           2035     2039       +4     
  Lines          76508    76626     +118     
  Branches        7825     7835      +10     
=============================================
+ Hits           53442    53541      +99     
- Misses         20325    20339      +14     
- Partials        2741     2746       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

In the case used, we compare to GraphQL schemas.
@t2gran t2gran force-pushed the custom-doc-transmodel-api branch from 4de6666 to 0bf3c72 Compare January 2, 2025 14:10
List of available custom documentation profiles. A profile is used to inject custom
documentation like type and field description or a deprecated reason.

Currently, ONLY the Transmodel API support this feature.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Currently, ONLY the Transmodel API support this feature.
Currently, ONLY the Transmodel API supports this feature.

private final Map<String, String> textMap;

/**
* Pacakge local to be unit-testable
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Pacakge local to be unit-testable
* Package local to be unit-testable

throw new OtpAppException("Resource not found: %s", resource);
}
var props = new Properties();
props.load(input);
Copy link
Member

Choose a reason for hiding this comment

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

This method assumes that the input stream is ISO-8869-1 since properties files used to be hardcoded to that encoding.

You need to wrap the input stream in a reader like this:

new InputStreamReader(input, "UTF-8")

import java.util.function.BiFunction;

/**
* This is GraphQL visitor witch inject custom documentation on types and fields.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* This is GraphQL visitor witch inject custom documentation on types and fields.
* This is GraphQL visitor which injects custom documentation on types and fields.

@t2gran t2gran added the bump serialization id Add this label if you want the serialization id automatically bumped after merging the PR label Jan 7, 2025
import org.opentripplanner._support.text.TextAssertions;

/**
* This test read in a schema file, inject documentation and convert the
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* This test read in a schema file, inject documentation and convert the
* This test reads in a schema file, injects documentation and convert the

Copy link
Member

@leonardehrenfried leonardehrenfried left a comment

Choose a reason for hiding this comment

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

There are a few things that I picked up on, mainly that properties files in Java are assumed to be ISO-8869-1.

@t2gran t2gran removed the bump serialization id Add this label if you want the serialization id automatically bumped after merging the PR label Jan 7, 2025
var fieldName = field.getName();
var typeName = parent.getName();

Optional<T> f1 = customDocumentation
Copy link
Contributor

Choose a reason for hiding this comment

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

Really nitpicking here, but shouldn't f1 and f2 be named the other way around? Now f2 is the preferred one. I don't know.

* <p>
* Note! There is a bug in the Java GraphQL library. Existing deprecated reasons
* cannot be changed or replaced. This test adds test-cases for this, but excludes
* them from the expected result. If this is fixed in the GraphQL library, this
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Entur Test This is currently being tested at Entur New Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants