-
Notifications
You must be signed in to change notification settings - Fork 3
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
OpenAPI schemas #15
base: master
Are you sure you want to change the base?
OpenAPI schemas #15
Conversation
When we chatted before, I forgot to tell you that there are community-maintained TypeScript typings, sorry. These may (have been) used to generate the JSON Schema definitions. |
routes/arrivals.js
Outdated
@@ -147,8 +147,284 @@ Works like \`/stops/{id}/departures\`, except that it uses [\`hafasClient.arriva | |||
content: { | |||
'application/json': { | |||
schema: { | |||
type: 'array', | |||
items: {type: 'object'}, // todo | |||
'type': 'array', |
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.
What do you think about moving the each "root" schema into a variable, to reduce the nesting level?
routes/arrivals.js
Outdated
'tripId': { | ||
'type': 'string' | ||
}, | ||
'stop': { |
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.
Let's move re-used sub schemas (e.g. a stop) into a variable each, and then use them here.
Auto-generating the schemas from the TS typings instead of from some JSON instances indeed seems better. There is only one drawback I have noticed so far: It doesn't distinguish between null and not present. But most libraries/programming languages don't do that anyways, so it shouldn't really be a problem. Thinking about it again, we should have one common schema file for all endpoints. That way, it's easier to replace it with a new auto-generated version. And the reused sub-schemas (using "$ref") actually get reused and turn into the same class in the generated code in the client. I will have to take a more thorough look at this. |
We can host the schemas in the |
In case that didn't become clear, I was talking about the endpoints like journeys, departures, arrivals, etc., which in the first iteration have completely separate schemas. In a generated client, that would lead to separate classes of the same structure (e.g. for a stop). |
Yes, we can refactor common parts into common (sub-)schemas later.
They do, but some |
I have changed the approach now.
|
I finally found time and energy to look at this from a broader perspective. Thank you for waiting. Also, I'd like to cc @bergmannjg, who has contributed the Some problems that are not yet solved by this PR: profiles
For example, the As the enum of supported products is quite relevant to people using @bergmannjg As a first step towards this, do you think it would be possible to let As the next step, we could modify
Dependents of passing the generated defintions into
|
Another unrelated note:
The former option is probably less work for you, the latter less work for me. Up to you! |
@derhuerst: a first note to your questions
Please have look at hafas-api-tsoa. It uses tsoa as an alternative to typescript-json-schema. The api spec is generated from the TS typings and from decorators in the controller file.
Usng tsoa the custom definitions may be generated from different controllers. |
I'm a bit hesitant to use tools like tsoa because they impose a very specific structure upon your API, which IMHO is neither more understandable (the controller pattern really doesn't fit to what |
Currently, |
This branch contains code to check and create the typing file, here is a short description.
Can you give an example, the types should work with all profiles. |
Some thoughts:
|
Yes, indeed it prevents the (somewhat hacky and potentially incomplete) manipulation of the generated JSON schema, at a high cost in other area: Structuring all of the code according to the controller pattern, which IMO does not fit well to
Maybe I misunderstood you, but there are at least two reasons why I'm not a fan of this approach which both come down to long-term maintenance:
Great! Let's first discuss the steps forward here though, so that you don't waste time working on things that we might revise anyways. |
It may be possible to generate profile specific typings from the general @types/hafas-client/index.d.ts file using For example: change the type of mode
with
for the nvv profile using the products array. The flags of the profile (like trip or radar) can be used to adapt hafas-client's interface methods. Maybe there should be flags for db profile specific fields firstclass, loadfactor, etc. The conversions can be implemented with a shell script or node program.
This should be solved with ES modules. The createClient namespace doesn't exist anymore. |
With manually tweaking the schema, I meant the end user who uses it to generate the classes/types in whatever programming language they are using. Talking about schema generation in hafas-rest-api, I think it's indeed a good idea to do it on the fly at runtime (the only drawback there that we have to add the TS typings as a runtime dependency). I can have a look at that when we have agreed on how to proceed and as soon as the TS typings have been updated to match v6. Since there still doesn't seem to be anything that really differs structurally, I'm still not convinced we should adapt the schema to profiles. This can even have the drawback for end users that they can not use the same (generated) code base for different HAFAS APIs. |
0446fc6
to
ee126a0
Compare
New dependencies detected. Learn more about Socket for GitHub ↗︎
|
Fast forward two years 🙈, I've updated the OpenAPI schema for v6.
|
disclaimer:
--> don't rely on it, just use it as a quick way to generate a client