Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 44 additions & 9 deletions examples/generate/serverurls/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,57 @@ servers:
basePath:
# open meaning there is the opportunity to use special base paths as assigned by the provider, default is `v2`
default: v2
# an example of a type that's defined, but doesn't have a default
# an example of a variable declared but NOT referenced in the URL.
# `oapi-codegen` filters these out so they don't pollute the
# generated function signature with no-op parameters
# (https://github.com/oapi-codegen/oapi-codegen/issues/2004).
noDefault: {}
# # TODO this conflict will cause broken generated code https://github.com/oapi-codegen/oapi-codegen/issues/2003
# conflicting:
# enum:
# - 'default'
# - '443'
# default: 'default'
# A server whose `port` enum literally includes the string `default`.
# The previous codegen tripped over this because the enum constant for
# the value `default` collided with the named default-pointer constant
# (https://github.com/oapi-codegen/oapi-codegen/issues/2003); the fix
# routes server-URL enums through the generic enum path and renames
# the default-pointer constant to `…VariableDefaultValue`.
- url: https://api.example.com/{port}
description: Conflicting default enum
variables:
port:
enum:
- 'default'
- '443'
default: 'default'
# A server whose URL contains a `{token}` placeholder for which there
# is no entry in `variables`. The previous codegen happily emitted a
# function that left `{token}` in the URL, which then tripped the
# trailing `{`/`}` runtime check on every call
# (https://github.com/oapi-codegen/oapi-codegen/issues/2005). The fix
# emits the undeclared placeholder as a plain `string` parameter so
# callers can fill it in.
- url: https://{tenant}.api.example.com
description: Undeclared placeholder server
# A server whose enum has two values that fold to the same Go
# identifier suffix (`foo` and `Foo` both `ucFirst` to `Foo`). The
# previous codegen would have emitted two `const ...VariableFoo`
# declarations and failed to compile; the synthesizer now appends a
# numeric suffix to disambiguate, and the typed default-pointer
# references the correct (post-suffix) enum constant — addressing the
# concern raised in PR #2358 review.
- url: https://api.example.com/{mode}
description: Case-only enum collision
variables:
mode:
enum:
- 'foo'
- 'Foo'
default: 'Foo'
# clash with the previous definition of `Development server` to trigger a new name
- url: http://localhost:80
description: Development server
# clash with the previous definition of `Development server` to trigger a new name (again)
- url: http://localhost:80
- url: http://localhost:81
description: Development server
# make sure that the lowercase `description` gets converted to an uppercase
- url: http://localhost:80
- url: http://localhost:82
description: some lowercase name
# there may be URLs on their own, without a `description`
- url: http://localhost:443
Expand Down
148 changes: 127 additions & 21 deletions examples/generate/serverurls/gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading