Skip to content

Conversation

@maddy-jo
Copy link

@maddy-jo maddy-jo commented Jun 17, 2025

Expose a Register function that can be used to install routes in subrouter

Takes the existing logic for generating the routes in gen-go/server and applies them to an injected router. This allows a server to compose routers by calling

Register(parentRouter.PathPrefix("/subrouter-prefix").Subrouter(), controller)

Testing this hypothesis out in app-district-service.

Jira

SHAPI-1697

Testing

See Clever/app-district-service#2.

$ curl -X GET http://localhost:8080/v2/things -i          
HTTP/1.1 500 Internal Server Error
Content-Type: text/plain; charset=utf-8
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
Date: Tue, 17 Jun 2025 00:22:25 GMT
Content-Length: 44

{"message":"TODO, this is just an example"}
madeline.lumetta> app-district-service $ curl -X GET http://localhost:8080/districts/v2/things -i
HTTP/1.1 500 Internal Server Error
Content-Type: text/plain; charset=utf-8
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
Date: Tue, 17 Jun 2025 00:22:30 GMT
Content-Length: 44

{"message":"TODO, this is just an example"}
madeline.lumetta> app-district-service $ curl -X GET http://localhost:8080/sessions/v2/things -i 
HTTP/1.1 500 Internal Server Error
Content-Type: text/plain; charset=utf-8
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
Date: Tue, 17 Jun 2025 00:22:38 GMT
Content-Length: 44

{"message":"TODO, this is just an example"}

madeline.lumetta> app-district-service $ curl -X GET http://localhost:8080/wrong/v2/things -i   
HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=utf-8
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
Date: Tue, 17 Jun 2025 00:22:41 GMT
Content-Length: 19

404 page not found

Checklist

  • Run make build
  • Run make generate
  • Update the current version in the /VERSION file. First line should be JUST the version e.g. v10.13.1. Then a blank line. Then release notes.

@maddy-jo maddy-jo requested a review from a team as a code owner June 17, 2025 00:23
@maddy-jo maddy-jo requested review from andruwm and removed request for a team June 17, 2025 00:23
@pickabot pickabot bot requested a review from vynmeister June 17, 2025 17:12
@maddy-jo maddy-jo force-pushed the subrouters branch 4 times, most recently from 729980a to 42e5049 Compare June 20, 2025 14:45
@andruwm andruwm removed their request for review June 24, 2025 00:14
@andruwm
Copy link
Contributor

andruwm commented Jun 24, 2025

I am untagging myself here so I don't get prompted by slack everyday to review, but feel free to re-tag me at any point if you are ready for a review.

Copy link
Contributor

@andruwm andruwm left a comment

Choose a reason for hiding this comment

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

The code changes here look reasonable. It's be helpful to add another swagger file which uses this new feature in samples so that its easier to understand how both the client and server look on a simple app.

@@ -0,0 +1,7 @@
package wagclientlogger

type NoOpLogger struct{}
Copy link
Contributor

Choose a reason for hiding this comment

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

We should have had one of these a long time ago.

Copy link
Author

Choose a reason for hiding this comment

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

yeah I think this would be worth cherry-picking into its own PR, probably?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed

@andruwm
Copy link
Contributor

andruwm commented Jul 10, 2025

The code changes here look reasonable. It's be helpful to add another swagger file which uses this new feature in samples so that its easier to understand how both the client and server look on a simple app.

I just looked through the sample PR provided and was able to get a good idea of it there, but having it all in one place would be awesome at some point. Doesnt need to be now.

@maddy-jo maddy-jo marked this pull request as draft August 1, 2025 15:45
@maddy-jo maddy-jo force-pushed the subrouters branch 2 times, most recently from f78c605 to 93c35c4 Compare August 4, 2025 23:41
…outer

Takes the existing logic for generating the routes in gen-go/server and applies
them to an injected router. This allows a server to compose routers by calling

```
Register(parentRouter.PathPrefix("/subrouter-prefix").Subrouter(), controller)
```

Testing this hypothesis out in app-district-service.
The extension schema is of the form

```yaml
x-routers:
  - key: subrouter1
    path: /v1/abc
  - key: subrouter2
    path: /v1/xyz
```

This pattern assumes that the repo has a routers/ directory with subdirectories
routers/subrouter1 and routers/subrouter2, with both being subdirectories having
wag-generated route handlers.
…g subrouter

This change allows us to use the existing notion of `basePath` to generate the
correct client paths for a subrouter, assuming that we do not want to support
path parameters for a subrouter, which keeps us spec compliant for OAS 2.
Since the strategy for subrouter JavaScript clients (at least, so far), has been
to include the subrouters in the root client generation — which is the opposite
of how the Go clients are generated — we don't need to generate the subrouter
clients. This change autosets conf.generateJSClient to false if conf.subrouter
is true.
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.

4 participants