Skip to content

feat(generate): allow generating Server URL boilerplate #2002

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

Merged
merged 1 commit into from
Jun 18, 2025

Conversation

jamietanna
Copy link
Member

@jamietanna jamietanna commented Jun 14, 2025

When working with a client generated by oapi-codegen, it can be a
little awkward to manage changing URLs for the client.WithBaseURL.

Although it's possible to manage these ourselves - with hardcoded values

  • it can be handy to have this pre-generated, especially if the input
    spec already defines $.servers.

This introduces the capability to opt-in to the generation (as we try to
make all changes opt-in where possible) of these.

This is a little more complicated than ""just"" generating constants, as
a Server object could introduce a templated URL.

This requires we:

  • generate the consts for non-templated URLs
  • generate the more in-depth boilerplate for templated URLs

We try and do most of the generating in the template, rather than in Go
code, although it's not straightforward to generate the method
parameters for the generated function (i.e.
NewServerUrlTheProductionAPIServer) so we create a
genServerURLWithVariablesFunctionParams function.

We'll leave a few cases of additional validation or handling of edge
cases to a follow-up.

@jamietanna jamietanna added the enhancement New feature or request label Jun 14, 2025
Copy link

kusari-inspector bot commented Jun 14, 2025

Kusari Analysis Results

Analysis for commit: d90d71a, performed at: 2025-06-14T13:14:45Z

@kusari-inspector rerun - Trigger a re-analysis of this PR

@kusari-inspector feedback [your message] - Send feedback to our AI and team


Recommendation

✅ PROCEED with this Pull Request

Summary

No Flagged Issues Detected

All values appear to be within acceptable risk parameters.

The PR introduces no dependency changes and contains only one low-impact, low-likelihood security issue related to using text/template instead of html/template. This issue poses minimal risk in the context of a code generator (not a web application directly serving content), making it unlikely to create a real XSS vulnerability. No secrets, critical vulnerabilities, or workflow issues were detected in the analysis.

Found this helpful? Give it a 👍 or 👎 reaction!

Copy link

Kusari PR Analysis rerun based on - e12ddc5 performed at: 2025-06-14T12:52:05Z - link to updated analysis

When working with a client generated by `oapi-codegen`, it can be a
little awkward to manage changing URLs for the `client.WithBaseURL`.

Although it's possible to manage these ourselves - with hardcoded values
- it can be handy to have this pre-generated, especially if the input
spec already defines `$.servers`.

This introduces the capability to opt-in to the generation (as we try to
make all changes opt-in where possible) of these.

This is a little more complicated than ""just"" generating constants, as
a Server object could introduce a templated URL.

This requires we:

- generate the `const`s for non-templated URLs
- generate the more in-depth boilerplate for templated URLs

We try and do most of the generating in the template, rather than in Go
code, although it's not straightforward to generate the method
parameters for the generated function (i.e.
`NewServerUrlTheProductionAPIServer`) so we create a
`genServerURLWithVariablesFunctionParams` function.

We'll leave a few cases of additional validation or handling of edge
cases to a follow-up.
Copy link

Kusari PR Analysis rerun based on - d90d71a performed at: 2025-06-14T13:14:45Z - link to updated analysis

@jamietanna jamietanna marked this pull request as ready for review June 14, 2025 13:20
@jamietanna jamietanna requested a review from a team as a code owner June 14, 2025 13:20
jamietanna added a commit to jamietanna/endoflife.date that referenced this pull request Jun 17, 2025
I noticed this while integrating with [0], that it may be nicer to
provide a `name` for the URL.

[0]: oapi-codegen/oapi-codegen#2002
jamietanna added a commit to jamietanna/endoflife.date that referenced this pull request Jun 17, 2025
I noticed this while integrating with [0], that it may be nicer to
provide a `description` for the URL.

[0]: oapi-codegen/oapi-codegen#2002
@jamietanna jamietanna merged commit aae687c into main Jun 18, 2025
35 checks passed
@jamietanna jamietanna deleted the feat/servers branch June 18, 2025 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy